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

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

  // 静态数据
  var tableData = [
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	{id: 1, month: '2024-03', lineName: '±500kV永富直流线', pagodaNum: '300', visitationNum: '21', visitationCount: '256', specialPatrolPersonNum: '100', station: '昆明运检一站', comName: '运检一公司'},
	
  ];

    
/**
 * 初始化数据
 */
function init(){
      // 渲染表格
  table.render({
    elem: '#table',
    // url: "/sys/achievement",
    page: true,
    skin: 'line', // 表格样式
    cols: [[
        {
            title: '序号',
            field: 'zizeng',
            align: 'center',
            type: 'numbers',
        },
        {field:'month', title: '月份',align: 'center'},
        {field:'lineName', title: '线路名称',align: 'center'},
        {field:'pagodaNum', title: '塔基数（基）',align: 'center'},
        {field:'visitationNum', title: '正常巡视次数（次）',align: 'center'},
        {field:'visitationCount', title: '共完成正常巡视塔基数（基）',align: 'center'},
		{field:'specialPatrolPersonNum', title: '值守及特巡（天*人）',align: 'center'},
        {field:'station', title: '所属运检站',align: 'center'},
		{field:'comName', title: '所属分公司',align: 'center'},
        {
            field: '',
            title: '操作',
            align: 'center',
			width: '20%',
            templet: function(d){
				var id= d.id;
				
				//详情
				var html = `<button class="layui-btn layui-btn-sm" onclick="detailsView('${id}')">详情</button>`
            	
            	return html;
            },
        }
    ]],
    data: tableData
  });
     
}


//详情
function detailsView(id) {
    /* $.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: './wagesReport/producePayrollDetails.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()为子页面的方法

                },
            });
        }
    }) */
	
	//测试
	let height = '98%';
	let width = '99%';
	var index = layer.open({
	    title: ['工程杆塔巡视详情', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
	    type: 2,
	    content: './workVisaDetails.html',
	    area: [width, height],
	    maxmin: false,
	    success: function (layero, index) {
	        // var myIframe = window[layero.find('iframe')[0]['name']];
	        // myIframe.hideSubmit();
	        // var fnc = myIframe.setData(data.data); //aaa()为子页面的方法
	
	    },
	});
}


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