<%@ 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">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="KKGL_KKGL_KKGL_T" html='<li class="layui-this"><a href="${ctx}/bankCard/findBankCardList">开卡管理</a></li>'/>
                <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 layuiadmin-card-header-auto" >
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">用户名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="customerName" class="layui-input" id="customerName" >
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">身份证号码：</label>
                        <div class="layui-input-block">
                            <input type="text" name="idCode" class="layui-input" id="idCode" >
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">开卡状态：</label>
                        <div class="layui-input-block">
                            <select id="status" name="status">
                                <option value="">请选择</option>
                                <option value="1">申请已受理</option>
                                <option value="2">预开户成功</option>
                                <option value="3">预开户失败</option>
                                <option value="4">正式开户成功</option>
                                <option value="5">正式开户失败</option>
                                <option value="7">销户失败</option>
                                <option value="8">销户中</option>
                                <option value="-1">待开卡</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">资方名称：</label>
                        <div class="layui-input-block">
                            <select name="partner" id="partner" lay-search>
                                <option value="">请选择</option>
                                <c:forEach items="${paterns}" var="data">
                                    <option value="${data.columns.id}">${data.columns.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </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;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();
        var zxBtn = '${fns:checkPagePermission(request, "KKGL_KKGL_ZX_B")}';
        var tbBtn = '${fns:checkPagePermission(request, "KKGL_KKGL_TBZT_B")}';
        //方案信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/bankCard/bankCardListDate'
            , 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: '操作',
                    align: 'center',
                    fixed: 'left',
                    minWidth: 150,
                    templet: function (d) {
                        var html = "";
                        if (d.coun == "0" && d.status != '6' && d.status != '7' && d.status != '8') {
                            if(d.partnerId == "04" && d.status == '-1'){
                                html += '<a href="#" class="layui-table-link" lay-event="view">查看</a>&nbsp;';
                            }else{
                                if(zxBtn =='0' && d.partnerId == '01') {
                                    html += '<a href="#" class="layui-table-link" lay-event="disabled">注销</a>&nbsp;';
                                }
                            }

                        } else if (d.status == '8') {
                            if(tbBtn =='0') {
                                html += '<a href="#" class="layui-table-link" lay-event="syscStatus">同步状态</a>&nbsp;';
                            }
                        } else {
                            html += '--';
                        }
                        return html;

                    }

                }
                /*, {field: 'id', minWidth: '4%', checkbox: true, align: 'center', fixed: 'left'}
                 , {field: 'sign', title: '操作', minWidth: 120, align: 'center', fixed: 'left'
                   , templet: function (d) {
                       var html = "";
                       if (downloadBtn == "0") {
                           if(d.status != '1'){
                               html += '<a href="#" class="layui-table-link" onclick="contractDetail(\'' + d.entryId + '\')">下载</a>&nbsp;';
                           }
                       } else {
                           html += '--';
                       }
                       return html;
                   }
               }*/
                , {field: 'partnerId', title: '资方id', minWidth: 200, align: 'center', exportable: true,hide:true}
                , {field: 'tenantName', title: '用户姓名', minWidth: 200, align: 'center', exportable: true}
                , {field: 'idCode', title: '身份证号', minWidth: 200, align: 'center', exportable: true}
                , {field: 'tenantMobile', title: '联系方式', minWidth: 200, align: 'center', exportable: true}
                , {field: 'companyName', title: '项目公司', minWidth: 200, align: 'center',exportable:true }
                , {field: 'name', title: '所属资方', minWidth: 200, align: 'center',exportable:true }
                , {field: 'status', title: '开卡状态', minWidth: 150, align: 'center',exportable:true ,
                    templet: function (d) {
                        if (d.status == '1') {
                            return "申请已受理";
                        } else if (d.status == '2') {
                            return "预开户成功";
                        } else if (d.status == '3') {
                            return "预开户失败";
                        } else if (d.status == '4') {
                            return "正式开户成功";
                        } else if (d.status == '5') {
                            return "正式开户失败";
                        } else if (d.status == '6') {
                            return "销户成功";
                        } else if (d.status == '7') {
                            return "销户失败";
                        } else if (d.status == '8') {
                            return "销户中";
                        } else if (d.status == '9') {
                            return "工行受理中";
                        } else if (d.status == '10') {
                            return "已过期";
                        }else if (d.status == '-1') {
                            return "待开卡";
                        }
                        return "--";
                    }}
                , {field: 'account_code', title: '卡号', minWidth: 150, align: 'center',exportable:true}
            ],
            ]
            , 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;
                var idCode = data.idCode;
                var partnerId = data.partnerId;
                console.log("idCode",idCode)
                switch(obj.event){
                    case 'disabled':
                        layer.confirm('确定注销？',{
                            btn: ['确定', '取消'],
                            success: function (layero, index) {
                                this.enterEsc = function (event) {
                                    if (event.keyCode == 13 ) {
                                        //确认  执行的代码
                                       // changeStatus(id,'2');
                                        //  console.log("id------------->",id)
                                        cancelBankCard(idCode)
                                        //关闭弹窗
                                        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 () {
                                //确认执行的代码
                                cancelBankCard(idCode)
                            },
                            no: function () {

                            }
                        });
                        break;
                    case 'syscStatus':
                        lookCardStatus(idCode);
                        break;
                    case 'view':
                        layer.confirm('确定查看该状态么？',{
                            btn: ['确定', '取消'],
                            success: function (layero, index) {
                                this.enterEsc = function (event) {
                                    if (event.keyCode == 13 ) {
                                        //确认  执行的代码
                                        // changeStatus(id,'2');
                                        //  console.log("id------------->",id)

                                        view(idCode,partnerId)

                                        //关闭弹窗
                                        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 () {
                                //确认执行的代码
                                view(idCode,partnerId)
                            },
                            no: function () {

                            }
                        });
                        break;
                };
        });


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

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var active = {
            reload: function(){
                reload();
            }
        };
    });

    function reload(){
        table.reload('test', {
            where: {
                customerName:$("#customerName").val().trim(),
                idCode:$("#idCode").val().trim(),
                status:$("#status").val().trim(),
                partner:$("#partner").find("option:selected").prop("value").trim()
            }
        });
    }

    window.importMaterial = function(materials){
        childWin.importMaterial(materials);
    }

    function cancelBankCard(idCode) {
        var loadingIndex = layer.load(2, {shade: [0.5,'#fff']});
        $.ajax({
            type: "get",
            url: '${ctx}/main/yueXiuBankCard/cancelBankCardByIdCode?IdCode=' + idCode,
            success: function(res) {
                console.log("res",res)
                if (res.code == '200'){
                    layer.msg('销户成功！', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(res.errMsg)
                }
                layer.close(loadingIndex);
            },
            error: function(err) {
                layer.close(loadingIndex);
                console.log("err",err);
                layer.msg("系统错误，请联系管理员")
              //  layer.msg(err);
            }
        });
    };

    function view(idCode,partnerId) {
        var loadingIndex = layer.load(2, {shade: [0.5,'#fff']});
        $.ajax({
            type: "get",
            url: '${ctx}/main/huaRongBankCard/viewBankCardByIdCode?IdCode=' + idCode+"&partnerId="+partnerId,
            success: function(res) {
                console.log("res",res)
                if (res.code == '200'){
                    layer.msg('操作成功！', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(res.errMsg)
                }
                layer.close(loadingIndex);
            },
            error: function(err) {
                layer.close(loadingIndex);
                console.log("err",err);
                layer.msg("系统错误，请联系管理员")
                //  layer.msg(err);
            }
        });
    };

    function lookCardStatus(idCode) {
        var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
        $.ajax({
            type: "get",
            url: '${ctx}/main/yueXiuBankCard/lookBankCardByIdCode?IdCode=' + idCode,
            success: function(res) {
                console.log("res",res)
                if (res.code == '200'){
                    layer.msg('销户成功！', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(res.errMsg)
                }
                layer.close(index);
            },
            error: function(err) {
                layer.close(index);
                console.log("err",err);
                layer.msg("系统错误，请联系管理员")
                //  layer.msg(err);
            }
        });
    };

</script>
</body>
</html>

