<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <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">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>
        html {
            background-color: #fff;
            padding-bottom: 50px;
        }
        .layui-input-block {
            margin-left: 110px;
        }

        .layui-form-label {
            width: 110px;
        }
        .layui-tab-title{
            margin: 0 0 0 20px;
        }

        input[type="radio"]:disabled, textarea:disabled, .layui-disabled {
            background-color: #ffffff;
        }
    </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">
                <li class="layui-this">电站信息</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-lg6 layui-col-sm6 layui-col-md6" >
                        <label class="layui-form-label">安装地址：</label>
                        <div class="inline-block" style="width: 25%">
                            <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: 25%;">
                            <select name="city" id="city" lay-filter="city"
                                    lay-search>
                                <option value="">市</option>

                            </select>
                        </div>
                        <div class="inline-block" style="width: 25%">
                            <select name="area" id="area" lay-search>
                                <option value="">县/区</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-lg3 layui-col-sm3">
                        <label class="layui-form-label">电站编码：</label>
                        <div class="layui-input-block">
                            <input type="text" id="powerStationCode" name="powerStationCode"  class="layui-input " value="">
                        </div>
                    </div>
                    <div class="layui-col-lg3 layui-col-sm3">
                        <label class="layui-form-label">客户姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" id="tenantName" name="tenantName"  class="layui-input " value="">
                        </div>
                    </div>
                </div>
            </form>
        </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">
<%--                    <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 class="operate-footer">
        <input type="button" class="layui-btn toExamine" value="提交">
        <input type="button" class="layui-btn layui-btn-primary" value="取消" onclick="cancel()">
    </div>
</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        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 getStatus(d) {
            var status =d.status;

            if (status == '0') {
                //预审状态 0.暂存 1.待预审 2.预审待审批 3.预审审批中 4.预审通过 5.预审拒绝
                if(d.credit=='1'){
                    return '待预审';
                }else if(d.credit=='2'){
                    return '预审审批中';
                }else if(d.credit=='3'){
                    return '预审审批中';
                }else if(d.credit=='4'){
                    if(d.design_audit_flag == '3'){
                        return '自审驳回';
                    }else if(d.design_audit_flag == 'a'){
                        return '待设计';
                    }else {
                        return '待踏勘';
                    }
                }else 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=='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 '进件审核驳回';
                } else if (d.design_audit_flag == '8') {
                    return "进件审核中";
                } else if (d.design_audit_flag == '9') {
                    return "进件审核通过";
                } else if (d.design_audit_flag == 'a') {
                    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'){
                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-210'
            // , toolbar: '#toolbarDemo'
            // , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/customerEntry/ajaxForWaitOrder?apply=1&status=wlxxbg&changeFlag=1&partner='+'${partnerId}'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',fixed: 'left'}
                , {field: 'power_station_code', title: '电站编码',minWidth:'180', sort: false, align: 'center',exportable:true}
                , {field: 'status', title: '状态', minWidth: '80', align: 'center', exportable: true,
                    templet: function(d){
                        return getStatus(d);
                    },
                    expFormat: function(d){
                        return getStatus(d.status,d.to_examine_status);
                    }}
                , {field: 'tenant_name', title: '客户姓名',minWidth:'80', sort: false, align: 'center', exportable:true}
                , {field: 'partner_name', title: '所属资方',minWidth:'80', sort: false, align: 'center', exportable:true}
                , {field: 'address', title: '安装地址',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'design_capacity', title: '设计容量（W）',minWidth:'80', 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"));
                }
            }
        });


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

        }

        //提交
        var examineFlag = false;
        $(".toExamine").click(function () {
            var checkData = layui.table.checkStatus('test').data;
            if (checkData.length<1){
                layer.msg("请先选择数据", {icon: 5, anim: 6});
                return;
            }
            if (checkData.length>1){
                layer.msg("只能选择一条数据", {icon: 5, anim: 6});
                return;
            }
            if (examineFlag) {
                return;
            }
            let id = checkData[0].id;

            examineFlag = true;
            $.ajax({
                url: "${ctx}/entryChanges/materialInformationChange/findEntryById?id="+id,
                type: "POST",
                contentType: "application/json;charsetset=UTF-8",
                 success: function (result) {
                    parent.addInfo(result);
                     var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                     parent.layer.close(index); //再执行关闭
                     examineFlag = false
                }, error: function () {
                    layer.msg("保存失败", {icon: 2});
                    examineFlag = false
                }
            })
        })


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

    });

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

    function searchOrder() {
        layer.closeAll();
        //执行重载
        var wherobj = _serializeJson($("#searchForm"));
        tableExt.reload('test', {
            where: wherobj
        });
    }
    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
    // 关闭弹框
    function cancel() {
        var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    }


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