 
 
var pers = []
var table,form
layui.use(['form','layer','table'], function () {
    table = layui.table;
    form = layui.form;

    // 触发submit提交 按钮点击或者表单被执行提交时触发
    form.on('submit(query)', function (data) {
        console.log("搜索")
            // 对表格进行重载。id 即 table表格的id
        table.reload('table', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: data.field
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    form.on('submit(reset)', function () {
        console.log("重置")
        $('#search1').val('');
        $('#search2').val('');
        $('#search3').val('');
        $('#search4').val('');
        form.render();
        let obj = {
            search1:'',
            search2:'',
            search3:'',
            search4:''
        }
            // 对表格进行重载。id 即 table表格的id
        table.reload('table', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: obj
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    table.on('tool(table)', function (obj) {
        switch (obj.event) {
            case 'edit': 
                console.log('详情',obj) 
                updateView()
                break;
            case 'del': 
                console.log('删除',obj) 
                delView()
                break;
        }
    });
    init();
});

  // 静态数据
  var tableData = [
    {id: 1, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 2, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 3, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 4, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 5, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 6, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 7, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 8, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 9, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 10, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 11, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 12, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 13, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 14, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 15, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 16, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 17, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 18, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 19, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 20, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 21, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 22, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 23, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
    {id: 24, name: '李云飞', idCard: '342224196202241356', sex: '男',ages:'55',phone:'15665366624',line:'500kVxxx线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01',endTime:'2025-01-01',status1:'在职',status2:'已签订',status3:'正式'},
  ];

    
/**
 * 初始化数据
 */
function init(){
      // 渲染表格
  table.render({
    elem: '#table',
    // url: "/sys/achievement",
    page: true,
    skin: 'line', // 表格样式
    data: tableData,
    cols: [[
        {
            title: '序号',
            field: 'zizeng',
            align: 'center',
            type: 'numbers'
        },
        {field:'name', title: '姓 名',align: 'center',},
        {field:'idCard', title: '身份证号',align: 'center',},
        {field:'sex', title: '性别',align: 'center',},
        {field:'ages', title: '年龄',align: 'center',},
        {field:'phone', title: '联系电话',align: 'center',},
        {field:'line', title: '管辖线路名称',align: 'center'},
        {field:'area', title: '范围、基数',align: 'center',width:170},
        {field:'startTime', title: '协议起始日期',align: 'center', },
        {field:'endTime', title: '协议终止日期',align: 'center', },
        {field:'status1', title: '人员状态',align: 'center',},
        {field:'status2', title: '合同状态',align: 'center',},
        {field:'status3', title: '人员类型',align: 'center',},
        {
            title: '操作',
            toolbar: '#opeator-bar',
            align: 'center',
            width: 200
        }
    ]],
  });
     
}

/**
 * 新增页面
 * */
function add() {
    var height = '98%';
    var width = '80%';
    var index = layer.open({
        title: ['新增人员', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
        type: 2,
        content: 'staffAdd.html',
        area: [width, height],
        maxmin: false,
        success: function (layero, index) {
            // //打开页面成功时执行
            var myIframe = window[layero.find('iframe')[0]['name']];
            //getTaskSource()为子页面的方法
            // myIframe.getTaskSource("taskSourceId","");

        },
        yes: function (index, layero) {
            // //提交子页面时执行
            // // 获取弹出层中的form表单元素
            // var formSubmit = layer.getChildFrame('form', index);
            // var submited = formSubmit.find('button')[0];
            // // 触发点击事件，会对表单进行验证，验证成功则提交表单，失败则返回错误信息
            // // var myIframe = window[layero.find('iframe')[0]['name']];
            // // myIframe.selectCheck(); //aaa()为子页面的方法
            // submited.click();
            // example.ajax.reload(); // 刷新页面
        }
    });
}

 

/**
 * 查看
 * */
function checkView(id) {
    let height = '98%';
    let width = '80%';
    $.ajax({
        type: 'post',
        contentType: "application/x-www-form-urlencoded",
        url: oiPlanUrl + '/monthlyPlanSubmission/getDataById',
        dataType: 'json',
        data: {
            id: id
        },
        success: function (data) {
            var index = layer.open({
                title: ['查看', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
                type: 2,
                content: 'staffAdd.html',
                area: [width, height],
                maxmin: false,
                success: function (layero, index) {
                    console.log(data);
                    var myIframe = window[layero.find('iframe')[0]['name']];
                    myIframe.hideSubmit();
                    // var fnc = myIframe.setData(data.data); //aaa()为子页面的方法

                },
            });
        }
    })
}

 

/**
 * 修改
 * */
function updateView(id) { 
        let height = '98%';
        let width = '80%';
        // $.ajax({//id获取详情打开弹窗传值子页面
        //     type: 'post',
        //     contentType: "application/x-www-form-urlencoded",
        //     url: oiPlanUrl + '/monthlyPlanSubmission/getDataById',
        //     dataType: 'json',
        //     data: {
        //         id: id
        //     },
        //     success: function (data) {
                var index = layer.open({
                    title: ['修改', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
                    type: 2,
                    content: 'staffAdd.html',
                    area: [width, height],
                    maxmin: false,
                    success: function (layero, index) {
                        //打开页面成功时执行
                        var myIframe = window[layero.find('iframe')[0]['name']];
                        // myIframe.setData(data.data); //调用子页面的方法
                    },
                    yes: function (index, layero) {
                        // //提交子页面时执行
                        // // 获取弹出层中的form表单元素
                        // var formSubmit = layer.getChildFrame('form', index);
                        // var submited = formSubmit.find('button')[0];
                        // // 触发点击事件，会对表单进行验证，验证成功则提交表单，失败则返回错误信息
                        // submited.click();
                    }
                });
            // }
        // })
 
}

 

/**
 * 删除
 * */
function delView(id) {
 
        let index = layer.confirm("是否确定删除数据？", function () {
            $.ajax({
                type: 'post',
                url: oiPlanUrl + '/monthlyPlanSubmission/del',
                dataType: 'json',
                data: {
                    id: id
                },
                success: function (data) {
                    layer.close(index);
                    if (data.code == 200) {
                        top.layer.alert('删除成功', {icon: 1});
                        // example.ajax.reload(); // 刷新页面
                    } else {
                        layer.msg("删除失败", {icon: 2}, function () {
                            // example.ajax.reload(); // 刷新页面
                        });
                    }
                }
            })
        })
 
}
    
function importData(){
    var height = '80%'; 
    var width = '50%';  
    var index = layer.open({
        title: [`导入`, 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
        type: 2,
        // content: 'child/orgInformation.html',
        content: 'staffImport.html',
        area: [width, height],
        maxmin: false,
        success: function (layero, index) {
            /*var myIframe = parent.window[layero.find('iframe')[0]['name']];
            var json = {'proIds': proId}
            myIframe.setParams(json)*/
        },
        yes: function (index, layero) {
        },
        end: function () {
        }
    });
}

function importDataThread(formData, idx) {
    $.ajax({
        url: oiPlanUrl + "/basePerson/importData",
        type: 'POST',
        async: false,
        data: formData,
        timeout: 20000,
        // 告诉jQuery不要去处理发送的数据
        processData: false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType: false,
        success: function (data) {
            layer.close(idx);
            if (data.code == 200) {
                layer.alert(data.data, {icon: 1});
                // example.ajax.reload(); // 刷新页面
            } else{
                layer.alert(data.msg, {icon: 2});
            }

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(JSON.stringify(errorThrown));
            layer.close(idx);
        }
    });
    $("#basePersonFile").val("");
}

//导出
function exportData() {
    // let search1 = $('#search1').val();
    // let search2 = $('#search2').val();
    window.location.href = oiPlanUrl + "/monthlyPlanSubmission/export?token=" + token;
         

}