<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 后台管理员</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta name="decorator" content="base" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
    <style>
        @font-face {
            font-family: 'iconfont';
            src: url('${ctxPlugin}/lib/font/iconfont.eot');
            src: url('${ctxPlugin}/lib/font/iconfont.eot?#iefix') format('embedded-opentype'),
            url('${ctxPlugin}/lib/font/iconfont.woff2') format('woff2'),
            url('${ctxPlugin}/lib/font/iconfont.woff') format('woff'),
            url('${ctxPlugin}/lib/font/iconfont.ttf') format('truetype'),
            url('${ctxPlugin}/lib/font/iconfont.svg#iconfont') format('svg');
        }
        .iconfont {
            font-family: "iconfont" !important;
            font-size: 16px;
            font-style: normal;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
      <div class="layui-tab layui-tab-brief">
          <ul class="layui-tab-title">
              <sfTags:pagePermission authFlag="XTSZ_GDBJ_GDBJ_T" html='<a href="${ctx}/yangguang/orderMarkSet/toMarkSetPage"><li class="layui-this">工单标记</li></a>'/>
          </ul>
      </div>
      <div class="layui-card-body">
      <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
      <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <sfTags:pagePermission authFlag="XTSZ_GDBJ_GDBJ_ADD_B" html='<button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
            <sfTags:pagePermission authFlag="XTSZ_GDBJ_GDBJ_UPDATE_B" html='<button class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>'/>
            <sfTags:pagePermission authFlag="XTSZ_GDBJ_GDBJ_DEL_B" html='<button class="layui-btn layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>'/>
        </div>
      </script>
    </div>
  </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/font/iconfont.js"></script>
<script>
    layui.use(['table','layer','laypage'], function(){
        $ = layui.$;
        table = layui.table;
        layer = layui.layer;
        laypage = layui.laypage;

        table.render({
            elem: '#test',
            height: 'full-150'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : false //开启分页
            , url: '${ctx}/yangguang/orderMarkSet/getMarkSetData'
            , cols: [[
                {type: 'numbers',title:'序号'}
                , {field: 'id', type: 'checkbox'}
                , {field: 'type', title: '标记图标', sort: false, align: 'center',templet:function(d){
                        return '<i class="icon iconfont" style="color: ' + d.type + ';">&#xe6b0;</i>';
                    }}
                , {field: 'name', title: '工单标记名称', align: 'center'}
                , {field: 'sort', title: '排序', align: 'center'}
                , {field: 'createTime', title: '创建时间', sort: false, align: 'center'}
            ]]
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var count = $(".layui-table").find("tbody").find("tr").length;
            //var count = obj.config.page.count;  开启分页后又用
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    if(count >=5){
                        layer.msg("标记图标已用完，不可再次添加！",{icon:2});
                        return;
                    }
                    layer.open({
                        type: 2
                        ,title: '新增'
                        ,content: '${ctx}/yangguang/orderMarkSet/addMarkPage?useType=1'
                        ,area: ['600px', '270px']
                        ,success : function(layero) {
                            layero.find('.layui-layer-btn').css('text-align', 'center');
                            layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                        }
                    });
                    break;
                case 'edit':
                    if(count >5){
                        layer.msg("标记图标已用完，不可编辑！",{icon:2});
                        return;
                    }

                    var data = checkStatus.data;
                    if (data.length < 1) {
                        layer.msg("请选择您要编辑的数据！",{icon:5,anim:6});
                    }else if(data.length > 1){
                        layer.msg("每次只能编辑一条数据！",{icon:5,anim:6});
                    }else{
                        layer.open({
                            type: 2
                            ,title: '编辑'
                            , content: '${ctx}/yangguang/orderMarkSet/toEditMarkPage?id=' + data[0].id
                            ,area: ['600px', '270px']
                            ,success : function(layero) {
                                layero.find('.layui-layer-btn').css('text-align', 'center');
                                layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                            }
                        });
                    }
                    break;
                case 'del':
                    var data = checkStatus.data;
                    if (data.length == '0') {
                        layer.msg("请选择您要删除的数据！",{icon:5,anim:6});
                        return;
                    }
                    var ids = "";
                    for(var i=0;i<data.length;i++){
                        ids += data[i].id + ",";
                    }
                    layer.confirm('确认要删除选中数据吗？', {icon:3}, function(index) {
                        delData(ids,index);
                    });
                    break;
            };
        });
    });

    function delData(ids,index){
        $.ajax({
            url: '${ctx}/yangguang/orderMarkSet/delMark',
            type: 'post',
            data: {
                ids: ids
            },
            success: function (data) {
                if (data == "200") {
                    layer.msg("删除成功！");
                    table.reload('test'); //数据刷新
                    layer.close(index); //关闭弹层
                } else {
                    layer.msg("删除失败！");
                }
            },
            complete: function () {
                noRepeat = false;
            }
        });
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>

