 
 
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
		 data.field.yjId=localStorage.getItem("selectyj");
		 data.field.subId=localStorage.getItem("selectSubCom");
        table.reload('table', {
            // //设定异步数据接口的额外参数
            page:{curr : 1}
            ,where: data.field
        })
        return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
	$("#reset").click(function(){
		console.log("重置")
		$('#userName').val('');
		$('#yjName').val('');
		$('#proName').val('');
		$('#makeMonth').val('');
		let obj = {
		    userName:'',
		    yjName:'',
			proName:'',
			makeMonth:'',
			yjId:localStorage.getItem("selectyj"),
			subId:localStorage.getItem("selectSubCom")
		}
		 // 对表格进行重载。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.data.id,obj.data.userId,obj.data.makeMonth);
                break;
       }
   });
    init();
});



var col = [
	[
		{
		    title: '序号',
		    field: 'zizeng',
		    align: 'center',
		    type: 'numbers',
			rowspan: 2
		},
		{
		    title: '运检站',
		    field: 'yjName',
		    align: 'center',
			rowspan: 2
		},
		{
		    title: '月份',
		    field: 'makeMonth',
		    align: 'center',
			rowspan: 2
		},
		{
		    title: '线路名称',
		    field: 'proName',
		    align: 'center',
			rowspan: 2
		},
		{
		    title: '运维总区段',
		    field: 'allGtName',
		    align: 'center',
			rowspan: 2
		},
		{
		    title: '姓名',
		    field: 'userName',
		    align: 'center',
			rowspan: 2
		},
		{
		    title: '管辖线路名称',
		    field: 'proName',
		    align: 'center',
			rowspan: 2,
		},
		{
		    title: '负责巡护区段',
		    align: 'center',
			rowspan: 2,
			templet: function(d){
				var dutyPatrol = d.gtName
				var gt=dutyPatrol==null?"":dutyPatrol;
				var gts=gt.split("/");
				var gtnum=0;
				if(gt==""){
					gtnum=0;
				}else{
					gtnum=gts.length-1;
				}
				var html = `<span style="color:#F56C82">${gtnum}基：</span><span>${dutyPatrol}</span>`;
				return html;
			},
		},
		{
			title: '本月实际提供到位照区段(或塔）及张数',
			colspan: 5,
			align: 'center'
		},
		{
		    title: '操作',
		    toolbar: '#opeator-bar',
		    align: 'center',
			rowspan: 2,
		},
	],
	[
		{
			title: '巡1次区段（基）',
			field: 'oneGt',
			align: 'center',
		},
		{
			title: '巡1次张数',
			field: 'oneMake',
			align: 'center',
		},
		{
			title: '巡2次区段（基）',
			field: 'twoGt',
			align: 'center',
		},
		{
			title: '巡2次张数',
			field: 'twoMake',
			align: 'center',
		},
		{
			title: '特巡天数',
			field: 'special',
			align: 'center',
		},
		
	],
]
    
/**
 * 初始化数据
 */
function init(){
	var subComId = $(window.parent.document).find("select[id='subComId']").val(); 
      // 渲染表格
  table.render({
    elem: '#table',
    url: PATH_URL + "/makeInfo/getListTabs",
    page: true,
	method:'post',
	border: true,
	// data: tableData,
    cols: col,
  });
     
}


//详情
function detailsView(id,userId,makeMonth) {
    localStorage.setItem("resultdataId",id);
    localStorage.setItem("resultdataMakeMonth",makeMonth);
    localStorage.setItem("resultdataUserId",userId);
    let height = '98%';
    let width = '99%';
    var index = layer.open({
        title: ['详情', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
        type: 2,
        content: './viewStatisticsDetails.html',
        area: [width, height],
        maxmin: false,
        success: function (layero, index) {
            // var myIframe = window[layero.find('iframe')[0]['name']];
            // myIframe.setDate();
            // var fnc = myIframe.setData(data.data); //aaa()为子页面的方法
    
        },
    });
}


//修改
function updateView(id) {
    let height = '98%';
    let width = '99%';
    /* $.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()为子页面的方法

                },
            });
        }
    }) */
	
	//测试
	var index = layer.open({
	    title: ['巡视结果上传', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
	    type: 2,
	    content: './viewResultUpdate.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 userName = $("#userName").val();
	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 + `/makeInfo/exportDatas?token=` + token
        + "&userName=" + userName
		+ "&proName=" + proName
		+ "&yjName=" + yjName
		+ "&makeMonth=" + makeMonth
		+ "&subId=" + subId
		+ "&yjId=" + yjId
}