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();
            }
            layer.open({
                type: 2,
                anim: 4,
                scrollbar: false,
                content: '/WorkOrder/EditMyOrder/?dtype=' + $("#dtype").val() + '&orderKeyId=' + data.F_WORKORDERID,
                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()
                          , workorderNum: $("#workorderNum").val()
                   , cusName: $("#cusName").val()
                    , userInfo: $("#userInfo").val()
                  , bussType: $("#bussType").val()
                   , detailType: $("#bussDetail").val()
                   , Content: $("#Content").val()

                      }
                    });
                }

            });
        }
        else if (obj.event === 'view') {
            layer.open({
                type: 2,
                anim: 4,
                scrollbar: false,
                content: '/WorkOrder/ViewMyOrder/?orderKeyId=' + data.F_WORKORDERID,
                area: ['90%', '90%'],
                id: 'ViewMyOrder',
                title: '服务监督热线系统业务工单'

            });
        }
    });
    var $ = layui.$, active = {
        //查询按钮
        reload: function () {

            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
              , where: {
                  types: 0,
                  dateParty: $("#test10").val()
                    , NowDateTime: new Date()
                   , workorderNum: $("#workorderNum").val()
                   , cusName: $("#cusName").val()
                   , phoneNumber: $("#phoneNumber").val()
                    , userInfo: $("#userInfo").val()
                  , bussType: $("#bussType").val()
                   , detailType: $("#bussDetail").val()
                   , Content: $("#Content").val()
              }
            });
        }
        //一周
        , oneWeek: function () {
            var dataParty = getWeekStartDate() + ' - ' + formatDate(now);
            $(".dayParty").val(dataParty);
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
              , where: {
                  types: 1
                    , NowDateTime: new Date()
                   , workorderNum: $("#workorderNum").val()
                   , cusName: $("#cusName").val()
                   , phoneNumber: $("#phoneNumber").val()
                    , userInfo: $("#userInfo").val()
                  , bussType: $("#bussType").val()
                   , detailType: $("#bussDetail").val()
                   , Content: $("#Content").val()

              }
            });
        }
        //一月
        , oneMonth: function () {
            var dataParty = getMonthStartDate() + ' - ' + formatDate(now);
            $(".dayParty").val(dataParty);
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
              , where: {
                  types: 2
                    , NowDateTime: new Date()
                   , workorderNum: $("#workorderNum").val()
                   , cusName: $("#cusName").val()
                   , phoneNumber: $("#phoneNumber").val()
                    , userInfo: $("#userInfo").val()
                  , bussType: $("#bussType").val()
                   , detailType: $("#bussDetail").val()
                   , Content: $("#Content").val()
              }
            });
        }
        //一年
        , oneYear: function () {
            var dataParty = getYearStartDate() + ' - ' + formatDate(now);
            $(".dayParty").val(dataParty);
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
              , where: {
                  types: 3
                    , NowDateTime: new Date()
                   , workorderNum: $("#workorderNum").val()
                   , cusName: $("#cusName").val()
                   , phoneNumber: $("#phoneNumber").val()
                    , userInfo: $("#userInfo").val()
                  , bussType: $("#bussType").val()
                   , detailType: $("#bussDetail").val()
                   , Content: $("#Content").val()
              }
            });
        }
    };


    //回车执行
    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()
                   , workorderNum: $("#workorderNum").val()
                   , cusName: $("#cusName").val()
                   , phoneNumber: $("#phoneNumber").val()
                    , userInfo: $("#userInfo").val()
                  , bussType: $("#bussType").val()
                   , detailType: $("#bussDetail").val()
                   , Content: $("#Content").val()
              }
            });
        }
    };



    $('.searchfilter .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    //高级查询折叠
    $('#advanceBtn').on('click', function () {
        $('.collapsible_box').slideToggle(200);
    })
    //.监听当前 select，动态改变子项
    form.on('select(fcoptype)', function (d) {
        $.ajax({
            url: "/WorkOrder/GetBussType",
            type: "get",
            contentType: "application/json",
            dataType: "text",
            cache: false,
            data: { "bussnessType": d.value },
            success: function (result, status) {
                if (status) {
                    $("#bussDetail").empty();
                    $("#bussDetail").append("<option value='' ></option>");
                    var list = eval("(" + result + ")");
                    if (list.length > 0) {
                        for (var i = 0; i < list.length; i++) {
                            $("#bussDetail").append("<option  value='" + list[i].F_WorkOrderTypeId + "'>" + list[i].F_Name + "</option>");
                        }
                    }

                    form.render('select');
                }
                else {
                    layui.layer.alert("获取信息失败!", {
                        icon: 2
                        ,offset: '40%'
                    });
                }

            }
        });
    });

});