 
 
var pers = []
var table,form,laydate
var yjId=localStorage.getItem("oneselectyj");
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(data,"搜索")
         // 对表格进行重载。id 即 table表格的id
        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:yjId
		}
		 // 对表格进行重载。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;
			case 'uploadResult':
				console.log('上传结果',obj.data.id,obj.data.userId) 
				updateView(obj.data.id,obj.data.userId,obj.data.makeMonth);
				break;
       }
   });
    init();
});
    
/**
 * 初始化数据
 */
function init(){
	let obj = {
	    userName:'',
	    yjName:'',
		proName:'',
		makeMonth:'',yjId:yjId
	}
      // 渲染表格
  table.render({
	elem: '#table',
	url: PATH_URL + "/makeInfo/getListTab",
	page: true, //开启分页
	method:'post',
	where:obj,
	skin: 'line', // 表格样式
    cols: [[
        {
            title: '序号',
            field: 'zizeng',
            align: 'center',
            type: 'numbers'
        },
        {field:'yjName', title: '运检站',align: 'center',},
        {field:'proName', title: '线路名称',align: 'center',},
        {field:'userName', title: '姓名',align: 'center',},
        {field:'makeMonth', title: '月份',align: 'center',},
        {field:'powerNum', title: '负责巡护区段',align: 'center',},
		{
			field: '',
			title: '正常巡视结果(第一次)',
			align: 'center',
			templet: function(d){
				var oneMake = d.oneMake
				var html = `<span style="color:#19BE6B">${oneMake}</span>`;
				return html;
			},
		},
		{
			field: '',
			title: '正常巡视结果(第二次)',
			align: 'center',
			templet: function(d){
				var twoMake = d.twoMake
				var html = `<span style="color:#19BE6B">${twoMake}</span>`;
				return html;
			},
		},
		{
			field: '',
			title: '巡视段外巡视',
			align: 'center',
			templet: function(d){
				var otherMake = d.otherMake
				var html = `<span style="color:#FF9900">${otherMake}</span>`;
				return html;
			},
		},
		{
			field: '',
			title: '未巡视',
			align: 'center',
			templet: function(d){
				var noMake = d.noMake
				var html = `<span style="color:#F56C6C">${noMake}</span>`;
				return html;
			},
		},
		{
			field: '',
			title: '特巡天数结果',
			align: 'center',
			templet: function(d){
				var special = d.special
				var html = `<span style="color:#73A0FA">${special}</span>`;
				return html;
			},
		},
        {
            title: '操作',
            toolbar: '#opeator-bar',
            align: 'center',
            width: 200
        }
    ]],
	done: function(res, curr, count){
		console.log(res)
	}
  });
     
}


//详情
function detailsView(id,userId,makeMonth) {
	localStorage.setItem("resultId",id);
	localStorage.setItem("resultMakeMonth",makeMonth);
	localStorage.setItem("resultUserId",userId);
    let height = '98%';
    let width = '99%';
	var index = layer.open({
	    title: ['详情', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
	    type: 2,
	    content: './viewResultDetail.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,userId,makeMonth) {
	localStorage.setItem("resultId",id);
	localStorage.setItem("resultMakeMonth",makeMonth);
	localStorage.setItem("resultUserId",userId);
    let height = '98%';
    let width = '99%';
	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) {
			localStorage.setItem("resultindex",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("oneselectyj");
    window.location.href = PATH_URL + `/makeInfo/exportData?token=` + token
        + "&userName=" + userName
		+ "&proName=" + proName
		+ "&yjName=" + yjName
		+ "&makeMonth=" + makeMonth
		+ "&yjId=" + yjId
}