layui.use('laydate', function () {
    var laydate = layui.laydate;
    //日期时间范围
    laydate.render({
        elem: '#test10'
        , 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;
        if (obj.event === 'edit') {
            //置忙
            if ($("#SeatFlag").val() === 1) {
                top.AgentBusy();
            }

            var openUrl = "";
            //微信
            if (data.F_REPAIRMANID === 3) {
                openUrl = '/CallRecord/WXWorkFlowEdit/?workOrderNum=' + data.F_WORKORDERID;
            }
            //微博
            else if (data.F_REPAIRMANID === 4) {
                openUrl = '/CallRecord/WXWorkFlowEdit/?workOrderNum=' + data.F_WORKORDERID;
            }
            //语音工单
            else {
                openUrl = '/CallRecord/CallWorkFolw/?workOrderNum=' + data.F_WORKORDERID + '&flowid=' + data.F_REPAIRLEVEL;
            }
            layer.open({
                type: 2,
                anim: 4,
                scrollbar: false,
                content: openUrl,
                area: ['90%', '90%'],
                id: 'CallWorkFolw',
                title: '服务监督热线系统业务工单',
                end: function () {
                    //置闲
                    if ($("#SeatFlag").val() === 1) {
                        top.AgentFree();
                    }
                    //执行重载
                    table.reload('recordtable', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            types: 0,
                            dateParty: $("#test10").val(),
                            NowDateTime: new Date()

                        }
                    });
                }

            });
        }

    });
  $ = layui.$, active = {
        //新增
        rowAdd: function () { 
                layer.open({
                    type: 2,
                    anim: 4,
                    scrollbar: false,
                    content: '/CallRecord/WBWorkFlow/?workOrderNum=0&ywType=1',
                    area: ['90%', '90%'],
                    id: 'WXWorkFlow',
                    title: '微博工单'
                    , end: function () { 
                        //执行重载
                        table.reload('recordtable', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                            , where: {
                                types: 0,
                                dateParty: $("#test10").val(),
                                NowDateTime: new Date() 
                            }
                        });
                    }
                }); 
        }
        //查询按钮
        ,reload: function () { 
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    types: 0,
                    dateParty: $("#test10").val(),
                    NowDateTime: new Date()

                }
            });
        }
        //一周
        , oneWeek: function () {
            var dataParty = getWeekStartDate() + ' - ' + formatDate(now);
            $(".dayParty").val(dataParty);
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    types: 1
                    , NowDateTime: new Date()


                }
            });
        }
        //本月
        , oneMonth: function () {
            var dataParty = getMonthStartDate() + ' - ' + formatDate(now);
            $(".dayParty").val(dataParty); 
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    types: 2
                    , NowDateTime: new Date()

                }
            });
        }
        //一年
      , oneYear: function () {
        var dataParty = getYearStartDate() + ' - ' + formatDate(now);
          $(".dayParty").val(dataParty); 
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    types: 3
                    , NowDateTime: new Date()

                }
            });
        }
    };

    //回车执行
    document.onkeydown = function (event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode === 13) {
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    types: 0,
                    dateParty: $("#test10").val(),
                    NowDateTime: new Date()

                }
            });
        }
    };

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

});