<%@ 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">
</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_SQCSXM_SQCSXM_T" html='<a href="${ctx}/customerEntry/findRetrialList"><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>
        <form 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" id="projectId">
                            <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="powerStationCode" id="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" id="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" id="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">
                        <input type="text" name="tenantName" id="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" id="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" id="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" id="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">
                        <input type="text" name="remarks" id="remarks" 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="applyReasonName" id="applyReasonName" class="layui-input" >
                    </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" readonly name="applyTimeMin" class="layui-input" id="applyEndStartTime" placeholder="开始日期" >
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" readonly name="applyTimeMax" class="layui-input" id="applyEndEndTime" placeholder="结束日期" >
                        </div>
                    </div>
                </div>


            </div>
        </form>
    </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_SQCSXM_SQCSXM_SH_B" html='<button class="layui-btn layui-btn-sm" lay-event="FlagcustomerEntry" id="FlagcustomerEntry"><i class="layui-icon layui-icon-ok-circle"></i>审核</button>'/>
                    <sfTags:pagePermission authFlag="XMGL_SQCSXM_SQCSXM_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', 'formSelects'], function(){
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        formSelects = layui.formSelects;
        form = layui.form;
        table = tableExt.getLayTable();


        var downloadForm = '${fns:checkPagePermission(request, "XMGL_SQCSXM_SQCSXM_XZFJ_B")}';

        //开始日期
        var applyEndStartTime = laydate.render({
            elem: '#applyEndStartTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新结束日期的最小日期
                applyEndEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                applyEndEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var applyEndEndTime = laydate.render({
            elem: '#applyEndEndTime'
            /* ,type: 'datetime'*/
            ,done: function(value, date){
                //更新开始日期的最大日期
                /*createEndStartTime.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/findRetrialPage?apply=1'
            , where: _serializeJson($("#searchForm"))
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',fixed: 'left'}
                , {field: 'power_station_code', title: '电站编码',minWidth: 200, sort: false, align: 'center',fixed:'left',
                    exportable: true,
                    templet: function (d) {
                        return '<a href="#" class="layui-table-link" onclick="psDetail(\'' + d.id + '\')">' + d.power_station_code + '</a>';
                    }}
                , {
                    field: 'traderName',
                    title: '物料清单',
                    minWidth: 150,
                    sort: false,
                    align: 'center',
                    templet: function (d) {
                        return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"materialDetail('" + d.id + "')\">查看</a>&nbsp;&nbsp;";
                    }
                }
                , {field: 'attach', title: '附件',minWidth: 130, sort: false, align: 'center', templet: function(d){
                        if(d.scheme_type=='1'){
                            return downloadForm == '0'? '<a href="javascript:downloadAttach(\'' + d.attach + '\');" class="layui-table-link">下载</a>': '';
                        } else {
                            return "__";
                        }
                    }
                }
                , {
                    field: 'apply_reason_name',
                    title: '申请原因',
                    minWidth: 130,
                    sort: false,
                    align: 'center',
                    exportable: true
                }
                , {field: 'projectCode', title: '产品编号', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'projectName', 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: 'hire_status',
                    title: '租赁状态',
                    minWidth: 130,
                    sort: false,
                    align: 'center',
                    exportable: true,
                    templet: function (d) {
                        if (d.hire_status == '2') {
                            return "否";
                        } else {
                            return "是";
                        }
                    },
                    expFormat: function (d) {
                        if(d.status=='2'){
                            return "否";
                        }else{
                            return "是";
                        }
                    }}*/
                , {field: 'remarks', title: '备注',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'creator', title: '申请人',minWidth: 150, sort: false, align: 'center',exportable:true}
                , {field: 'create_time', title: '申请时间',minWidth: 180, 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 === 'FlagcustomerEntry'){
                var data = checkStatus.data;
                if (data.length !=1) {
                    layer.msg("请选择一条数据",{icon:5,anim:6});
                    return false;
                }
                var id=data[0].id;
                console.log(data)
                layer.open({
                    type: 2,
                    title: '审核',
                    content: '${ctx}/customerEntry/getexamineRetrial?objType=1&customerEntryId=' + id,
                    area: ['40%','40%']
                });
            }

        });

        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
                }
            });
        });
    })

    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 materialDetail(id) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '70%'],
            content: '${ctx}/material/order/materialList?id=' + id
        });
    }

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

    function deliver(){

    }

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

            }
        });
    }

    function planDetail(entryId){
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/planManage/viewMatchedPlan?entryId=' + entryId,
            area: ['80%','80%']
        });
    }

    function downloadImg(attach) {
        var name = attach.substring(0, attach.lastIndexOf(".") - 1);
        var suffix = attach.substring(attach.lastIndexOf("."));
        window.open('${commonStaticImgPath}'+attach)
       // location.href = '${ctx}/technical/imgDownload?path=' + '${commonStaticImgPath}' + attach + "&fileGS=" + suffix + "&name=" + name;
    }

    function inDoc(id){

    }

    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>

