<%@ 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" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-sacle=1, maximum-scale=1" >

    <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" />
    <style>
        .xm-select-parent .xm-select {
            min-height: 32px;
        }
    </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">
                <a href="${ctx}/customerEntry/completionRectificationList"><li class="layui-this">竣工结果查询</li></a>
                <a href="${ctx}/completion/completionOrder"><li>竣工单</li></a>
                <a href="${ctx}/rectification/rectificationOrder"><li>整改单</li></a>
                <a href="${ctx}/rectification/rectificationResult"><li>整改结果查询</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">
                        <input type="text" name="powerStationCode" id="powerStationCode" class="layui-input" >
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm2" style="width: 33.3%">
                    <label class="layui-form-label">竣工状态：</label>
                    <div class="layui-input-block">
                        <select name="isCheckAccept" lay-search>
                            <option value="">请选择</option>
                            <option value="0">未提交</option>
                            <option value="1">已提交</option>
                            <option value="2">已竣工</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="projectCompanyName" id="projectCompanyName" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm2" style="width: 33.3%">
                    <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-lg4 layui-col-sm4 layui-col-md4" style="margin-top: 5px" >
                    <label class="layui-form-label">验收区域：</label>
                    <div class="inline-block" style="width: 18%">
                        <select name="province" lay-search lay-filter="province"  id="province">
                            <option value="">省</option>
                            <c:forEach items="${province}" var="trader">
                                <option value="${trader.columns.ProvinceName}"  title="${trader.columns.ProvinceID}">${trader.columns.ProvinceName}</option>
                            </c:forEach>
                        </select>

                    </div>
                    <div class="inline-block" style="width: 18%;">
                        <select name="city" id="city" lay-filter="city"
                                lay-search>
                            <option value="">市</option>

                        </select>
                    </div>
                    <div class="inline-block" style="width: 18%">
                        <select name="area" id="area" lay-search>
                            <option value="">县/区</option>

                        </select>
                    </div>
                    <div class="inline-block" style="width: 20%">
                        <input type="text" name="address" class="layui-input">

                    </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="GFXMGL_JGZG_JG_B" html='<button class="layui-btn layui-btn-sm" lay-event="completion">竣工</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 formSelects;
    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;
        form = layui.form;
        table = tableExt.getLayTable();
        formSelects = layui.formSelects;
        var type = "${user.userType}";

        function getStatus(d) {
            var status =d.status;

            if (status == '0') {
                //预审状态 0.暂存 1.待预审 2.预审待审批 3.预审审批中 4.预审通过 5.预审拒绝
                if(d.credit=='1'){
                    return '待预审';
                }
                if(d.credit=='2'){
                    return '预审审批中';
                }
                if(d.credit=='3'){
                    return '预审审批中';
                }
                if(d.credit=='4'){
                    if(d.design_audit_flag == '3'){
                        return '自审驳回';
                    }
                    else if(d.design_audit_flag == 'a'){
                        return '待设计';
                    } else {
                        return '待踏勘';
                    }
                }
                if(d.credit=='5'){
                    return '预审拒绝';
                }
                return '暂存';
            }
            if (status == '1') {
                //设计审核状态：1.待踏勘 2.待自审 3.自审驳回 4.自审通过 5.设计审核驳回 6.设计审核通过/已完成 7.进件审核驳回
                if(d.design_audit_flag=='1'){
                    return '待踏勘';
                }else if(d.design_audit_flag=='2'){
                    return '待自审';
                }else if(d.design_audit_flag == 'a'){
                    return '待设计';
                }  else if(d.design_audit_flag=='3'){
                    return '自审驳回';
                } else if(d.design_audit_flag=='4'){
                    return '自审通过';
                } else if(d.design_audit_flag=='5'){
                    return '设计审核驳回';
                } else if(d.design_audit_flag=='6'){
                    return '设计审核通过';
                }else if(d.design_audit_flag=='7'){
                    return '进件审核驳回';
                }
                return '待审核';
            }
            if (status == '2') {
                return '审核驳回';
            }
            if (status == '3') {
                return '待下单';
            }
            if (status == '4') {
                if (d.install_flag == '1'){
                    return '待派工';
                }else if (d.install_flag == '2'){
                    return '待安装';
                }else if (d.install_flag == '3'){
                    return '自审驳回';
                }else if (d.install_flag == '4'){
                    return '安装完成';
                }

            }
            if(status == '5'){
                return '待安装验收';
            }
            if(status == 'f'){
                return '安装验收退回';
            }
            if(status == '6'){
                return '待并网';
            }
            if(status == '7'){
                if (d.merge_flag === '1') {
                    return '待并网验收';
                }
                if (d.merge_flag === '3') {
                    return '资方审核中';
                }
                return '待并网验收';
            }
            if(status == '8'){
                return '待交付';
            }
            if(status == '9'){
                return '待归档';
            }
            if(status == '10'){
                return '验收驳回';
            }
            if(status == '11'){
                return '归档驳回';
            }
            if(status == 'a'){
                return '已完成';
            }if(status == 'c'){
                return '待代理商确认';
            }
            // if(status == 'd'){
            //     return '待上传发票';
            // }
            if(status == 'e'){
                return '待签署合同';
            }
            if(status == 'w'){
                return '信息登记';
            }
            if(status == 'g'){
                return '设计审核';
            }
            if(status == 'AN'){
                return '待安装确认';
            }
            if(status == 'AT'){
                return '安装确认驳回';
            }
            if(status == 'BW'){
                return '待并网确认';
            }
            if(status == 'BN'){
                return '并网确认驳回';
            }
            if(status == 'h'){
                return '设计自审';
            }
            if(status == 'i'){
                return '安装自审';
            }
        }

        tableExt.render({
            elem: '#test'
            , title:'项目查询'
            , height: 'full-270'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/customerEntry/ajaxForWaitOrder?apply=1&entryPage=all&partner='+'${partner}'+'&stageStatus=a'
            , where: _serializeJson($("#searchForm"))
            , method:"post"
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',fixed: 'left'}
                , {field: 'entryStratus', title: '电站状态', minWidth: 120, align: 'center', exportable: true,fixed:'left',
                    templet: function(d){
                        return getStatus(d);
                    },
                    expFormat: function(d){
                        return getStatus(d);
                    }}
                , {field: 'is_check_accept', title: '竣工状态', minWidth: 120, align: 'center', exportable: true,fixed:'left',
                    templet:function(d){
                        if (d.is_check_accept === '0') {
                            return "未提交";
                        } else if (d.is_check_accept === '1') {
                            return "已提交";
                        } else if(d.is_check_accept ==='2'){
                            return "已竣工";
                        } else {
                            return "未提交";
                        }
                    },
                    expFormat: function(d){
                        if (d.is_check_accept === '0') {
                            return "未提交";
                        } else if (d.is_check_accept === '1') {
                            return "已提交";
                        } else if(d.is_check_accept ==='2'){
                            return "已竣工";
                        } else {
                            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: 'project_company_name',title: '项目公司',minWidth: '220',sort: false,align: 'center',exportable: true}
                , {field: 'traderName', title: '代理商名称', minWidth: 280, 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: 300, sort: false, align: 'center', exportable: true}
                , {field: 'pca', title: 'pca', minWidth: 300, sort: false, align: 'center', exportable: true, hide: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;
                // $('span[data-oneself="oneselfFlag"]').parent().parent().parent().css('background-color', '#E2D5D2');
            }
        });

        form.on('select(province)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            provinceOrder(province);
        });
        form.on('select(city)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            cityOrder(city);

        });

        function provinceOrder(province) {
            $("#city").empty();
            $("#area").empty();
            if (isBlank(province)) {
                $("#city").append("<option value=''>市</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getCitysByProId",
                data: {
                    province: province
                },
                success: function (result) {

                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = " <option value=''>市</option>";
                    for (var i = 0; i < result.length; i++) {
                        var city = result[i];
                        html = html + '<option value="' + city.columns.CityName + '" title="' + city.columns.CityID + '">' + city.columns.CityName + '</option>';
                    }
                    $("#city").append(html);
                    form.render('select');
                }
            });

        }

        function cityOrder(city, arean) {
            $("#area").empty()
            if (isBlank(city)) {
                $("#area").append("<option value=''>区/县</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getAreaByCityId",
                data: {
                    city: city
                },
                success: function (result) {
                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = "<option value=''>区/县</option>";
                    for (var i = 0; i < result.length; i++) {
                        var area = result[i];
                        html = html + '<option value="' + area.columns.DistrictName + '" value="' + area.columns.DistrictId + '">' + area.columns.DistrictName + '</option>';
                    }
                    $("#area").append(html);
                    if (!isBlank(arean)) {
                        $("#area").val(arean)
                    }

                    form.render('select');
                }
            });

        }

        table.on('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
                if(obj.event==='completion'){
                var data = checkStatus.data;
                console.log(data)
                if (data.length < 1) {
                    layer.msg("请选择数据",{icon:5,anim:6});
                    return false;
                }
                var chename = "";
                var ids = [];
                var projectCompanyName = "";
                var pca = "";
                var traderName = "";
                for(var i=0; i<checkStatus.data.length; i++){
                    ids.push(checkStatus.data[i].id);
                    if(i==0){
                        projectCompanyName = checkStatus.data[i].project_company_name;
                        pca = checkStatus.data[i].pca;
                        traderName = checkStatus.data[i].traderName;
                    }
                    if(i>=1){
                        if(checkStatus.data[i].project_company_name != projectCompanyName){
                            chename = "400";
                            break;
                        }
                        if(checkStatus.data[i].pca != pca){
                            chename = "500";
                            break;
                        }
                        if(checkStatus.data[i].traderName != traderName){
                            chename = "600";
                            break;
                        }
                    }
                    if(checkStatus.data[i].is_check_accept=='1' || checkStatus.data[i].is_check_accept=='2'){
                        chename = "300";
                        break;
                    }
                }
                    if(chename =='300'){
                        layer.msg("已提交，已竣工的信息不可提交",{icon:5,anim:6});
                        return false;
                    }
                    if(chename =='400'){
                        layer.msg("所选电站项目公司不一致，不可提交",{icon:5,anim:6});
                        return false;
                    }
                    if(chename =='500'){
                        layer.msg("所选电站省市区不一致，不可提交",{icon:5,anim:6});
                        return false;
                    }
                    if(chename =='600'){
                        layer.msg("所选电站代理商不一致，不可提交",{icon:5,anim:6});
                        return false;
                    }

                if (data.length > 2) {
                    for(var i=0; i<checkStatus.data.length; i++){
                        ids.push(checkStatus.data[i].power_station_code);
                    }
                }
                var idStr = ids.join(",");
                layer.open({
                    title: '竣工',
                    type: 2,
                    area: ['80%', '80%'],
                    content: '${ctx}/completion/addCompletion?idStr='+idStr
                });
            }

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

        });
    }

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

    //查看详情
    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("");
    }

    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'); //数据刷新
            }
        });
    }
</script>
</body>
</html>

