
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>阿特斯--质量验收</title>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card{box-shadow: none;}
        .layui-btn + .layui-btn {
            margin-left: 35px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card" id="searchForm">
        <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this sf-tab"><a href="${ctx}/entryQuality/qualityManagement/entryQualityPage">电站检验</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" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body">
            <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="qualityEmpId" id="qualityEmpId">
                            <option value="">请选择</option>
                            <c:forEach items="${empList}" var="emp">
                                <option value="${emp.columns.id}">${emp.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="traderId" id="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-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 class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">检验类型：</label>
                    <div class="layui-input-block">
                        <select name="type" id="type">
                            <option value="">请选择</option>
                            <option value="1">质检</option>
                            <option value="2">巡检</option>
                        </select>
                    </div>
                </div>

            </div>
        </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">
                    <sfTags:pagePermission authFlag="XMGL_ZLYS_ZLYS_DC_T" 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 type="text/html" id="table-toolbar">
    {{# if(d.status == '1'){ }}
    <sfTags:pagePermission authFlag="XMGL_ZLYS_ZLYS_PG_T" html='<a class="layui-table-opt-link" lay-event="dispatchEmp">派工</a>'/>
  <%--  {{# }else if(d.status == '2' && d.quality_emp_user_id == '${user.id}'){ }}
    <a class="layui-table-opt-link" lay-event="sampleAccept">检验验收</a>--%>
    {{#  } else { }}
    --
    {{# } }}
</script>
<script type="text/javascript">
    var table;
    var $;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laydate','form'], function(){
        $ = layui.jquery;
        tableExt = layui.tableExt;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var  form = layui.form;
        table = tableExt.getLayTable();
        //开始日期
        var insStart = laydate.render({
            elem: '#createTimeSta'
            ,type: 'date'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#createTimeEnd'
            ,type: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        tableExt.render({
            elem: '#test'
            ,toolbar : '#toolbarDemo'
            , height: 'full-200'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/entryQuality/qualityManagement/entryQualityData'
            ,cols: [[
                {type: 'numbers',title:'序号',fixed:'left'}
                , {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title: '操作',toolbar: '#table-toolbar',align: 'center', fixed: 'left',width: 180}
                , {field: 'status', title: '状态', align: 'center', fixed: 'left', width: 150, exportable: true
                    , templet: function (d) {
                        if (d.status == '1') {
                            return '待派工';
                        }else if(d.status== '2' && d.type == '1'){
                            return '质检中';
                        }else if(d.status== '2' && d.type == '2'){
                            return '巡检中';
                        }else if(d.status== '5'){
                            return '已完成';
                        }
                        return '';
                    }, expFormat: function (d) {
                        if (d.status == '1') {
                            return '待派工';
                        }else if(d.status== '2' && d.type == '1'){
                            return '质检中';
                        }else if(d.status== '2' && d.type == '2'){
                            return '巡检中';
                        }else if(d.status== '5'){
                            return '已完成';
                        }
                        return '';
                    }
                }
                , {field: 'number', title: '检验单号', align: 'center', fixed: 'left', width: 180, exportable: true
                    , templet: function (d) {
                        return "<a href=\"#\" class=\"layui-table-link \" style='font-size:14px;' onclick=\"lookDetail('" + d.id + "')\">" + d.number + "</a>";
                    }
                }
               // ,{field:'total_count', title: '总户数',align: 'center',width: 130,exportable:true}
                ,{field:'sample_count', title: '抽检户数',align: 'center',width: 130,exportable:true}
                /*, {field: 'create_method', title: '生成方式', align: 'center', width: 150, exportable: true
                    , templet: function (d) {
                        if (d.create_method == '1') {
                            return "系统生成";
                        }else {
                            return "";
                        }
                    },expFormat:function (d){
                        if (d.create_method == '1') {
                            return "系统生成";
                        }else {
                            return "";
                        }
                    }}*/
                ,{field:'quality_emp_name', title: '检验人员',align: 'center',width: 180,exportable:true}
                , {field: 'type', title: '检验类型', align: 'center', width: 150, exportable: true
                    , templet: function (d) {
                        if (d.type == '1') {
                            return "质检";
                        }else if (d.type == '2') {
                            return "巡检";
                        }else {
                            return "";
                        }
                    },expFormat:function (d){
                        if (d.type == '1') {
                            return "质检";
                        }else if (d.type == '2') {
                            return "巡检";
                        }else {
                            return "";
                        }
                    }}
                , {field: 'region_province', title: '区域', align: 'center', width: 200, exportable: true
                    , templet: function (d) {
                        return d.region_province+d.region_city+d.region_area;
                    },expFormat:function (d){
                        return d.region_province+d.region_city+d.region_area;
                    }
                },{field: 'trader_name', title: '代理商', align: 'center', width: 200, exportable: true}
                ,{field:'create_time', title: '生成时间',align: 'center',width: 220,exportable:true}
                ,{field:'finish_time', title: '检验完成时间',align: 'center',width: 220,exportable:true}
            ]],done: function(res, curr, count){

            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '质量验收',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '质量验收导出',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    var ret = {};
                    ret.number= $("#number").val();
                    ret.powerStationCode= $("#powerStationCode").val();
                    ret.tenantName=$("#tenantName").val();
                    ret.qualityEmpId=$("#qualityEmpId").val();
                    ret.traderId=$("#traderId").val();
                    ret.createTimeSta=$("#createTimeSta").val();
                    ret.createTimeEnd=$("#createTimeEnd").val();
                    ret.type=$("#type").val();
                    return ret;
                }
            }
        });

        table.on('tool(test)',function(obj) {
            var data = obj.data;
            var id = data.id;
            if (obj.event === 'dispatchEmp') {
                layer.open({
                    title:'派工',
                    type: 2,
                    area: ["60%", "70%"],
                    content: '${ctx}/entryQuality/qualityManagement/entryQualityDispatchPage?id='+id
                })
            } if (obj.event === 'sampleAccept') {
                layer.open({
                    title:'检验验收',
                    type: 2,
                    area: ["100%", "100%"],
                    content: '${ctx}/entryQuality/qualityManagement/qualityAcceptPage?id='+id
                })
            }
        });

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

        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });


    });

    function sampleAccept(id){
        layer.open({
            title:'检验验收',
            type: 2,
            area: ["100%", "100%"],
            content: '${ctx}/entryQuality/qualityManagement/qualityAcceptPage?id='+id
        })
    }

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


    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }

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

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

