<%@ 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>竣工结果查询</li></a>
                <a href="${ctx}/completion/completionOrder"><li>竣工单</li></a>
                <a href="${ctx}/rectification/rectificationOrder"><li class="layui-this">整改单</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="projectCompanyName" id="projectCompanyName" 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="completionNo" id="completionNo" 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="rectificationNo" id="rectificationNo" 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="rectificationStatus" lay-search>
                            <option value="">请选择</option>
                            <option value="-26">提交失败</option>
                            <option value="-31">核实不通过</option>
                            <option value="10">创建中</option>
                            <option value="20">整改中</option>
                            <option value="25">整改提交中</option>
                            <option value="30">核实中</option>
                            <option value="40">已完成</option>
                        </select>
                    </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-sm6">
                    <label class="layui-form-label">竣工创建时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeMin" class="layui-input" id="createEndStartTime"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeMax" class="layui-input" id="createEndEndTime"
                                   placeholder="结束日期">
                        </div>
                    </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_ZG_B" html='<button class="layui-btn layui-btn-sm" lay-event="rectification">整改</button>'/>
                    <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 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.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();
        formSelects = layui.formSelects;

        //开始日期
        var endStartTime = laydate.render({
            elem: '#createEndStartTime'
            /* ,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: '#createEndEndTime'
            /* ,type: 'datetime'*/
            , done: function (value, date) {
                //更新开始日期的最大日期
                endStartTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        tableExt.render({
            elem: '#test'
            , title:'竣工单查询'
            , height: 'full-270'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/rectification/getRectificationOrderList'
            , where: _serializeJson($("#searchForm"))
            , method:"post"
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',fixed: 'left'}
                , {field: 'rectification_no',title: '整改单号',minWidth: '220',sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        var html = '';
                        return html + '<a href="#" class="layui-table-link" onclick="psDetail(\'' + d.id + '\')">' + d.rectification_no + '</a>';
                    }}
                , {field: 'rectification_status',title: '整改状态',minWidth: '220',sort: false,align: 'center',exportable: true
                    , templet:function(d){
                        return rectificationStatusStr(d.rectification_status);
                    }
                    , expFormat: function(d){
                        return rectificationStatusStr(d.rectification_status);
                    }
                }
                , {field: 'completion_no',title: '竣工单号',minWidth: '220',sort: false,align: 'center',exportable: true}
                , {field: 'create_trader_name', title: '代理商名称', minWidth: 280, sort: false, align: 'center', exportable: true}
                , {field: 'power_station_count', title: '电站户数', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'recount', title: '整改数量', minWidth: 130, sort: false, align: 'center', exportable: true}
                , {field: 'create_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;
                // $('span[data-oneself="oneselfFlag"]').parent().parent().parent().css('background-color', '#E2D5D2');
            }
        });

        function  rectificationStatusStr(rectificationStatus) {
            if (rectificationStatus == '-26') {
                return "整改提交失败";
            } else if (rectificationStatus == '-31') {
                return "核实不通过";
            } else if (rectificationStatus == '10') {
                return "创建中";
            } else if (rectificationStatus == '20') {
                return "整改中";
            } else if (rectificationStatus == '25') {
                return "整改提交中";
            } else if (rectificationStatus == '30') {
                return "核实中";
            } else if (rectificationStatus == '40') {
                return "已完成";
            }else{
                return "--";
            }
        }

        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==='rectification'){
                var data = checkStatus.data;
                console.log(data)
                if (data.length < 1) {
                    layer.msg("请选择数据",{icon:5,anim:6});
                    return false;
                }
                if (data.length > 1) {
                    layer.msg("请选择一条数据",{icon:5,anim:6});
                    return false;
                }
                var chename = "";
                for(var i=0; i<checkStatus.data.length; i++){
                    if(checkStatus.data[i].rectification_status=='40'){
                        chename = "300";
                        break;
                    }
                }
                if(chename =='300'){
                    layer.msg("已完成状态不可整改",{icon:5,anim:6});
                    return false;
                }
                var id = checkStatus.data[0].id;
                layer.open({
                    title: '整改',
                    type: 2,
                    area: ['80%', '80%'],
                    content: '${ctx}/rectification/addRectification?id='+id
                });
            }

        });
        //监听搜索
        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 searchOrder() {
        layer.closeAll();
        //执行重载
        var wherobj = _serializeJson($("#searchForm"));
        tableExt.reload('test', {
            where: wherobj
        });
    }

    function deliver() {

    }

    //查看详情
    function psDetail(id) {
        layer.open({
            type: 2
            , title: '竣工详情'
            , content: '${ctx}/rectification/rectificationDetail?id=' + id
            , area: ['80%', '80%']
            , yes: function(index, layero){

            }
        });
    }


    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>

