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 === 'view') {
            layer.open({
                type: 2,
                anim: 4,
                scrollbar: false,
                content: '/LostGoods/LostGoodsView/?fid=' + data.F_Id,
                area: ['1000px', '90%'],
                id: 'RebackLost',
                title: '失物详情',

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

            LoadDataList();
        }

        //批量接收
        , saveData: function () {
            var checkStatus = table.checkStatus('recordtable')
                   , data = checkStatus.data;
            if (data.length == 0) {
                layui.layer.alert("请先选中要操作的数据行！", {
                    icon: 3
                });
            }
            else {
                var strId = "";
                for (var i = 0; i < data.length; i++) {
                   
                        if (i == 0) {
                            strId += data[i].rowKey;
                        }
                        else {
                            strId += "," + data[i].rowKey;
                        }
                }
                layer.confirm('确认要接收选中行的数据？', function (index) {
                    $.ajax({
                        url: "/LostGoods/SaveReceivedData",
                        type: "get",
                        async: false,//同步请求
                        contentType: "application/json",
                        dataType: "text",
                        cache: false,
                        data: "keyList=" + strId + "&status=1",
                        success: function (thisResult, result) {

                            if (thisResult == "True") {
                                layer.open({
                                    content: '操作成功'
                                     , icon: 1
                                     , btn: ['确定']
                                     , yes: function (index, layero) {
                                         LoadDataList();
                                         layer.close(index);
                                     }
                                });
                            } else {
                                layui.layer.alert("接收失败!", {
                                    icon: 2
                                });

                            }
                        },
                        error: function (error) {
                            return false;
                        }
                    });
                    layer.close(index);
                });





            }
        }

        //批量退回
        , reback: function () {
            var checkStatus = table.checkStatus('recordtable')
                   , data = checkStatus.data;
            if (data.length == 0) {
                layui.layer.alert("请先选中要操作的数据行！", {
                    icon: 3
                });
            }
            else {
                var strId = "";
                for (var i = 0; i < data.length; i++) {

                    if (i == 0) {
                        strId += data[i].rowKey;
                    }
                    else {
                        strId += "," + data[i].rowKey;
                    }
                }
                layer.confirm('确认要退回选中行的数据？', function (index) {
                    $.ajax({
                        url: "/LostGoods/SaveReceivedData",
                        type: "get",
                        async: false,//同步请求
                        contentType: "application/json",
                        dataType: "text",
                        cache: false,
                        data: "keyList=" + strId + "&status=2",
                        success: function (thisResult, result) {

                            if (thisResult == "True") {
                                layer.open({
                                    content: '操作成功'
                                     , icon: 1
                                     , btn: ['确定']
                                     , yes: function (index, layero) {
                                         LoadDataList();
                                         layer.close(index);
                                     }
                                });
                            } else {
                                layui.layer.alert("退回失败!", {
                                    icon: 2
                                });

                            }
                        },
                        error: function (error) {
                            return false;
                        }
                    });
                    layer.close(index);
                });





            }
        }

    };

    function LoadDataList() {
        //执行重载
        table.reload('recordtable', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
          , where: {
              NowDateTime: new Date()
               , getDate: $("#test10").val()
               , goodsName: $("#goodsName").val()
               , goodsProty: $("#goodsProty").val()
               , goodsKinds: $("#goodsKinds").val()
                , getPlace: $("#getPlace").val()

          }
        });
    }

    //回车执行
    document.onkeydown = function (event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 13) {
            LoadDataList();
        }
    };
    $('.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);
    })

});