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

    
    //杆塔信息

    initGmTable()
    // 触发submit提交 按钮点击或者表单被执行提交时触发
    form.on('submit(queryGm)', function (data) {
        console.log("搜索")
         // 对表格进行重载。id 即 table表格的id
        table.reload('gmTable', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: data.field
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    form.on('submit(resetGm)', function () {
        console.log("重置")
        $('#search1').val('');
        $('#search2').val('');
        let obj = {
            search1:'',
            search2:''
        }
         // 对表格进行重载。id 即 table表格的id
        table.reload('gmTable', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: obj
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    let selectList = [{name:'全部',value:''},{name:'已绑定',value:'0'},{name:'未绑定',value:'1'}]
    $.each(selectList, function(index, value) {
        // console.log(value);
        $('#search2').append(new Option(value.name, value.value)); // 下拉菜单里添加元素
    });
    form.render("select");//重新渲染





    //人员信息
    initStaffTable()
    // 触发submit提交 按钮点击或者表单被执行提交时触发
    form.on('submit(queryUser)', function (data) {
        console.log("搜索")
         // 对表格进行重载。id 即 table表格的id
        table.reload('staffTable', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: data.field
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    form.on('submit(resetUser)', function () {
        console.log("重置")
        $('#search1').val('');
        $('#search2').val('');
        let obj = {
            search1:'',
            search2:''
        }
         // 对表格进行重载。id 即 table表格的id
        table.reload('staffTable', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: obj
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });








    
    form.render();
    init();



});




 // 静态数据
 var tableData = [
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
    {id: 1, gmName: 'N1', lName: '张三', uName: 'J10 (xxxx乙线)',month:'张三'},
  ];

 // 静态数据
 var tableData2 = [
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
    {id: 1, name: '李云飞', idCard: '342224196202241356', phone: '15665366624',line:'500kV邑劝甲线,500kV邑劝乙线',area:'N1/N2/N3/N4/N5/N6/N7/N8/N9/N10',startTime:'2024-01-01', endTime:'2025-01-01'},
  ];

/**
 * 初始化数据
 */
function init(){

}
 // 渲染杆塔表格
function initGmTable(){
   
    table.render({
    elem: '#gmTable',
    // url: "/sys/achievement",
    page: true,
    skin: 'line', // 表格样式
    cols: [[
        {
            type: 'checkbox'
        },
        {
            title: '序号',
            field: 'zizeng',
            align: 'center',
            type: 'numbers'
        },
        {field:'gmName', title: '杆塔名称',align: 'center',},
        {field:'lName', title: '护线员 (来源：人员合同)',align: 'center',},


        {field:'uName', title: '对应双回路杆塔',align: 'center',},
        {field:'month', title: '对应双回路杆塔护线员',align: 'center',}, 

        {
            title: '操作（双回路杆塔设置）',
            toolbar: '#opeator-bar',
            align: 'center',
            width: 200
        }
    ]],
    data: tableData
    });
}

function addGm(){
    var height = '42%'; 
    var width = '38%';  
    var index = layer.open({
        title: [`选择工程、杆塔 `, 'color:#3B70A1;background-color:#fff;font-size:20px'],
        type: 1,
        content: $("#gmDetail").html(),
        closeBtn: 1,
        area: [width, height],
        success: function (layero, index) {  

        },
 
        cancel: function(index, layero){//关闭
            console.log(3)
            layer.close(index);
        },
        
    });
}   

// 渲染人员表格
function initStaffTable(){
    table.render({
        elem: '#staffTable',
        // url: "/sys/achievement",
        page: true,
        skin: 'line', // 表格样式
        cols: [[
            {
                type: 'checkbox'
            },
            {
                title: '序号',
                field: 'zizeng',
                align: 'center',
                type: 'numbers'
            },
            {field:'name', title: '姓 名',align: 'center',width:100},
            {field:'idCard', title: '身份证号',align: 'center',},
            {field:'phone', title: '联系电话',align: 'center',width:120},
            {field:'line', title: '管辖线路名称',align: 'center',width:350}, 
            {field:'area', title: '范围、基数',align: 'center',width:350}, 
            {field:'startTime', title: '协议起始日期',align: 'center',width:140}, 
            {field:'endTime', title: '协议终止日期',align: 'center',width:140}
        ]],
        data: tableData2
    });
}


function editProject(){
    window.parent.updateView();
}

function projectAddUser(){
    var height = '98%';
    var width = '90%';
    var index = layer.open({
        title: ['新增人员', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
        type: 2,
        content: 'projectAddUser.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(); // 刷新页面
        }
    });
}
