<%@ 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-table-opt-link{margin: 0px 6px;}
    </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_XMGSSZ_JCXX_T" html='<li class="layui-this sf-tab"><a href="${ctx}/projectCompany/settings">基础信息</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 " lay-submit lay-filter="LAY-user-back-search" 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" name="name" id="name" 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="type">
                            <option value="">请选择</option>
                            <option value="0">项目公司</option>
                            <option value="1">EPC公司</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                    <label class="layui-form-label">所属资方：</label>
                    <div class="layui-input-block">
                        <select name="partnerId" >
                            <option value="">请选择</option>
                            <c:forEach items="${partnerList}" var="partner">
                                <option value="${partner.id}" >${partner.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" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_XZ_B" html='<button class="layui-btn layui-btn-sm" id="add" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
                <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_DRGS_B" html=' <button class="layui-btn layui-btn-sm" lay-event="importProjectCompany"><i class="layui-icon layui-icon-export"></i>导入项目公司</button>'/>
                <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_DRQY_B" html=' <button class="layui-btn layui-btn-sm" lay-event="importAuthorizedArea"><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="XTSZ_XMGSSZ_JCXX_CK_B" html='<a href="#" class="layui-table-link" lay-event="look">查看</a>'/>
    {{# if(d.status == '0'){ }}
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_BJ_B" html='<a class="layui-table-opt-link" lay-event="edit">编辑</a>'/>
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_JY_B" html='<a class="layui-table-opt-link" lay-event="disabled">禁用</a>'/>
<%--    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_BJ_B" html='<a class="layui-table-opt-link ml-10" lay-event="impower">授权</a>'/>--%>
    {{# }else if(d.status == '1'){ }}
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_QY_B" html='<a class="layui-table-opt-link" lay-event="canUse">启用</a>'/>
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_SC_B" html='<a class="layui-table-opt-link" lay-event="delete">删除</a>'/>
    {{# } }}

    {{# if(d.partner == '04'){ }}
    <sfTags:pagePermission authFlag="XTSZ_XMGSSZ_JCXX_YZSQ_B" html='<a class="layui-table-opt-link" lay-event="sealAuth">印章授权</a>'/>
    {{# } }}
</script>

<script type="text/javascript">
    var table;
    var $;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer','laydate','form'], function(){
        $ = layui.jquery;
        table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var  form = layui.form;
        //开始日期
        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
                });
            }
        });

        table.render({
            elem: '#test'
            ,toolbar : '#toolbarDemo'
            , height: 'full-180'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/projectCompany/projectCompanyList'
            ,cols: [[
                {type: 'numbers',title:'序号',fixed: 'left'}
                ,{field:'processId', title: '操作',toolbar: '#table-toolbar',fixed: 'left',align: 'center',width: 160}
                ,{field:'name', title: '公司名称',align: 'center',fixed: 'left', width:300}
                ,{field:'type', title: '公司性质',align: 'center', width:150
                    ,templet:function(d){
                        if(d.type=='0'){
                            return "项目公司";
                        }else if(d.type=='1'){
                            return "EPC公司";
                        }
                    }}
                ,{field:'enterprise_qualification_number', title: '统一社会信用代码',align: 'center', width:200}
                ,{field:'charge_person', title: '法定代表人',align: 'center', width:150}
                ,{field:'psn_account', title: '法人授权电话',align: 'center', width:150}
                ,{field:'charge_person_id_card', title: '法人身份证号',align: 'center', width:150}
                ,{field:'telephone', title: '联系电话',align: 'center', width:150}
                ,{field:'address', title: '公司注册地址',align: 'center' ,width: 200}
                /*,{field:'name', title: '租金设置',align: 'center'
                    ,templet:function(d){
                     return "查看";
                    }
                }*/
                ,{field:'company_code', title: '公司代码',align: 'center',width: 200}
                , {field: 'filing_type', title: '备案类型', align: 'center', width: 100, templet: function (d) {
                        var add = '';
                        if (d.filing_type == '1') {
                            add = '农户备案';
                        } else if (d.filing_type == '2') {
                            add = '项目公司备案';
                        }
                        return add;
                    }
                }
                , {field: 'partnerName', title: '所属资方',width: 230, align: 'center'}
                ,{field:'createTime', title: '创建时间',align: 'center',width: 180}
            ]]
            ,done: function(res, curr, count){

            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '基础信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '基础信息导出',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            switch (obj.event){
                case 'add':
                    layer.open({
                        title:'新增',
                        type: 2,
                        area: ["80%", "85%"],
                        content: '${ctx}/projectCompany/addProjectCompany'
                    })
                    break;
                case 'importProjectCompany':
                    layer.open({
                        type: 2,
                        title:"导入项目公司",
                        resize:false,
                        area: ['50%', '53%'],
                        content: '${ctx}/projectCompany/importProjectCompanyForm'
                    });
                    break;
                case 'importAuthorizedArea':
                    layer.open({
                        type: 2,
                        title:"导入授权区域",
                        resize:false,
                        area: ['50%', '53%'],
                        content: '${ctx}/projectCompany/importAuthorizedAreaForm'
                    });
                    break;
            }
        })

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'disabled'){
                layer.confirm('确定禁用？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                changeCompanyStatus(id,'1');
                                //关闭弹窗
                                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 () {
                        //确认执行的代码
                        changeCompanyStatus(id,'1');
                    },
                    no: function () {

                    }
                });
            } else if(obj.event === 'canUse'){
                layer.confirm('确认启用该项目公司？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                changeCompanyStatus(id,'0');
                                //关闭弹窗
                                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 () {
                        //确认执行的代码
                        changeCompanyStatus(id,'0');
                    },
                    no: function () {

                    }
                });
            } else if(obj.event === 'delete'){
                layer.confirm('确认删除该项目公司？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                changeCompanyStatus(id,'2');
                                //关闭弹窗
                                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 () {
                        //确认执行的代码
                        changeCompanyStatus(id,'2');
                    },
                    no: function () {

                    }
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    title:'编辑',
                    type: 2,
                    area: ["80%", "100%"],
                    content: '${ctx}/projectCompany/addProjectCompany?id='+id
                })
            } else if(obj.event === 'look'){
                layer.open({
                    title:'查看',
                    type: 2,
                    area: ["80%", "100%"],
                    content: '${ctx}/projectCompany/projectCompanyDetail?id='+id
                })
            }else if(obj.event ==='sealAuth'){
               var seal_external_auth=data.seal_external_auth;
               if(seal_external_auth=='3'){
                   layer.msg("印章已授权，无需再次授权!")
                   return;
               }

                layer.confirm('您确定要印章授权吗？', {
                    btn: ['确定', '取消'],
                    yes: function () {
                        var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
                        $.ajax({
                            url: '${ctx}/projectCompany/createSealAuth?companyId=' + data.id,
                            method: 'get',
                            dataType: 'JSON',
                            contentType: "application/json",
                            success: function (res) {
                                if (res.code == "200") {
                                    layer.close(index);
                                    layer.confirm(res.data, {btn: '关闭'} , function(index){
                                        layer.close(index);
                                    });
                                } else {
                                    layer.close(index);
                                    layer.msg(res.errMsg, {time: 3000});
                                }
                            },
                            error: function (data) {
                            }
                        });
                    }
                });
            }
            <%--else if(obj.event === 'impower'){--%>
            <%--    layer.open({--%>
            <%--        type: 2--%>
            <%--        ,title: '授权'--%>
            <%--        ,content: '${ctx}/projectCompany/rightsForm?id='+id--%>
            <%--        ,area: ['80%','80%']--%>
            <%--        ,success : function(layero) {--%>
            <%--            layero.find('.layui-layer-btn').css('text-align', 'center');--%>
            <%--            layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");--%>
            <%--        }--%>
            <%--    });--%>
            <%--}--%>
        });

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



    });

    function changeCompanyStatus(id,status){
        $.post('${ctx}/projectCompany/changeCompanyStatus', {id: id,status:status}, function(result){
            if("200" == result.code){
                layer.msg('操作成功', {time: 2000}, function () {
                    reload();
                });
            }else{
                layer.msg(result.errMsg);
            }
        });
    }

    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }

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

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

