$(document).ready(function () {
    if (!$('.select2').hasClass('select2-offscreen')) {
		$(".select2").select2({
			minimumResultsForSearch: -1,
			width:360
        });
        $("#faceInfo_query_province_slct,#faceInfo_query_city_slct").select2({
			minimumResultsForSearch: -1,
			width:131
        });
    }
    $("#singleAddition").click(function () {
        var title = "添加";
        CustomOpenModal.openDialogByData("addPeopleModal", "ipc/pages/events/addpeople.html?m=" + Math.random(), "",title, 1040, "");
    });

    dataTableDraw();
});
/**
 * 检验表头是否check
 * 点击每一行的时候
 */
 function checkCheck() {
    if ($(this).is(":checked") == false) {
        $('#checkall').prop("checked", false);
    }
}
function dataTableDraw() {
    var aoColumns = [
        {
            "mDataProp": "id",//mDataProp
            "title": ' <input type="checkbox" id="checkall"/ style="vertical-align:sub"><span style="margin-left:5px">序号</span></label>',
            'orderable': false  //
        },
        {
            "mDataProp": "Name",
            // "sWidth":"25%"//设置列宽
        },
        {
            "mDataProp": "Sex",
            "mRender": function (data, type, full) {// 返回自定义内容
                if (data == "male") {
                    return "男"
                } else if (data == "female") {
                    return "女"
                } else {
                    return ""
                }
            },
        },
        {
            "mDataProp": "Birthday",
            "mRender": function (data, type, full) {// 返回自定义内容
                var data = $.formatDate(data);
                return data.y + "-" + data.m + "-" + data.d;
            },
        },
        {
            "mDataProp": "ValidPeriod",//有效期
            "mRender": function (data, type, full) {// 返回自定义内容
                return '<button class="facekubutn" style="width:48px;height: 28px;line-height:28px">查看</button>';

            },
        },
        {
            "mDataProp": "Country",
        },
        {
            "mDataProp": "CertificateType",//证件类型
            "mRender": function (data, type, full) {// 返回自定义内容
                if (data == "passport") {
                    return "护照";
                } else if (data == "IC") {
                    return "身份证";
                }else if (data == "custom") {
                    return "其他";
                }else if (data == "other") {
                    return "";
                }

            },
        },
        {
            "mDataProp": "CertificateID",//证件号码
        },
        {
            "mRender": function (data, type, full) {// 返回自定义内容
                if (data == "success") {
                    return '<img src="ipc/img/icon/jianm_cg.png"><span class="model-state">建模成功</span>';
                } else {
                    return '<img src="ipc/img/icon/shij_sc.png"><span class="model-state">建模失败</span>';
                }

            },
            "mDataProp": "ModelState",
        },
        {
            "mRender": function(data, type, full) {// 返回自定义内容
                return '<button class="modify-white">修改</button>';
            },
            "mDataProp": null,
        }
    ];
    var aaData = [{
        "id": "1",
        "Name": "huangsheng",
        "Sex": "male",
        "Birthday": "20231213T000000",
        "ValidPeriod": "2020-01-01",
        "Country": "wuhan",
        "CertificateType": "passport",
        "CertificateID": "123456789",
        "ModelState": "success",

    },
    {
        "id": "2",
        "Name": "huangsheng",
        "Sex": "unknown",
        "Birthday": "20231213T000000",
        "ValidPeriod": "2020-01-01",
        "Country": "wuhan",
        "CertificateType": "IC",
        "CertificateID": "123456789",
        "ModelState": "failed",

    }]
    $("#wihteTableList").dataTable({
        "columnDefs": [{
            targets: 0,
            render: function (data, type, row, meta) {
                //每一行第一列都是复选框, 复选框要有name属性 方便查找
                //并且要加一个onclick 事件, 保证单选的时候也检查表头复选框状态.
                    return '<input type="checkbox" name="checklist" style="vertical-align:sub" οnclick="checkCheck()" value="' + row.id + '" /><span style="margin-left:5px">' + row.id + '</span>'
                }
        }],
        "aaData":aaData,
        "retrieve": true,//可能是表格重复使用时受到影响 必须加上
        "processing": true,
        "paging": true,
        "bPaginate": true, //翻页功能
        "sPaginationType": "bootstrap", //翻页风格
        "bLengthChange": true, //开关，是否显示每页大小的下拉框
        "bFilter": false, //过滤功能
        "bSort": false, //排序功能
        "bInfo": true, //页脚信息
        "bAutoWidth": false, //自动宽度
        // "bServerSide": true, //启用服务器分页
        "bDestroy": false, //解决重新渲染问题
        "iDisplayLength": 10, //每页显示数量
        "aoColumns": aoColumns,
        "dom": '<t><lfip>',
        "infoCallback": function (settings, start, end, max, total, pre) {
            return "共有"+ total + "条记录"
        },
        "initComplete": function (settings, json) {
         },
        // 当表格重绘就会调用这个回调
        fnDrawCallback: function (data) {
        },
        // fnServerData: retrieveData
    });
}
function retrieveData(sSource, aoData, fnCallback) {
    // 获取pageSize
    var pageSize = aoData[4].value;
    //获取page
    var start = aoData[3].value;
    var page = Math.ceil(start / pageSize) + 1;

}
