
<%@ 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">
        <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this sf-tab"><a href="${ctx}/entryQuality/qualityManagement/qualityStatistics">质检统计</a></li>
                <li><a href="${ctx}/entryQuality/qualityManagement/inspectionStatistics">巡检统计</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" 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">
                        <select name="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">
                        <input type="text" name="dispatchTime" class="layui-input" id="dispatchTime" value="${nowMouth}">
                    </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_ZJTJ_ZJTJ_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 src="${ctxPlugin}/lib/layuiAdmin/dist/modules/excel.js"></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','excel'], function(){
        $ = layui.jquery;
        tableExt = layui.tableExt;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var excel = layui.excel;
        var  form = layui.form;
        table = tableExt.getLayTable();
        //开始日期
        var insStart =  laydate.render({
            elem: '#dispatchTime',
            type: 'month',
            format: 'yyyy-MM',
            btns: ['now','confirm'],
            done: function (value, date, endDate) {

            }
        });

      var tableRes =   tableExt.render({
            elem: '#test'
            ,toolbar : '#toolbarDemo'
            , height: 'full-180'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/entryQuality/qualityManagement/getQualityStatisticsList?type=1'
            ,cols: [[
                {type: 'numbers', title: '序号', fixed: 'left', rowspan: 2}
                , {field: 'quality_emp_name', title: '质检员', align: 'center', rowspan: 2, exportable: true}
                , {title: '质检总数', align: 'center', colspan: 2 }
                , {title: '质检中', align: 'center',colspan: 2}
                , {title: '质检完成', align: 'center', colspan: 2}
                , {title: '无法验收', align: 'center',colspan: 2}
                , {field: 'prop', title: '无法验收比例', align: 'center', rowspan: 2,exportable: true}
                , {field: 'dispatch_time', title: '统计时间', align: 'center', rowspan: 2,exportable: true}
            ],[
                {field:'zjNum', title: '户数',align: 'center',exportable:true
                    , templet: function (d) {
                        if(isBlank(d.zjNum)){
                            return "0";
                        }else {
                            return d.zjNum;
                        }
                    }}
                ,{field:'zjCapacity', title: '容量（KW）',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.zjCapacity)){
                          return "0";
                      }else {
                          return d.zjCapacity;
                      }
                  }}
                ,{field:'zjzNum', title: '户数',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.zjzNum)){
                          return "0";
                      }else {
                          return d.zjzNum;
                      }
                  }}
                ,{field:'zjzCapacity', title: '容量（KW）',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.zjzCapacity)){
                          return "0";
                      }else {
                          return d.zjzCapacity;
                      }
                  }}
                ,{field:'zjwcNum', title: '户数',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.zjwcNum)){
                          return "0";
                      }else {
                          return d.zjwcNum;
                      }
                  }}
                ,{field:'zjwcCapacity', title: '容量（KW）',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.zjwcCapacity)){
                          return "0";
                      }else {
                          return d.zjwcCapacity;
                      }
                  }}
                ,{field:'wfysNum', title: '户数',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.wfysNum)){
                          return "0";
                      }else {
                          return d.wfysNum;
                      }
                  }}
                ,{field:'wfysCapacity', title: '容量（KW）',align: 'center',exportable:true
                  , templet: function (d) {
                      if(isBlank(d.wfysCapacity)){
                          return "0";
                      }else {
                          return d.wfysCapacity;
                      }
                  }}
            ]]
            ,done: function(res, curr, count){

            }
            // ,exportOpt:{                           //导出选项配置
            //     ele:'#exportBtn',                   //导出的Dom元素
            //     headerTitle: '质检统计',             //excel表格的标题
            //     pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
            //     maxAmount: 1000,                    //当pageData为false生效
            //     fileName: '质检统计导出',
            //     multiHeaderExport: true,
            //     where: function (){                 //当pageData为false时生效，过滤的条件
            //         return _serializeJson($("#searchForm"));
            //     }
            // }
        });
        let mergeConf = excel.makeMergeConfig([
            ['A1', 'K1'],
            ['A2', 'A3'],
            ['B2', 'C2'],
            ['D2', 'E2'],
            ['F2', 'G2'],
            ['H2', 'I2'],
            ['J2', 'J3'],
            ['K2', 'K3'],
        ]);

        let colConf = excel.makeColConfig({
            A: 120,
            B: 100,
            C: 100,
            D: 100,
            E: 100,
            F: 100,
            G: 100,
            H: 100,
            I: 100,
            J: 100,
            K: 100,
        });


    table.on('toolbar(test)',function(obj) {

        if (obj.event === 'export') {
            var date = [
                {
                    quality_emp_name: '质检统计',
                }
                , {
                    quality_emp_name: '质检员',
                    zjNum: '质检总数',
                    zjzNum: '质检中',
                    zjwcNum: '质检完成',
                    wfysNum: '无法验收',
                    prop: '无法验收比例',
                    dispatch_time: '统计时间',
                },
                {
                    quality_emp_name: '质检员',
                    zjNum: '户数',
                    zjCapacity: '容量（KW）',
                    zjzNum: '户数',
                    zjzCapacity: '容量（KW）',
                    zjwcNum: '户数',
                    zjwcCapacity: '容量（KW）',
                    wfysNum: '户数',
                    wfysCapacity: '容量（KW）',
                }
            ]; // 获取表格数据
            let tableData = [];
            let titleList = excel.filterExportData(date, getCellStyle());
            let dataList = excel.filterExportData(layui.table.cache['test'], getCellStyle());
            tableData.push.apply(tableData, titleList);
            tableData.push.apply(tableData, dataList);
            excel.exportExcel({sheet1: tableData}, "质检统计导出.xlsx", "xlsx",
                {
                    extend: {
                        // extend 中可以指定某个 sheet 的属性，如果不指定 sheet 则所有 sheet 套用同一套属性
                        sheet1: {
                            // 以下配置仅 sheet1 有效
                            '!merges': mergeConf,
                            '!cols': colConf
                        }
                    }
                });
        }
    });
        //公共样式
        let commonStyle = {
            font: {    sz: 12 },
            alignment: {
                vertical: "center",
                horizontal: "center"
            },
            border: {
                top: {style: 'thin', color: {rgb: '666666'}},
                bottom: {style: 'thin', color: {rgb: '666666'}},
                left: {style: 'thin', color: {rgb: '666666'}},
                right: {style: 'thin', color: {rgb: '666666'}}
            }
        }

        function getCellStyle(styleParam) {
            let tmpData = {};
            ['quality_emp_name', 'zjNum', 'zjCapacity', 'zjzNum', 'zjzCapacity', 'zjwcNum', 'zjwcCapacity', 'wfysNum', 'wfysCapacity'
            ,'prop','dispatch_time'].forEach(item => {
                tmpData[item] = function (value, line, data) {
                    return {
                        v: isBlank(value)?"0":value,
                        s: Object.assign({}, commonStyle)
                    }
                }
            });
            return tmpData;
        }

        //监听搜索
        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 reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

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

