<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代理商准入申请</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}/static/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
</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="DSPYW_DLSZRSQ_DLSZRSQ"
                                       html='<a href="${ctx}/flowpath/traderApply/traderApplyList"><li class="layui-this">代理商准入申请</li></a>'/>
                <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-md3 layui-col-sm3">
                    <label class="layui-form-label">代理商名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" id="traderName" >
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label">实控人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="actual_contacts" class="layui-input" id="actualContacts" >
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label">联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="telephone" class="layui-input" id="telephone" >
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label">业务联系人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="contacts" class="layui-input" id="contacts" >
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label">业务联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" class="layui-input" id="mobile" >
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" class="layui-input" id="remarks" >
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label">申请时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="create_timeMin" class="layui-input pointer" readonly
                                   id="createTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="create_timeMax" class="layui-input pointer" readonly
                                   id="createTimeMax"
                                   placeholder="结束日期">
                        </div>
                    </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">
                <div class="layui-btn-container">
                    <sfTags:flowableAddPermission formId="${formId}" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="addTraderApply"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
                </div>
            </script>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.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'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = layui.table;
        tableExt.render({
            elem: '#test'
            , height: 'full-180'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/flowpath/traderApply/findtraderApplyList'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {type: 'numbers',title:'序号'}
                ,{field :'id',hide:true }
                , {field: 'id', title: '操作', minWidth: 150, align: 'center',
                    templet: function (d) {
                        var add='';
                        if(d.status == '1'){
                            var fg=d.audit;
                            if("1"==fg){
                                add+= '<a class="layui-table-opt-link" lay-event="audit">审批</a>';
                            }
                        }else if((d.status == '0' || d.status == '2') && d.create_by == '${userId}'){
                            add += '<a class="layui-table-link ml-10" lay-event="edit">编辑</a>';
                            add +='<a class="layui-table-opt-link ml-10" lay-event="delete">删除</a>';
                        }
                        if(d.lookAuth=='1' || d.audit=='1'){
                            add += '<a class="layui-table-link ml-10" lay-event="detail">查看</a>';
                        }
                        if(isBlank(add)){
                            add+='--';
                        }
                        return add;
                    }
                }
                ,{field:'name', title: '代理商名称',align: 'center',minWidth: 150}
                ,{field:'task_name', title: '审批状态',align: 'center',minWidth: 90}
                ,{field:'login_name', title: '登录账号',align: 'center',minWidth: 100}
                ,{field:'contacts', title: '业务联系人',align: 'center',minWidth: 100}
                ,{field:'mobile', title: '联系电话',align: 'center',minWidth: 100}
                ,{field:'actual_contacts', title: '实控人',align: 'center',minWidth: 100}
                ,{field:'telephone', title: '联系电话',align: 'center',minWidth: 100}
                ,{field:'bond', title: '保证金',align: 'center',minWidth: 75}
                ,{field:'bank_name', title: '开户银行',align: 'center',minWidth: 100}
                ,{field:'bank_code', title: '银行账号',align: 'center',minWidth: 100}

                ,{field:'tax_number', title: '统一信用代码',align: 'center',minWidth: 100}
                ,{field:'traderAddressfrom', title: '代理商地址',align: 'center',minWidth: 200}
                ,{field:'takeAddress', title: '收货地址',align: 'center',minWidth: 200}
                ,{field:'remarks', title: '备注',align: 'center',minWidth: 180}
                ,{field:'creator', title: '申请人',align: 'center',minWidth: 100}
                ,{field:'department_name', title: '所属部门',align: 'center',minWidth: 100}
                ,{field:'create_time', title: '申请时间',align: 'center',minWidth: 150}
            ]],done:function(res,cuss,count){
                console.log(res)
            }
            ,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"));
                }
            }
        });
        laydate = layui.laydate;

        //开始日期
        var createTimeMin = laydate.render({
            elem: '#createTimeMin'
            , type: 'date'
            , done: function (value, date) {
                //更新结束日期的最小日期
                createTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                createTimeMax.config.elem[0].focus();
            }
        });
        //结束日期
        var createTimeMax = laydate.render({
            elem: '#createTimeMax'
            , type: 'date'
            , done: function (value, date) {
                //更新开始日期的最大日期
                createTimeMin.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        table.on('toolbar(test)',function(obj) {
            if (obj.event === 'addTraderApply') {
                layer.open({
                    type: 2,
                    title: '新增',
                    content: '${ctx}/flowpath/traderApply/addTrderApply',
                    area: ['98%', '90%'],
                });
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {//编辑地址
                var id = data.id;
                layer.open({type: 2,
                    title: '编辑信息',
                    content: '${ctx}/flowpath/traderApply/addTrderApply?id='+id,
                    area: ['98%', '90%'],
                });
            }else if (obj.event === 'audit') {//编辑地址
                var id = data.id;
                layer.open({type: 2,
                    title: '审批',
                    content: '${ctx}/flowpath/traderApply/traderApplyDetail?from=audit&id='+id,
                    area: ['90%', '90%'],
                });
            }else if (obj.event === 'detail') {//查看详情
                var id = data.id;
                layer.open({type: 2,
                    title: '查看信息',
                    content: '${ctx}/flowpath/traderApply/traderApplyDetail?id='+id,
                    area: ['90%', '90%'],
                });
            }else if (obj.event === 'delete') {//删除工程师
                var id = data.id;
                layer.confirm('您确定要删除代理商申请吗',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                deleteTraderApply(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 () {
                        //确认执行的代码
                        deleteTraderApply(id);
                    },
                    no: function () {

                    }
                });
            }
        });

        //监听搜索
        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 deleteTraderApply(id){
            $.ajax({
                type: "POST",
                url: "${ctx}/flowpath/traderApply/delete",
                data: {
                    id: id
                },
                success: function (result) {
                    if (result.code == '200') {
                        layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                            window.location.reload();
                        });
                    } else if (result.code == '501') {
                        layer.msg('当前数据不满足删除条件！', {icon: 2});
                    } else {
                        layer.msg('删除失败！'+result.errMsg, {icon: 2});
                    }
                },
                error: {}
            })
        }


        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: {
                name: $('#name').val().trim(),
                telephone:$("#mobile").val().trim()
            }
        });
    }


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