<%@ 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" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="BBTJ_DAILY_RECORD_T" html='<a href="${ctx}/customerEntryDailyRecord/dailyRecordList"><li>日报</li></a>'/>
                <sfTags:pagePermission authFlag="BBTJ_WEEKLY_RECORD_T" html='<a href="${ctx}/customerEntryWeeklyRecord/weeklyRecordList"><li class="layui-this">周报</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>
        <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-lg5 layui-col-sm5">
                        <label class="layui-form-label">日期：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs5">
                                <input type="text" name="creatTime" class="layui-input" id="creatTime" placeholder="统计日期" value="${time}" >
                                <input type="hidden"  id="start" value="" >
                                <input type="hidden" id="end" value="" >
                            </div>
                        </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">
                    <sfTags:pagePermission authFlag="BBTJ_WEEKLY_RECORD_DC_B" html='<button class="layui-btn layui-btn-sm"  id="exportExcel"  onclick="exportExcel()"  ><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>
                    <sfTags:pagePermission authFlag="BBTJ_WEEKLY_RECORD_TBZB_B" html='<button class="layui-btn layui-btn-sm"  id="syncWeeklyRecord" onclick="syncWeeklyRecord()">同步周报</button>'/>
                </div>
            </script>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.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();

        laydate.render({
            elem: '#creatTime',
            type: 'date',
            max: genTime('day'),
            format: "yyyy-MM-dd~yyyy-MM-dd",
            showBottom: false,
            done: function (value, date, endDate) {
                if (value != "" && value.length > 0) {
                    let today = new Date(value.substring(0, 10));
                    let weekday = today.getDay();
                    let monday;
                    let sunday;
                    if (weekday == 0) {
                        monday = new Date(1000 * 60 * 60 * 24 * (weekday - 6) + today.getTime());
                    } else {
                        monday = new Date(1000 * 60 * 60 * 24 * (1 - weekday) + today.getTime());
                    }
                    if (weekday == 0) {
                        sunday = today;
                    } else {
                        sunday = new Date(1000 * 60 * 60 * 24 * (7 - weekday) + today.getTime());
                    }
                    let month = monday.getMonth() + 1;
                    if (month < 10) {
                        month = "0" + month;
                    }
                    let day1 = monday.getDate();
                    if (day1 < 10) {
                        day1 = "0" + day1;
                    }
                    let start = "" + monday.getFullYear() + "-" + month + "-" + day1;
                    let month2 = sunday.getMonth() + 1;
                    if (month2 < 10) {
                        month2 = "0" + month2;
                    }
                    let day2 = sunday.getDate();
                    if (day2 < 10) {
                        day2 = "0" + day2;
                    }
                    let end = "" + sunday.getFullYear() + "-" + month2 + "-" + day2;
                    $("#creatTime").val(start + "~" + end);
                    $("#start").val(start);
                    $("#end").val(end);
                } else {
                    $('#creatTime').val('');
                }
            }
        });

        tableExt.render({
            elem: '#test'
            , title:'周报'
            , height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/customerEntryWeeklyRecord/getWeeklyRecordListData'
            , where:_serializeJson($("#searchForm"))
            , cols:[[
                {type: 'numbers',fixed:'left',title:'序号',rowspan:2}
                , {field: 'province', title: '省区',minWidth:'130', sort: false, align: 'center',exportable:true,rowspan:2}
                , {field: 'leader_name', title: '负责人',minWidth:'130', sort: false, align: 'center', exportable:true,rowspan:2}
                , {title: '代理商签约',minWidth:'130', sort: false, align: 'center',exportable:true,colspan:2}
                , {title: '发货量（MW）',minWidth:'130', sort: false, align: 'center',exportable:true,colspan:5}
                , {title: '进件用户数量（个）',minWidth:'130', sort: false, align: 'center',exportable:true,colspan:3}
                , {title: '安装量 提交验工验收（MW）',minWidth:'130', sort: false, align: 'center',exportable:true,colspan:5}
                , {title: '安装量 终审通过（MW）',minWidth:'130', sort: false, align: 'center',exportable:true,colspan:3}
                , {title: '并网量（MW）',minWidth:'130', sort: false, align: 'center',exportable:true,colspan:3}
                ],[
                  {field: 'signed_cnt_week', title: '上周完成数量',minWidth:'130', sort: false, align: 'center', exportable:true}
                , {field: 'cum_signed_cnt', title: '累计数量',minWidth:'130', sort: false, align: 'center', exportable:true}
                , {field: 'shipped_cnt_week_target', title: '上周目标',minWidth:'130', sort: false, align: 'center', exportable:true}
                , {field: 'shipped_cnt_week', title: '上周已发',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'shipped_cnt_week_prop_rate', title: '推进率',minWidth:'130', sort: false, align: 'center', exportable:true}
                , {field: 'shipped_cnt_month', title: '本月发货量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'shipped_cnt_year', title: '年度发货量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'app_cnt_week', title: '上周进件量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'app_cnt_month', title: '本月进件量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'app_cnt_year', title: '年度进件量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'submitted_week', title: '上周安装量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'submitted_month_target', title: '本月目标',minWidth:'130', sort: false, align: 'center', exportable:true}
                , {field: 'submitted_month', title: '本月安装量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'submitted_month_prop_rate', title: '推进率',minWidth:'130', sort: false, align: 'center', exportable:true}
                , {field: 'submitted_year', title: '年度安装量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'final_approved_week', title: '上周安装量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'final_approved_month', title: '本月安装量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'final_approved_year', title: '年度安装量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'grid_connected_week', title: '上周并网量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'grid_connected_month', title: '本月并网量',minWidth:'130', sort: false, align: 'center',exportable:true}
                , {field: 'grid_connected_year', title: '年度并网量',minWidth:'130', 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"));
                }
            }
        });


        //监听搜索
        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 genTime(opt) {
        let now = new Date();
        let year = now.getFullYear();
        let mth = now.getMonth();
        let day = now.getDate();
        let month = mth + 1;
        if (month < 10) {
            month = '0' + month
        }
        if (day < 10) {
            day = '0' + day
        }
        let str;
        if (opt == 'day') {
            str = year + '-' + month + '-' + day;
        } else if (opt == 'month') {
            str = year + '-' + month;
        }
        return str;
    }

    function syncWeeklyRecord(){
        layer.open({
            type: 2,
            title:"同步周报",
            resize:false,
            area: ['30%', '50%'],
            content: '${ctx}/customerEntryWeeklyRecord/toSyncWeeklyRecord'
        });
    }

    function exportExcel(){
        window.open('${ctx}/customerEntryWeeklyRecord/exportExcel?'+$('#searchForm').serialize());
    }


    function searchOrder() {
        //执行重载
        table.reload('test', {
            where: function (){
                return _serializeJson($("#searchForm"));
            }
        });
    }
    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("");
        $("#creatTime").val('${maxDate}');

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


