
@{
    ViewBag.Title = "Managerlist";
    Layout = "~/Views/Shared/_LayoutList.cshtml";
}
<!--模糊搜索区域-->
<div class="layui-row">
    <form class="layui-form layui-col-md12 angel-search">
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="请输入题目名称" name="sortName" autocomplete="off">
        </div>
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="请输入选项内容" name="show" autocomplete="off">
        </div>
			<button class="layui-btn" lay-submit="" lay-filter="search">
				<i class="layui-icon">&#xe615;</i>
			</button>
    </form>
</div>
<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
<script>
    layui.use(["table", "form", "laydate", "angelLayer", "angelUtils"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var angelLayer = layui.angelLayer;
        var angelUtils = layui.angelUtils;

        var AllTable = table.render({
            elem: "#tableId",
            url: "/api/atikuksapi/list",
            limit: 10,
            page: true,
            toolbar: "#toolbarTpl",
            size: "sm",
            cols: [[
                { type: "checkbox" },
                { field: "id", title: "ID", width: 60, sort: true },
                { field: "trY_SUBJECT", title: "题目", width: 280 },
                { field: "trY_KEY", title: "答案", width: 60 },
                { field: "a", title: "A选项", width: 120 },
                { field: "b", title: "B选项", width: 120 },
                { field: "c", title: "C选项", width: 120 },
                { field: "d", title: "D选项", width: 120 },
                { field: "sortID", title: "分类ID", width: 80 },
                { field: "sequence", title: "排序", width: 60 },
                { field: "display", title: "是否显示", width: 80, templet: "#enableddisplayTpl" },
                { title: "操作", width: 110, align: "center", fixed: "right", templet: "#operationTpl"}
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        form.on("submit(search)", function (data) {
            AllTable.reload({
                where: data.field,
                page: { curr: 1 }
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
                case "batchDel":
                    batchDel();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            var data = obj.data;

            switch (obj.event) {
                case "edit":
                    edit(data.id);//field Id 和 数据库表字段 Id 要一致
                    break;
                case "del":
                    del(data.id);
                    break;
            }
        });

        function add() {
            angelLayer.open("添加科四题库", "/Admin/Tikuks/Add", "90%", "90%", null, null);
        }

        function batchDel() {
            angelLayer.confirm("确定要批量删除吗？", function (index) {
                layer.close(index);
                var idsStr = angelUtils.tableBatchCheck(table);
                //alert(idsStr);
                if (idsStr) {
                    angelUtils.ajax("api/atikuksapi/batchdelete", "get", { idsStr: idsStr }, true).done(function (response) {
                        angelUtils.tableSuccessMsg(response.message);
                    }).fail(function (error) {
                        console.log(error)
                    });
                }
            });
        }

        function edit(id) {

            angelLayer.open("编辑", "/Admin/Tikuks/Edit/" + id, "90%", "90%", null, null);
        }

        function del(id) {
            angelLayer.confirm("确定要删除吗？", function () {
                angelUtils.ajax("api/atikuksapi/delete", "get", { id: id }, true).done(function (response) {
                    angelUtils.tableSuccessMsg(response.message);
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }


    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel">批量删除</button>
		<button class="layui-btn layui-btn-sm" lay-event="add">添加题库</button>
	</div>
</script>
<!-- 行工具栏模板 -->
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
	<a href="javascript:" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
	<a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
<!-- 启用|停用模板 -->
<script type="text/html" id="enableddisplayTpl">
    {{#  if(d.display==1){ }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">已启用</span>
    {{#  } else{ }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">已停用</span>
    {{#  } }}
</script>
<!-- 性别模板 -->
<script type="text/html" id="genderTpl">
    {{#  if(d.Gender){ }}
    <span>男</span>
    {{#  } else{ }}
    <span>女</span>
    {{#  } }}
</script>
