<%@ 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="GYSGL_GYSGL_GYSGL_T" html='<li class="layui-this"><a href="${ctx}/supplySupplierManage/supplierPage">供应商管理</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" >
            <form class="layui-form layui-card" action="" 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" name="name" class="layui-input" id="name" >
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">企业负责人：</label>
                        <div class="layui-input-block">
                            <input type="text" name="actualContacts" class="layui-input" id="actualContacts" >
                        </div>
                    </div>
                    <div class="layui-col-lg2 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-md2 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-md2 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-lg2 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-lg4 layui-col-sm6">
                        <label class="layui-form-label">申请时间：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeSta" id="createTimeSta" class="layui-input"  placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeEnd" id="createTimeEnd" class="layui-input"  placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

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

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
<%--
<%--    <sfTags:pagePermission authFlag="GYSGL_GYSGL_XZ_T" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增 </button>'/>--%>
<%--    <sfTags:pagePermission authFlag="GYSGL_GYSGL_BD_T" html='<button class="layui-btn layui-btn-sm" id="bindBtn" lay-event="bind"><i class="layui-icon layui-icon-ok-circle"></i>绑定</button>'/>--%>
<%--    <sfTags:pagePermission authFlag="GYSGL_GYSGL_JCBD_T" html='<button class="layui-btn layui-btn-sm" id="unbind" lay-event="unbind"><i class="layui-icon layui-icon-close-fill"></i>解除绑定</button>'/>--%>
    <sfTags:pagePermission authFlag="GYSGL_GYSGL_SC_T" html='<button class="layui-btn layui-btn-sm" id="deleteBtn" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除 </button>'/>


</div>
</div>
<script type="text/html" id="table-toolbar">
    {{# if('3' == d.applyStatus){ }}
    <sfTags:flowableAddPermission formId="02" html='<a class="layui-table-opt-link" href="#" lay-event="edit">编辑</a>'/>
    {{# }else{ }}
    {{# } }}
    <a class="layui-table-opt-link" href="#" lay-event="detail">查看</a>
</script>
<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','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = layui.table;
        var excel = layui.excel;
        var laydate = layui.laydate;

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

        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/supplySupplierManage/supplierList'
            , 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',rowspan:'2', fixed: 'left'}
                , {field : 'id', minWidth : '4%',checkbox : true,align : 'center',rowspan:'2' , fixed: 'left'}
                , {field:'id', title: '操作', minWidth: 150,toolbar: '#table-toolbar',align: 'center', fixed: 'left'}
                , {field: 'name', title: '供应商名称', minWidth: 150, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'login_name', title: '登录账号', minWidth: 200, align: 'center',exportable:true ,rowspan:'2'}
               /* , {field: 'contacts', title: '法定代表人', minWidth: 150, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'mobile', minWidth: 180, title: '联系电话', align: 'center',exportable:true ,rowspan:'2'}*/
                , {field: 'actual_contacts', title: '企业负责人', minWidth: 150, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'telephone', minWidth: 180, title: '联系电话', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'bank_name', minWidth: 180, title: '开户行', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'bank_code', minWidth: 180, title: '银行账号', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'tax_number', minWidth: 180, title: '统一信用代码', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'address', minWidth: 180, title: '供应商地址', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'remarks', minWidth: 180, title: '备注', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'create_time', minWidth: 180, title: '准入时间', align: 'center',exportable:true ,rowspan:'2'}
            ],
            ]
            ,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('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'add') {
                layer.open({
                    type: 2,
                    title: '新增',
                    content: '${ctx}/supplySupplierManage/editSupplierPage',
                    area: ['90%', '90%']
                });
            } else if (obj.event === 'delete') {
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }
                var ids="";
                for(var i=0;i<data.length;i++){
                    ids+=data[i].id+",";
                }
                var indexla = layer.confirm('您确定要删除供应商吗？', {
                    btn: ['确定', '取消'], //按钮
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13) {
                                //确认  执行的代码

                                //关闭弹窗
                                layer.close(index);
                                deleteSupp(ids);
                                //取消连续回车键，导致不断弹出询问框
                                $(':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 () {
                        //确认执行的代码
                        layer.close(index);
                        deleteSupp(ids);
                    },
                    no: function () {

                    }
                })

            }else if(obj.event === 'bind'){
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }
                if (data.length > 1) {
                    layer.msg("请选择一条数据",{icon:5,anim:6});
                    return;
                }
                var id=data[0].id;
                layer.open({
                    type: 2,
                    title: '绑定',
                    content: '${ctx}/supplySupplierManage/bindSupervisionPage?id='+id,
                    area: ['30%','35%']
                });
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
             if (obj.event === 'edit') {//编辑
                var editId = data.id;
                layer.open({
                    type: 2,
                    title: '编辑',
                    content: '${ctx}/flowpath/supplySupplierApply/addSupplierApply?supplierId='+editId,
                    area: ['98%', '90%'],
                });
            } else if (obj.event === 'detail') {
                 layer.open({type: 2,
                     title: '查看信息',
                     content: '${ctx}/supplySupplierManage/detailSupplierPage?id='+data.id+'&type=0',// type=0表示查看
                     area: ['90%', '90%']
                 });
             }
        });

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

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




    });

    function deleteSupp(ids){
        $.ajax({
            type: "POST",
            url: "${ctx}/supplySupplierManage/deleteSupplier",
            data: {
                ids: ids
            },
            success: function (result) {
                if(result.code=='200'){
                    layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg('删除失败!', {icon: 2});
                }
            },
            error:{
            }
        })
    }

    function reload(){
        table.reload('test', {
            where: {
                number:$("input[name='number']").val().trim(),
                name: $('#name').val().trim(),
                bindingFlag:$("select[name='bindingFlag']").val().trim(),
                createTimeSta:$("#createTimeSta").val().trim(),
                createTimeEnd:$("#createTimeEnd").val().trim()
            }
        });
    }



    function  denglsj(id,userId) {
        console.log("siteInfo" + id +" userId : "+ userId)
        parent.denglusdj(id,userId);
    }

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

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