<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" 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" media="all">
    <style>
        dl{
            max-height: 250px;
        }
        .layui-table-opt-link{padding:10px}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this"><a href="${ctx}/entryQuality/qualityRectification/qualityRectificationPage">电站整改</a></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-lg2 layui-col-sm3">
                        <label class="layui-form-label">检验单号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" 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" id="powerStationCode" 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="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">
                            <select name="traderId">
                                <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">
                            <select name="changeStatus">
                                <option value="">请选择</option>
                                <option value="1">整改中</option>
                                <option value="3">待验收</option>
                                <option value="5">已完成</option>
                            </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="createTimeSta" id="createTimeSta" class="layui-input"  placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeEnd" id="createTimeEnd" class="layui-input"  placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide " 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>
</div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        laydate = layui.laydate;
        table = layui.table;

        let pgFlag = '${fns:checkPagePermission(request, "XMGL_ZLZG_PG_B")}';
        let dzzgFlag = '${fns:checkPagePermission(request, "XMGL_ZLZG_DZZG_B")}';
        let ysFlag = '${fns:checkPagePermission(request, "XMGL_ZLZG_YS_B")}';

        //开始日期
        var insStart = laydate.render({
            elem: '#createTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期

            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#createTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期

            }
        });

        //信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-180'
            , id: 'test'
            , toolbar : '#toolbarDemo'
            , defaultToolbar : false
            , url: '${ctx}/entryQuality/qualityRectification/getQualityRectificationList'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', title: '序号', align: 'center', type: 'numbers'}
                ,{field : 'id', checkbox : true,align : 'center'}
                ,{field : 'main_id', hide: true}
                ,{field:'id', title: '操作',align: 'center',minWidth: 200,templet:function(d){
                        var htm="";
                        htm+= '<a class="layui-table-opt-link" lay-event="look">查看</a>';
                        if(d.change_status === '1'){
                            if (pgFlag === '0') {
                                htm += '&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="dispatch">派工</a>';
                            }
                        }
                        if((d.change_status === '2' || d.change_status === '4') && d.change_emp_user_id=='${user.id}'){
                            htm += '&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="change">电站整改</a>';
                        }
                        if(d.change_status === '3' && d.emp_user_id=='${user.id}'){
                            htm += '&nbsp;&nbsp;<a class="layui-table-opt-link" lay-event="accept">验收</a>';
                        }
                        return htm;
                    }
                }
                , {field: 'power_station_code', title: '电站编号', minWidth: 200, align: 'center', exportable:true, templet: function(d){
                        var htm="";
                        return htm +=  '<a href="#" class="layui-table-link" onclick="psDetail(\''+d.entry_id+'\')">'+d.power_station_code+'</a>';
                    }
                }
                , {field: 'change_status', title: '整改状态', minWidth: 200, align: 'center',exportable:true
                    ,templet: function (d) {
                        if(isBlank(d.change_status)){
                            return "待整改";
                        }else if(d.change_status === '1' || d.change_status === '2' || d.change_status === '4') {
                            return "整改中";
                        }if(d.change_status === '3') {
                            return "待验收";
                        }else if(d.change_status === '5') {
                            return "已完成";
                        }
                    },expFormat: function (d) {
                        if(isBlank(d.change_status)){
                            return "待整改";
                        }else if(d.change_status === '1' || d.change_status === '2' || d.change_status === '4') {
                            return "整改中";
                        }if(d.change_status === '3') {
                            return "待验收";
                        }else if(d.change_status === '5') {
                            return "已完成";
                        }
                    }
                }
                , {field: 'number', title: '检验单号', minWidth: 200, align: 'center',exportable:true
                    // , templet: function (d) {
                    //     return "<a href=\"#\" class=\"layui-table-link \" style='font-size:14px;' onclick=\"lookDetail('" + d.main_id + "')\">" + d.number + "</a>";
                    // }
                }
                , {field: 'tenant_name', title: '业主姓名', minWidth: 200, align: 'center',exportable:true }
                , {field: 'trader_id', title: '代理商ID', hide:true}
                , {field: 'trader_name', title: '代理商', minWidth: 200, align: 'center',exportable:true }
                , {field: 'type', title: '检验类型', minWidth: 200, align: 'center',exportable:true ,
                    templet: function (d) {
                        if(d.type === '1') {
                            return "质检";
                        }else if(d.type === '2') {
                            return "巡检";
                        }
                    },expFormat: function (d) {
                        if(d.type === '1') {
                            return "质检";
                        }else if(d.type === '2') {
                            return "巡检";
                        }
                    }
                }
                , {field: 'change_create_time', title: '创建时间', minWidth: 200, align: 'center',exportable:true }
                , {field: 'change_time', title: '整改时间', minWidth: 200, align: 'center',exportable:true }
                , {field: 'accept_time', title: '整改验收时间', minWidth: 200, align: 'center',exportable:true ,templet: function (d) {
                        if(d.change_status === '1' || d.change_status === '2' || d.change_status === '3' || d.change_status === '4') {
                            return "";
                        }else{
                            return d.accept_time;
                        }
                    }
                }
                , {field: 'taskSource', title: '任务来源', minWidth: 200, align: 'center',exportable:true }
                , {field: 'quality_emp_name', title: '验收人员', minWidth: 200, align: 'center',exportable:true ,templet: function (d) {
                        if(d.change_status === '1' || d.change_status === '2' || d.change_status === '3' || d.change_status === '4') {
                            return "";
                        }else{
                            return d.quality_emp_name;
                        }
                    }
                }
                , {field: 'change_emp_name',title: '整改人', minWidth: 200 , align: 'center',exportable:true }
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '电站整改',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '电站整改',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            var traderId = data.trader_id;
            var mainId = data.main_id;
            var id = data.id;
            if(obj.event === 'dispatch'){
                layer.open({
                    title:'派工',
                    type: 2,
                    content: '${ctx}/entryQuality/qualityRectification/qualityRectificationDispatchPage?traderId='+traderId+"&id="+id+"&mainId="+mainId,
                    area: ['90%','90%']
                })
            }else if(obj.event === 'look'){
                layer.open({
                    title:'查看',
                    type: 2,
                    content: '${ctx}/entryQuality/qualityRectification/qualityRectificationDetail?id='+id,
                    area: ['90%','90%']
                })
            }else if(obj.event === 'change'){
                layer.open({
                    title:'查看',
                    type: 2,
                    content: '${ctx}/entryQuality/qualityRectification/qualityRectificationChanging?id='+id,
                    area: ['90%','90%']
                })
            }else if(obj.event === 'accept'){
                layer.open({
                    title:'验收',
                    type: 2,
                    content: '${ctx}/entryQuality/qualityRectification/qualityRectificationAccept?id='+id,
                    area: ['90%','90%']
                })
            }
        });

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

    function lookDetail(id){
        layer.open({
            title:'查看',
            type: 2,
            area: ["80%", "85%"],
            content: '${ctx}/entryQuality/qualityManagement/detailPage?id='+id
        })
    }

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

            }
        });
    }

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

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

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

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





