<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>变更类型设置</title>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card{box-shadow: none;}
    </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="XTSZ_BGLXSZ_LHHSZ_T" html='<a href="${ctx}/sysSettings/linkNumber/index"><li class="layui-this">联行号设置</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset" id="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" data-type="reload">
                     <i class="layui-icon fs-12">&#xe615;</i>
                     查询
                 </button>

            </ul>
        </div>
        <div class="layui-card-body" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">联行号：</label>
                    <div class="layui-input-block">
                        <input type="text" id="number" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">开户行：</label>
                    <div class="layui-input-block">
                        <input type="text" id="bankName" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">资方：</label>
                    <div class="layui-input-block" >
                        <select name="capitals" id="capitals"  xm-select="capitals" xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                            <option value="">请选择</option>
                            <c:forEach items="${paterns}" var="data">
                                <option value="${data.columns.id}">${data.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test-table-reload" lay-filter="table-toolbar"></table>
            <script type="text/html" id="toolbarDemo">
                <sfTags:pagePermission authFlag="LHHSZ_XZ_B" html='<button class="layui-btn layui-btn-sm" lay-event="addBtn"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
                <sfTags:pagePermission authFlag="LHHSZ_DR_B" html=' <button class="layui-btn layui-btn-sm" lay-event="import"><i class="layui-icon layui-icon-export"></i>导入</button>'/>
            </script>
        </div>
    </div>

</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/html" id="table-toolbar">
    <sfTags:pagePermission authFlag="LHHSZ_BJ_B" html='<a href="#" class="layui-table-link" lay-event="edit" >编辑</a>'/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <sfTags:pagePermission authFlag="LHHSZ_SC_B" html='<a href="#" class="layui-table-link" lay-event="del">删除</a>'/>
</script>

<script type="text/javascript">
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laydate'], function(){
        var tableExt = layui.tableExt;
        var layer = layui.layer;
        var $ = layui.jquery;
        laydate = layui.laydate;

        tableExt.render({
            elem: '#test-table-reload',
            height: 'full-160'
            ,toolbar : '#toolbarDemo'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/sysSettings/linkNumber/getList'
            ,cols: [[
                {type: 'numbers',title:'序号'}
                ,{field:'number', title: '联行号',minWidth: 100,align: 'center'}
                ,{field:'bank_name', title: '开户支行',minWidth: 300,align: 'center'
                }
                ,{field:'capitals', title: '资方',minWidth: 400,align: 'center',templet: function (d) {
                    var html = "";
                    if(d.capitals != null){
                        var arr = d.capitals.split(",");
                        for(var i = 0;i<arr.length;i++){
                            if(arr[i] == "01"){
                                html+="广州越秀融资租赁有限公司,"
                            }else if(arr[i] == "02"){
                                html+="华能,"
                            }else if(arr[i] == "03"){
                                html+="广州发展新能源集团股份有限公司,"
                            }else if(arr[i] == "04"){
                                html+="华融金融租赁股份有限公司,"
                            }
                        }
                        html = html.substring(0,html.length-1);
                    }else {
                        html = "--";
                    }
                        return html;
                }
                    }
                ,{field:'create_time', title: '创建时间',minWidth: 120,align: 'center'}
                ,{field:'id', title: '操作',align: 'center',toolbar: '#table-toolbar'}
            ]]
            ,done: function(res, curr, count){
                //   console.log("customer done", res);
            }
        });

        var table = tableExt.getLayTable();

        //监听行工具事件
        table.on('tool(table-toolbar)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'del'){
                layer.confirm('真的删除所选项吗？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                $.post('${ctx}/sysSettings/linkNumber/delete', {id: id}, function(result){
                                    if("200" == result){
                                        layer.msg("删除成功");
                                        obj.del();
                                        layer.close(index);
                                    } else {
                                        layer.msg("删除失败");
                                    }
                                });
                                //关闭弹窗
                                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 () {
                        //确认执行的代码
                        $.post('${ctx}/sysSettings/linkNumber/delete', {id: id}, function(result){
                            if("200" == result){
                                layer.msg("删除成功");
                                obj.del();
                                layer.close(index);
                            } else {
                                layer.msg("删除失败");
                            }
                        });
                    },
                    no: function () {

                    }
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    , title: '编辑'
                    , area: ['800px', '600px']
                    , content: '${ctx}/sysSettings/linkNumber/editPage?id=' + id
                })
            }
        });

        var active = {
            reload: function(){
                table.reload('test-table-reload', {
                    where: {
                        number: $('#number').val(),
                        bankName: $("#bankName").val(),
                        capitals: $("#capitals").find("option:selected").prop("value").trim()
                    }
                });
            }
        };

        //开始日期
        var insStart = laydate.render({
            elem: '#startTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });

        //结束日期
        var insEnd = laydate.render({
            elem: '#endTime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        // 监听头部事件
        table.on('toolbar(table-toolbar)', function(obj) {
            switch (obj.event) {
                case 'addBtn':
                    layer.open({
                        type: 2
                        , title: '新增'
                        , area: ['800px', '600px']
                        , content: '${ctx}/sysSettings/linkNumber/addPage'
                    })
                    break;
                case 'import':
                    layer.open({
                        type: 2,
                        title:"导入",
                        resize:false,
                        area: ['40%', '43%'],
                        content: '${ctx}/sysSettings/linkNumber/importBankNumberForm'
                    });
                    break;
            }
        })

        $("#reset").on('click', function () {
            $("#searchForm").find("select").val("");
            $("#searchForm").find("input").val("");
        })
    });
    function reload(){
        table.reload('test-table-reload', {
            page:{
                curr:1
            }
        });
    }
</script>
</body>
</html>
