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;
    //监听表格复选框选择
    table.on('checkbox(demo)', function (obj) {
        console.log(obj);
    });

    var $ = layui.$, active = {
        //查询按钮
        reload: function () {
            var cusName = $('#cusName');
            var cusNum = $('#cusNum');
            //执行重载
            table.reload('recordtable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    dateParty: $("#test10").val()
                    , NowDateTime: new Date()
                    ,cusName: cusName.val()
                    ,cusNum: cusNum.val()

                }
            });
        }

        //删除
        , rowDelete: function () {

            var checkStatus = table.checkStatus('recordtable')
                , data = checkStatus.data;
            if (data.length === 0) {
                layui.layer.alert("请先选中要操作的数据行！", {
                    icon: 3
                });
            }
            else {

                layer.confirm('确认要删除该行数据么？', function (index) {

                    var strId = "";
                    for (var i = 0; i < data.length; i++) {
                        if (i === 0) {
                            strId += +data[i].SMSID;
                        }
                        else {
                            strId += "," + data[i].SMSID;
                        }
                    }

                    $.ajax({
                        url: "/SMS/DeleteSmsData",
                        type: "get",
                        async: false,//同步请求
                        contentType: "application/json",
                        dataType: "text",
                        cache: false,
                        data: "smsId=" + strId,
                        success: function (thisResult, result) {

                            if (thisResult === "True") {
                                layer.open({
                                    content: '删除成功'
                                    , icon: 1
                                    , btn: ['确定']
                                    , yes: function (index, layero) {

                                        layer.close(index);
                                        RefushTableList();

                                    }
                                });
                            } else {
                                layui.layer.alert("删除失败!", {
                                    icon: 2
                                });

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

        }


    };

    $('.searchfilter .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    formatcalldir = function (d) {
        var rescontent = "";
        if (d === 1) {
            rescontent = "<i class=\"iconfont icon-huchu\"></i>";
        }
        else {
            rescontent = "<i class=\"iconfont icon-huru\"></i>";
        }
        return rescontent;
    };


    //刷新表
    function RefushTableList() {
        //执行重载
        table.reload('recordtable', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            , where: { 
                 dateParty: $("#test10").val()
                , NowDateTime: new Date()
            }
        });
    }



});