
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: '#makeMonth',
	    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("重置")
		$('#proName').val('');
		$('#yjName').val('');
		$('#makeMonth').val('');
		let obj = {
		    proName:'',
		    yjName:'',
			makeMonth:''
		}
		 // 对表格进行重载。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(){
	var subComId = $(window.parent.document).find("select[id='subComId']").val(); 
      // 渲染表格
  table.render({
    elem: '#table',
    url: PATH_URL + "/workvisa/getListTab",
    page: true,
	method:'post',
    skin: 'line', // 表格样式
    cols: [[
        {
            title: '序号',
            field: 'zizeng',
            align: 'center',
            type: 'numbers',
        },
        {field:'makeMonth', title: '月份',align: 'center'},
        {field:'proName', title: '线路名称',align: 'center'},
        {field:'powerNum', title: '塔基数（基）',align: 'center'},
        {field:'makeNum', title: '正常巡视次数（次）',align: 'center'},
        {field:'ygtNum', title: '共完成正常巡视塔基数（基）',align: 'center'},
		{field:'specialNum', title: '值守及特巡（天*人）',align: 'center'},
        {field:'yjName', title: '所属运检站',align: 'center'},
		{field:'subName', title: '所属分公司',align: 'center'},
        {
            field: '',
            title: '操作',
            align: 'center',
			width: '20%',
            templet: function(d){
				var id= d.id;
				var proId=d.proId;
				var makeMonth=d.makeMonth;
				//详情
				var html = `<button class="layui-btn layui-btn-sm" onclick="detailsView('${id}','${proId}','${makeMonth}')">详情</button>`
            	
            	return html;
            },
        }
    ]],
    // data: tableData
  });
     
}


//详情
function detailsView(id,proId,makeMonth) {
   
	localStorage.setItem("resultVisaId",id);
	localStorage.setItem("resultVisaProId",proId);
	localStorage.setItem("resultVisaMakeMonth",makeMonth);
	//测试
	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() {
	var proName = $("#proName").val();
	var yjName = $("#yjName").val();
	var makeMonth = $("#makeMonth").val();
	yjId=localStorage.getItem("selectyj");
	subId=localStorage.getItem("selectSubCom");
    window.location.href = PATH_URL + `/workvisa/exportData?token=` + token
		+ "&proName=" + proName
		+ "&yjName=" + yjName
		+ "&makeMonth=" + makeMonth
		+ "&subId=" + subId
		+ "&yjId=" + yjId
}