@model  AngelExam.Areas.Admin.Controllers.EditOjbectClasstk
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_LayoutForm.cshtml";
}

<style type="text/css">
    .fr {
        float: right;
    }

    .img-headshot {
        width: 90px;
        height: 90px;
        position: absolute;
        top: -30px;
        border: medium none;
        border-radius: 50%;
        cursor: pointer;
    }
</style>
<form class="layui-form layui-form-pane angel-form" lay-filter="formTest">

    <input data-val="true"  id="ID" name="ID" type="hidden" value="0" />
    <div class="layui-form-item">
        <label class="layui-form-label">题库类型</label>
@*        <div class="layui-input-block">
          @Html.DropDownList("SortID", new SelectList(Model.Myselect.Items, "ID", "Name"),"-请选择角色-", new Dictionary<string, object> { { "lay-verify", "required" }, { "lay-vertype", "tips" }, { "class", "layui-input" } })
        </div>*@
	   <div class="layui-input-block" id="tag_ids2"></div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">题目名称</label>
        <div class="layui-input-block">
            <input type="text" name="TRY_SUBJECT" placeholder="题目名称" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">答案</label>
        <div class="layui-input-block">
                <div class="layui-input-inline" style="width:260px;"><input type="text" name="TRY_KEY" placeholder="直接填写A、B、C、D即可" autocomplete="off" class="layui-input"></div>
                <div class="layui-input-inline" style="width:380px;"><label class="layui-form-label addwidth" style="width:160px;">答案注意字词</label><input type="text" name="CLASS" style="width:auto;" placeholder="答案标注关键字或词多个请用逗号(,)分隔" value="左右,右边" autocomplete="off" class="layui-input"><font style="color:red">友情提示：答案标注关键字或词多个请用逗号(,)分隔</font></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">A选项</label>
        <div class="layui-input-block">
            <input type="text" name="a" placeholder="请输入内容" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">B选项</label>
        <div class="layui-input-block">
            <input type="text" name="b" placeholder="请输入内容" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">C选项</label>
        <div class="layui-input-block">
            <input type="text" name="c" placeholder="请输入内容" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">D选项</label>
        <div class="layui-input-block">
            <input type="text" name="d" placeholder="请输入内容" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>

        <div class="layui-form-item">
            <label class="layui-form-label">图片</label>
            <div class="layui-input-inline">
                <input name="img" id="img" class="layui-input">
            </div>
            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                <button type="button" class="layui-btn layui-btn-primary" id="btnUpload">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">语音提示</label>
            <div class="layui-input-inline">
                <input name="voice"  id="voice" class="layui-input">
            </div>
            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                <button type="button" class="layui-btn layui-btn-primary" id="btnUploadvoice">
                    <i class="layui-icon">&#xe67c;</i>上传语音
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">视频讲解</label>
            <div class="layui-input-inline">
                <input name="video"  id="video" class="layui-input">
            </div>
            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                <button type="button" class="layui-btn layui-btn-primary" id="btnUploadvideo">
                    <i class="layui-icon">&#xe67c;</i>上传视频
                </button>
            </div>
        </div>

	<div class="layui-form-item">
			<label class="layui-form-label">本题类型</label>
			<div class="layui-input-block">
				<input type="radio" name="qustType" value="001" title="判断题" >
                <input type="radio" name="qustType" value="002" title="选择题" checked>
				<input type="radio" name="qustType" value="003" title="多选题" >
			</div>
	</div>
	<div class="layui-form-item">
			<label class="layui-form-label">是否显示</label>
			<div class="layui-input-block">
				<input type="radio" name="display" value="0" title="否">
				<input type="radio" name="display" value="1" title="是" checked>
			</div>
	</div>

   <div class="layui-form-item">
        <label class="layui-form-label">排序编号</label>
        <div class="layui-input-block" style="width:306px;">
            <input type="text" name="Sequence"  lay-verify="number" value="0" autocomplete="off" onkeyup="value=yznumber(this.value)" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    /*自定义处理数字*/
    function yznumber(value) {
        value = value.replace(/[^\d]/g, '').replace(/^0{1,}/g, '');
        if (value != '')
            value = parseFloat(value);
        else
            value = parseFloat(0);
        return value;
    }

    layui.use(["form", "laydate", "angelLayer", "angelUtils", "upload", "layer", 'selectM'], function () {
        var form = layui.form;
        var laydate = layui.laydate;
        var angelLayer = layui.angelLayer;
        var angelUtils = layui.angelUtils;
        var upload = layui.upload;
        var layer = layui.layer;
        var selectM = layui.selectM;
        var $ = layui.$;

        angelUtils.ajax("api/atikuclassapi/getClassList", "get", {}, true).done(function (data) {
            tagData = data.data;
            //console.log(tagData);
            //多选标签-所有配置
            var tagIns2 = selectM({
                //元素容器【必填】
                elem: '#tag_ids2'
                //候选数据【必填】
              , data: tagData
                //默认值
              , selected: [@Model.tikus.SortID]
                //最多选中个数，默认5
               , max: 30
                //input的name 不设置与选择器相同(去#.)
               , name: 'SortID'
                //值的分隔符
                , delimiter: ','
                //候选项数据的键名
                , field: { idName: 'id', titleName: 'sortName' }
            });
        }).fail(function (error) {
            console.log(error)
        });


        var uploadInst = upload.render({
            elem: '#btnUpload' //绑定元素
            , url: '/Upload/ExportFile/' //上传接口
            , size: '@ViewBag.MaxFileUpload'
            , exts: '@ViewBag.UploadFileType'
            , done: function (res) {  //上传完毕回调
                //假设code=0代表上传成功
                if (res.code == 0) {
                    //do something （比如将res返回的图片链接保存到表单的隐藏域）
                    $("#img").val(res.data.src);
                }
            }
            , error: function () { //请求异常回调

            }
        });

        var uploadvoice = upload.render({
            elem: '#btnUploadvoice' //绑定元素
            , url: '/Upload/ExportFilevoice/' //上传接口
            , size: '@ViewBag.MaxFileUpload'
            , exts: '@ViewBag.UploadFileType'
            , done: function (res) {  //上传完毕回调
                //code=0代表上传成功
                if (res.code == 0) {
                    //do something （比如将res返回的音频链接保存到表单的隐藏域）
                    $("#voice").val(res.data.src);
                }
            }
            , error: function () { //请求异常回调

            }
        });
        //视频
        var uploadvideo = upload.render({
            elem: '#btnUploadvideo' //绑定元素
            , url: '/Upload/ExportFilevideo/' //上传接口
            , size: '@ViewBag.MaxFileUpload'
            , exts: '@ViewBag.UploadFileType'
            , done: function (res) {  //上传完毕回调
                //code=0代表上传成功
                if (res.code == 0) {
                    //do something （比如将res返回的音频链接保存到表单的隐藏域）
                    $("#video").val(res.data.src);
                }
            }
            , error: function () { //请求异常回调

            }
        });


        //给表单赋值
        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "ID": "@Model.tikus.ID",
            "SortID": "@Model.tikus.SortID",
            "TRY_SUBJECT": "@Model.tikus.TRY_SUBJECT",
            "TRY_KEY": "@Model.tikus.TRY_KEY",
            "a": "@Model.tikus.a",
            "b": "@Model.tikus.b",
            "c": "@Model.tikus.c",
            "d": "@Model.tikus.d",
            "CLASS": "@Model.tikus.CLASS",
            "img": "@Model.tikus.img",
            "voice": "@Model.tikus.voice",
            "video": "@Model.tikus.video",
            "display": "@Model.tikus.display",
            "qustType": "@Model.tikus.qustType",
            "Sequence": "@Model.tikus.Sequence"
        });

        form.render(); //更新全部
        form.on("submit(add)", function (data) {
            angelUtils.ajax("api/atikuapi/postedit", "post", data.field, true).done(function (response) {
                angelLayer.greenTickMsg(response.message, function () {
                    parent.location.reload(); // 父页面刷新
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引 再执行关闭
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>

