<%@ 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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <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="XMGL_DJFXM_DJFXM_T" html='<a href="${ctx}/customerEntry/waitDeliver"><li class="layui-this">待交付项目</li></a>'/>
                <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" 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" >
                        <select name="projectCode">
                            <option value="">请选择</option>
                            <c:forEach items="${projectList}" var="project">
                                <option value="${project.columns.id}">${project.columns.code}</option>
                            </c:forEach>
                        </select>
                    </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="projectName" 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" name="powerStationCode" class="layui-input" >
                    </div>
                </div>
                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">代理商名称：</label>
                        <div class="layui-input-block">
                            <select name="traderId" lay-search>
                                <option value="">请选择</option>
                                <c:forEach items="${traderList}" var="trader">
                                    <option value="${trader.columns.id}">${trader.columns.name}</option>
                                </c:forEach>
                            </select>
                        </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="traderMobile" class="layui-input">
                        </div>
                    </div>
                </c:if>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">验收人：</label>
                    <div class="layui-input-block" >
                        <select name="checkAcceptBy">
                            <option value="">请选择</option>
                            <c:forEach items="${empList}" var="emp">
                                <option value="${emp.columns.user_id}">${emp.columns.name}</option>
                            </c:forEach>
                        </select>
                    </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="tenantName" 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" name="tenantAddress" 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="installWay">
                            <option value="">请选择</option>
                            <c:forEach items="${installWays}" var="installWay">
                                <option value="${installWay.columns.id}">${installWay.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">屋顶类型：</label>
                    <div class="layui-input-block" >
                        <select name="roofType">
                            <option value="">请选择</option>
                            <option value="平屋顶">平屋顶</option>
                            <option value="斜屋顶">斜屋顶</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="plan">
                            <option value="">请选择</option>
                            <c:forEach items="${plans}" var="plan">
                                <option value="${plan.columns.id}">${plan.columns.name}</option>
                            </c:forEach>
                        </select>
                    </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" >
                    </div>
                </div>
                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">标记类型：</label>
                    <div class="layui-input-block" >
                        <select name="flag" xm-select="flag"  xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                            <option value="">请选择</option>
                            <c:forEach items="${typeList}" var="flag">
                                <option value="${flag.columns.id}" >${flag.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                </c:if>
                <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" readonly name="checkAcceptTimeMin" class="layui-input" id="endStartTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" readonly name="checkAcceptTimeMax" class="layui-input" id="endEndTime" 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:pagePermission authFlag="XMGL_DJFXM_DJFXM__DCWL_B" html='<button class="layui-btn layui-btn-sm" lay-event="exportfittingBtn" id="exportfittingBtn"><i class="layui-icon layui-icon-ok-circle"></i>导出物料</button>'/>
<%--                    <sfTags:pagePermission authFlag="XMGL_DYSXM_DYSXM_YS_B" html='<button class="layui-btn layui-btn-sm" lay-event="accept" id="acceptBtn"><i class="layui-icon layui-icon-ok-circle"></i>验收</button>'/>--%>
                    <sfTags:pagePermission authFlag="XMGL_DYSXM_DYSXM_DC_B" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>
                </div>
            </script>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script>
    var entrycount=0;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        //layui.use(['table','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 type = "${user.userType}";

        var downloadReport = '${fns:checkPagePermission(request, "XMGL_DJFXM_DJFXM_XZYSBG_B")}';

        var djfan_but = '${fns:checkPagePermission(request, "XMGL_DJFXM_DJFXM_JF_B")}';

        var tuihui_but = '${fns:checkPagePermission(request, "XMGL_DJFXM_DJFXM_TH_B")}';

        var JJPer = '${fns:checkPagePermission(request, "XMGL_DSHXM_DSHXM_JJSQ_B")}';
        var JJSH = '${fns:checkPagePermission(request, "XMGL_DSHXM_DSHXM_SHJJ_B")}';

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

        tableExt.render({
            elem: '#test'
            , title:'待交付项目'
            , height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/customerEntry/ajaxForWaitOrder?status=8,11'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}

                ,{field : 'id', minWidth : 150, title: '操作',align : 'center',rowspan:'2' , fixed: 'left', templet: function(d){
                        var html ="";
                        if(!isBlank(d.management_type)){
                            console.log(d.apply_status+"------");
                            if(isBlank(d.next_apply_status) || d.next_apply_status == '0' || d.next_apply_status == '3'){
                                 /*JJPer == '0'? html= html+  "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"preInputEntry('"+d.id+"')\">进件申请</a>&nbsp;&nbsp;":html;*/
                            }else if(d.next_apply_status == '1' ){
                                 JJSH == '0'? html= html+ "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"examineInputEntry('"+d.id+"')\">审核</a>&nbsp;&nbsp;":html;
                            }else if(d.next_apply_status == '2' && djfan_but == '0'){
                                    html = html +'<a href="#" class="layui-table-link" onclick="deliver(\''+d.id+'\')">交付</a>&nbsp;&nbsp;';

                            }

                        }else{
                            html = html +'<a href="#" class="layui-table-link" onclick="deliver(\''+d.id+'\')">交付</a>&nbsp;&nbsp;';
                        }
                        <c:if test="${user.userType ne '6' && user.userType ne '7' }">
                        if(tuihui_but == '0'){
                            html = html +'<a href="#" class="layui-table-link" onclick="returnEntry(\''+d.id+'\')">退回</a>';
                        }
                        </c:if>
                        return html;
                    }}

                ,{field : 'status', minWidth : 120 , title: '状态', align : 'center',rowspan:'2' ,exportable:true, fixed: 'left', templet: function(d){
                        if (d.status == '8') {
                            return '待交付';
                        } else if (d.status == '11') {
                            return '归档驳回';
                        }
                        return '';
                    },expFormat:function(d){
                        if (d.status == '8') {
                            return '待交付';
                        } else if (d.status == '11') {
                            return '归档驳回';
                        }
                        return '';
                    }}
                , {field: 'power_station_code', title: '电站编码',minWidth: 200, sort: false, align: 'center',fixed: 'left',exportable: true,templet: function(d){
                        var flag = d.flag;
                        var html="";
                        <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                        if(isBlank(flag)){//
                            html ="<i class=\"icon iconfont\" style=\"color: #8D8D8D\" onclick=\"customerEntryFlag('"+d.id+"')\">&#xe6b0;</i>";
                        }else{
                            html ="<i class=\"icon iconfont \" style=\"color: "+d.flag_type+";\" onclick=\"customerEntryFlag('"+d.id+"')\">&#xe6b0;</i>";
                        }
                        </c:if>
                        return html +  '<a href="#" class="layui-table-link" onclick="psDetail(\''+d.id+'\')">'+d.power_station_code+'</a>';
                    }}

                , {
                    field: 'planName',
                    title: '匹配方案',
                    minWidth: 100,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if(d.scheme_type=='1'){
                            if (isBlank(d.scheme_id)) {
                                return '——';
                            }
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\''+d.id+'\')">'+d.planName+'</a>';
                        }else if(isBlank(d.planName)){
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\''+d.id+'\')">查看方案</a>';
                        }else{
                            return '<a href="#" class="layui-table-link" onclick="planDetail(\''+d.id+'\')">'+d.planName+'</a>';
                        }
                    }
                }
                , {
                    field: 'scheme_id',
                    title: '验收报告',
                    minWidth: 100,
                    sort: false,
                    align: 'center',
                    exportable: false,
                    templet: function (d) {
                        return downloadReport == '0'? '<a href="#" class="layui-table-link" onclick="downloadReport(\''+d.id+'\')">查看</a>':'';
                    }
                }
                , {field: 'projectCode', title: '产品编号',minWidth: 130, sort: false, align: 'center',exportable:true}
                , {field: 'projectName', title: '产品名称',minWidth: 130, sort: false, align: 'center',exportable:true}

                , {field: 'whether_to_pay', title: '已支付',minWidth: 130, sort: false, align: 'center',exportable:true,  templet:function(d){
                        if(d.whether_to_pay=='2'){
                            return "是";
                        }else{
                            return "否";
                        }
                    },
                    expFormat: function (d) {
                        if (d.whether_to_pay == '2') {
                            return "是";
                        } else {
                            return "否";
                        }
                    }
                }
                , {
                    field: 'examine_remarks',
                    title: '审核备注',
                    minWidth: 130,
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {field: 'traderName', title: '代理商名称', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'traderMobile', title: '代理商电话', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'tenant_name', title: '业主姓名', minWidth: 150, sort: false, align: 'center', exportable: true}
                , {field: 'mobile', title: '联系电话', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'address', title: '安装地址', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'roof_type', title: '屋顶类型', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'angle', title: '朝向角度', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'distance', title: '估算并网距离（米）', minWidth: 180, sort: false, align: 'center', exportable: true}

                , {field: 'remarks', title: '备注',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'check_accept_name', title: '验收人',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'check_accept_time', title: '验收时间',minWidth: 150, sort: false, align: 'center',exportable:true}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '待交付项目',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '待交付项目',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            } ,done: function(res, curr, count){
                //得到数据总量
                entrycount = count;
            }
        });

        table.on('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'exportfittingBtn') {
                if(entrycount<1){
                    layer.msg('当前无数据导出', {time: 1000});
                    return ;
                }

                let hideSubmitForm = document.createElement("form");
                hideSubmitForm.id = "tempForm1";
                hideSubmitForm.method = "post";
                hideSubmitForm.action = "${ctx}/excel/doExportUserExcel";
                hideSubmitForm.target = "_blank";
                hideSubmitForm.appendChild(createHideInput("status", "8,11"));
                hideSubmitForm.appendChild(createHideInput("projectId", isBlank($("#projectId").val())?"":$("#projectId").val()));
                hideSubmitForm.appendChild(createHideInput("powerStationCode", isBlank($("#powerStationCode").val())?"":$("#powerStationCode").val()));
                hideSubmitForm.appendChild(createHideInput("tenantName", isBlank($("#tenantName").val())?"":$("#tenantName").val()));
                hideSubmitForm.appendChild(createHideInput("tenantAddress", isBlank($("#tenantAddress").val())?"":$("#tenantAddress").val()));
                hideSubmitForm.appendChild(createHideInput("installWay", isBlank($("#installWay").val())?"":$("#installWay").val()));
                hideSubmitForm.appendChild(createHideInput("roofType", isBlank($("#roofType").val())?"":$("#roofType").val()));
                hideSubmitForm.appendChild(createHideInput("plan", isBlank($("#plan").val())?"":$("#plan").val()));
                hideSubmitForm.appendChild(createHideInput("flag", isBlank($("#flag").val())?"":$("#flag").val()));
                hideSubmitForm.appendChild(createHideInput("remarks", isBlank($("#remarks").val())?"":$("#remarks").val()));

                hideSubmitForm.appendChild(createHideInput("checkAcceptTimeMin",isBlank($("#endStartTime").val())?"": $("#endStartTime").val()));
                hideSubmitForm.appendChild(createHideInput("checkAcceptTimeMax", isBlank($("#endEndTime").val())?"":$("#endEndTime").val()));
                hideSubmitForm.addEventListener('onsubmit',function(){
                    // this.openDownloadWindow(name);
                });
                document.body.appendChild(hideSubmitForm);
                hideSubmitForm.submit();
                document.body.removeChild(hideSubmitForm);

                //  window.open("${ctx}/excel/doExportUserExcel?status=3&"+$("#searchForm"))
            }
        });

        function  createHideInput(name, value){
            let hideInput = document.createElement("input");
            hideInput.type = "hidden";
            hideInput.name = name;
            hideInput.value = value;
            return hideInput;
        };
        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });

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


    function downloadReport(id){
        layer.open({
            type: 2,
            title: '验收报告',
            content: '${ctx}/customerEntry/downloadReport?opt=down&id=' + id,
            area: ['100%','100%']
        });
    }


    function downloadAttach(attach){
        attach=decodeURI(attach);
        attach = attach.replace(/\+/g,"%2B"); //
        window.location.href = '${commonStaticImgPath}' + attach;
    }


    function returnEntry(id){
        var indexla = layer.confirm('您确定要退回此项目？', {
            icon: 3,
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                url: "${ctx}/customerEntry/returnEntry",
                data: {
                    id: id
                },
                success: function (result) {
                    if(result.code=='200'){
                        layer.msg('退回成功！', {icon: 1, time: 1000}, function () {
                            table.reload('test'); //数据刷新
                        });
                    }else{
                        layer.msg('退回失败！', {icon: 2});
                    }
                },
                error:{

                }
            })
        }, function () {
            layer.close(indexla);
        });
    }


    function searchOrder() {
        //执行重载
        table.reload('test', {
            where: function (){
                return _serializeJson($("#searchForm"));
            }
        });
    }

    function deliver(){

    }

    //查看详情
    function psDetail(id){
        layer.open({
            type: 2
            , title: '电站详情'
            , content: '${ctx}/customerEntry/entryDetail?entryId=' + id
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }

    function customerEntryFlag(id){
        layer.open({
            type: 2,
            content: "${ctx}/customerEntry/getFlagcustomerEntry?customerEntryId="+id //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            ,title: "标记项目"
            ,area:["300px","260px"]
            ,closeBtn: 0
            ,shadeClose:true

        });
    }
    function planDetail(entryId){
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/planManage/viewMatchedPlan?entryId=' + entryId,
            area: ['80%','80%']
        });
    }
    function lookInputEntryStatus(id,type){
        layer.open({
            type: 2,
            title: '查看进件状态',
            content: '${ctx}/customerEntryExtra/lookInputEntryStatus?id='+id+'&type='+type,
            area : [ '650px', '450px' ],
            cancel:function(){
                table.reload('test'); //数据刷新
            }
        });
    }


    function deliver(id){
        layer.open({
            type: 2,
            title: '交付',
            content: '${ctx}/customerEntry/toDeliverPage?id=' + id,
            area: ['550px', '300px']
        });
    }

    function examineInputEntry(id){
        layer.open({
            type: 2,
            title: '审核进件申请',
            content: '${ctx}/customerEntryExtra/supplyTwoInputEntry?id='+id,
            area: ['63%','60%']
        });
    }

    function preInputEntry(id){
        layer.open({
            type: 2,
            title: '进件申请',
            content: '${ctx}/customerEntryExtra/supplyInputEntry?id='+id,
            area: ['63%','60%']
        });
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

