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'
        ,min: "2021-01-26"
        ,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);
    });
    //监听工具条
    table.on('tool(demo)', function (obj) {
        var data = obj.data;
        var dateParty = $("#test10").val();
        var ywtype = "";
        switch (data.来电类型) {
            case "咨询": ywtype = 1; break;
            case "建议": ywtype = 2; break;
            case "表扬": ywtype = 3; break;
            case "挂失": ywtype = 4; break;
            case "投诉": ywtype = 9; break;
            case "放弃排队": ywtype = 9999; break; 
            default:   break;
        }
        if (obj.event === 'view') { 
           layer.open({
                type: 2,
                anim: 4,
                scrollbar: false,
               content: '/WorkOrder/WorkOrderAllListShow/?ywtype=' + ywtype+ '&dateParty=' + dateParty ,
                area: ['90%', '90%'],
                id: 'WorkOrderAllListShow',
                title: '热线来电'

            });
        }
    });
     $ = 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 format, bottom, datas;
        $.ajax({
            url: "/Report/CallInTypeMatchChartData",
            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);
                    format = dataModel.format;
                    bottom = JSON.parse(dataModel.bottom);
                    datas = dataModel.datas;



                    // 使用
                    require(
                    [
                'echarts',
                'echarts/chart/pie' // 使用柱状图就加载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: '',
                                x: 'center'
                            },
                            tooltip: {
                                trigger: 'item',
                                formatter: "{a} <br/>{b} : {c} ({d}%)"
                            },
                            toolbox: {
                                show: true,
                                feature: {
                                    dataView: {
                                        show: true,
                                        title: '数据视图',
                                        readOnly: true,
                                        lang: ['数据视图', '关闭', '刷新']
                                    },
                                    saveAsImage: {
                                        show: true,
                                        title: '保存为图片',
                                        type: 'png',
                                        lang: ['点击保存']
                                    }
                                }
                            },
                            legend: {
                                show: true,
                                orient: 'horizontal',
                                bottom: 20,
                                data: bottom
                            },
                            series: [
                    {
                        name: '来电类型',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '55%'],
                        data: eval(datas)
                            ,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                            ]
                        };
                        // 为echarts对象加载数据
                        myChart.setOption(option);
                    }
                );
                }


            }
        });




    }

    Init();

});