layui.use('element', function () {
    var $ = layui.jquery
    , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    $('.site-demo-active').on('click', function () {
        var othis = $(this), type = othis.data('type');
        active[type] ? active[type].call(this, othis) : '';
    });

    //Hash地址的定位
    var layid = location.hash.replace(/^#test=/, '');
    element.tabChange('test', layid);

    element.on('tab(test)', function (elem) {
        location.hash = 'test=' + $(this).attr('lay-id');
    });

});
layui.use('laydate', function () {
    var laydate = layui.laydate;
    //日期时间范围
    laydate.render({
        elem: '#test10'
        // , type: 'datetime'
      , range: true

    });
});
layui.use(['table', 'jquery'], function () {
    var table = layui.table;
    var form = layui.form,
       layer = parent.layer === undefined ? layui.layer : parent.layer,
       $ = layui.jquery;
    //监听表格复选框选择
    table.on('checkbox(demo)', function (obj) {
        console.log(obj)
    });

    var $ = layui.$, active = {
        //查询按钮
        reload: function () {
            Init();
            //执行重载
            table.reload('recordtable', {
                where: {
                    dateParty: $("#test10").val()
                   , NowDateTime: new Date()

                }
            });
        }
        //本周
       , oneWeek: function () {

        var thisDateParty = getWeekStartDate() + ' - ' + formatDate(now);
        $("#test10").val(thisDateParty);
           Init();
           //执行重载
           table.reload('recordtable', {
               where: {
                   dateParty: thisDateParty
                  , NowDateTime: new Date()

               }
           });
       }

        //本月
       , oneMonth: function () {

        var thisDateParty = getMonthStartDate() + ' - ' + formatDate(now);
        $("#test10").val(thisDateParty);
           Init();
           //执行重载
           table.reload('recordtable', {
               where: {
                   dateParty: thisDateParty
                  , NowDateTime: new Date()

               }
           });
       }
        //本年
       , oneYear: function () {

        var thisDateParty = getYearStartDate() + ' - ' + formatDate(now);
        $("#test10").val(thisDateParty);

           Init();
           //执行重载
           table.reload('recordtable', {
               where: {
                   dateParty: thisDateParty
                  , NowDateTime: new Date()

               }
           });
       }

    };

    $('.searchfilter .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';


    });


    // 路径配置
    require.config({
        paths: {
            echarts: '/Content/dist'
        }
    });
    function Init() {

        var  bottom, d1, d2, d3, d4, d5;
        $.ajax({
            url: "/Report/WorkOrderTypeUserMathChartData",
            type: "get",
            contentType: "application/json",
            dataType: "text",
            cache: false,
            data: {
                NowDateTime: new Date(), dateParty: $("#test10").val()
            },
            success: function (result, status) {
                if (status) {
                    var dataModel = JSON.parse(result);
                    
                    bottom = dataModel.bottom;
                    d1 = dataModel.d1;
                    d2 = dataModel.d2;
                    d3 = dataModel.d3;
                    d4 = dataModel.d4;
                    d5 = dataModel.d5;



                    // 使用
                    require(
                    [
                'echarts',
                'echarts/chart/bar' // 使用柱状图就加载bar模块，按需加载
                  , 'echarts/chart/line' // 使用柱状图就加载bar模块，按需加载
                    ],
                    function (ec) {
                        var dahuatheme
                        require(['echarts/theme/dahua'], function (theme) {
                            dahuatheme = theme;
                        });
                        // 基于准备好的dom，初始化echarts图表
                        var myChart = ec.init(document.getElementById('divimagereport'), dahuatheme);
                        option = {
                            title: {
                                show: false,
                                text: '',
                                subtext: ''
                            },
                            tooltip: {
                                trigger: 'axis'
                            },
                            legend: {
                                data: ['业务数量', '语音业务数量', '在线业务数量', '微信业务数量', '微博业务数量']
                            },
                            toolbox: {
                                show: true,
                                feature: {
                                    dataView: { show: true, readOnly: false },
                                    magicType: { show: true, type: ['line', 'bar'] },
                                    restore: { show: true },
                                    saveAsImage: { show: true }
                                }
                            },
                            calculable: true,
                            xAxis: [
                                {
                                    type: 'category',
                                    axisLabel: {
                                        interval: 0
                                    },
                                    data:eval( bottom)
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value'
                                }
                            ],
                            series: [
                                {
                                    name: '业务数量',
                                    type: 'bar',
                                    data: eval(d1),
                                    markPoint: {
                                        data: [
                                            { type: 'max', name: '最大值' },
                                            { type: 'min', name: '最小值' }
                                        ]
                                    },
                                    markLine: {
                                        data: [
                                            { type: 'average', name: '平均值' }
                                        ]
                                    }
                                },
                                {
                                    name: '语音业务数量',
                                    type: 'bar',
                                    data: eval(d2),
                                    markPoint: {
                                        data: [
                                            { type: 'max', name: '最大值' },
                                            { type: 'min', name: '最小值' }
                                        ]
                                    },
                                    markLine: {
                                        data: [
                                            { type: 'average', name: '平均值' }
                                        ]
                                    }
                                },
                                {
                                    name:  '在线业务数量',
                                    type: 'bar',
                                    data:  eval(d3),
                                    markPoint: {
                                        data: [
                                            { type: 'max', name: '最大值' },
                                            { type: 'min', name: '最小值' }
                                        ]
                                    },
                                    markLine: {
                                        data: [
                                            { type: 'average', name: '平均值' }
                                        ]
                                    }
                                },
                                {
                                    name: '微信业务数量',
                                    type: 'bar',
                                    data:  eval(d4),
                                    markPoint: {
                                        data: [
                                            { type: 'max', name: '最大值' },
                                            { type: 'min', name: '最小值' }
                                        ]
                                    },
                                    markLine: {
                                        data: [
                                            { type: 'average', name: '平均值' }
                                        ]
                                    }
                                },
                                {
                                    name: '微博业务数量',
                                    type: 'bar',
                                    data:  eval(d5),
                                    markPoint: {
                                        data: [
                                            { type: 'max', name: '最大值' },
                                            { type: 'min', name: '最小值' }
                                        ]
                                    },
                                    markLine: {
                                        data: [
                                            { type: 'average', name: '平均值' }
                                        ]
                                    }
                                }
                            ]
                        };
                        // 为echarts对象加载数据
                        myChart.setOption(option);
                    }
                );
                }


            }
        });




    }

    Init();

});