i<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .left-tree dt {
            font-size: 14px;
            font-weight: 600;
            padding: 5px 0;
            cursor: pointer;
        }
        .left-tree dd:hover {
            background-color: #eee !important;
        }
        .left-tree dd {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="SXGL_XMSX_DSH_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/waitDealItemPage">待审核</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_DFP_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/waitDispatchItemPage">待分配</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_YSH_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/endAuditItemPage">已审核</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_SDSZ_T"
                                       html='<li class=""><a href="${ctx}/itemManagement/proj/auditSettingPage">审单设置</a></li>'/>
                <sfTags:pagePermission authFlag="SXGL_XMSX_YXSDSZ_T"
                                       html='<li class="layui-this"><a href="${ctx}/itemManagement/proj/priorAuditSettingPage">优先审单设置</a></li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset" onclick="reset()">
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit
                        lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </ul>
        </div>

        <div class="layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-md4 layui-col-sm4">
                    <label class="layui-form-label">代理商：</label>
                    <div class="layui-input-block" >
                        <select name="traderId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${traderList}" var="trader">
                                <option value="${trader.columns.id}">${trader.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-col-md4 layui-col-sm4">
                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-block">
                        <select name="status">
                            <option value="">请选择</option>
                            <option value="0">启用</option>
                            <option value="1">禁用</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <sfTags:pagePermission authFlag='SXGL_XMSX_YXSDSZ_XZ_B' html='<button class="layui-btn layui-btn-sm" lay-event="add" id="add" >新增</button>'/>
            </script>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    var laydate;

    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
        ,form = layui.form
        ,tableExt = layui.tableExt;
        laydate = layui.laydate;
        table = layui.table;

        var bj_btn = '${fns:checkPagePermission(request, "SXGL_XMSX_YXSDSZ_BJ_B")}';
        var sc_btn = '${fns:checkPagePermission(request, "SXGL_XMSX_YXSDSZ_SC_B")}';
        var qy_btn = '${fns:checkPagePermission(request, "SXGL_XMSX_YXSDSZ_QY_B")}';
        var jy_btn = '${fns:checkPagePermission(request, "SXGL_XMSX_YXSDSZ_JY_B")}';
        tableExt.render({
            elem: '#test'
            , height: 'full-160'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/priorReviewSetting/getPriorReviewSettingList'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', minWidth: 50, title: '序号', align: 'center', type: 'numbers', fixed: 'left'}
                , {field: 'id', title: '操作', minWidth : 100, align: 'center', fixed: 'left', templet:function(d){
                        var htm="";
                        if(d.status == 0){
                            if(jy_btn =='0'){
                                htm+= '&nbsp;&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="disable">禁用</a>';
                            }
                            return htm;
                        }else if(d.status == 1){
                            if(bj_btn =='0'){
                                htm+= '<a class="layui-table-opt-link" lay-event="edit">编辑</a>';
                            }
                            if(qy_btn =='0') {
                                htm += '&nbsp;&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="enable">启用</a>';
                            }
                            if(sc_btn =='0'){
                                htm+= '&nbsp;&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="delete">删除</a>';
                            }
                            return htm;
                        }else{
                            return "--";
                        }
                    }
                }
                , {field: 'traderName', title: '代理商', minWidth: 200, align: 'center',exportable:true }
                , {field: 'reviewer1', title: '主审核人员', minWidth: 150, align: 'center',exportable:true }
                , {field: 'reviewer2', title: '备选人员1', minWidth: 150, align: 'center',exportable:true }
                , {field: 'reviewer3', title: '备选人员2', minWidth: 150, align: 'center',exportable:true }
                , {field: 'finally_update_time', title: '最新修改时间', minWidth: 150, align: 'center',exportable:true }
                , {field: 'status', title: '状态', minWidth: 60, align: 'center',exportable:true, templet:function(d){
                    if(d.status=='0'){
                        return "启用";
                    }else if(d.status=='1'  ){
                        return "禁用";
                    }else{
                        return "--";
                    }
                },expFormat:function (d) {
                    if(d.status=='0'){
                        return "启用";
                    }else if(d.status=='1'  ){
                        return "禁用";
                    }else{
                        return "--";
                    }
                }}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '优先审核',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '优先审核',
                where: function (){
                    //   console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('tool(test)',function(obj) {
            var data = obj.data;
            if(obj.event === 'edit'){
                layer.open({type: 2,
                    title: '编辑',
                    content: '${ctx}/priorReviewSetting/edit?id='+data.id,
                    area: ['90%', '90%'],
                    end: function(){
                    }
                });
            }else if(obj.event === 'delete'){
                var id=data.id;
                layer.confirm('确认删除该数据？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                deleteSetting(id);
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        deleteSetting(id);
                    },
                    no: function () {

                    }
                });
            }else if(obj.event === 'disable'){
                var status = '1';
                var id=data.id;
                var traderId=data.trader_id;
                layer.confirm('确认禁用该数据？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                changeStatus(id,status,traderId);
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        changeStatus(id,status,traderId);
                    },
                    no: function () {

                    }
                });
            }else if(obj.event === 'enable'){
                var id=data.id;
                var status = '0';
                var traderId=data.trader_id;
                layer.confirm('确认启用该数据？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                changeStatus(id,status,traderId);
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        changeStatus(id,status,traderId);
                    },
                    no: function () {

                    }
                });
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            switch (obj.event){
                case 'add':
                    layer.open({
                        type: 2,
                        title: '新增',
                        content: '${ctx}/priorReviewSetting/add',
                        area: ['90%','90%']
                    });
                    break;

            }
        })

        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });
    })

    $('input').on('keydown', function(event){
        if(event.keyCode == 13){
            //执行相关操作
            $("#searchBtn").click();
        }
    });

    function deleteSetting(id){
        $.post('${ctx}/priorReviewSetting/deletePriorReviewSetting', {id:id}, function (result) {
            if (result.code === '200') {
                layer.msg('操作成功', {time: 2000}, function () {
                    reload();
                });
            }else {
                layer.msg('操作失败！' + result.errMsg);
            }
        });
    }

    function changeStatus(id,status,traderId){
        $.post('${ctx}/priorReviewSetting/changeStatus', {id:id,status:status,traderId:traderId}, function (result) {
            if (result.code === '200') {
                layer.msg('操作成功', {time: 2000}, function () {
                    reload();
                });
            }else {
                layer.msg('操作失败！' + result.errMsg);
            }
        });
    }


    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    $('input').on('keydown', function(event){
        if(event.keyCode == 13){
            //执行相关操作
            $("#searchBtn").click();
        }
    });

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }
</script>
</body>
</html>
