let  layer,laypage,table,form,element;

layui.use(['element', 'layer', 'form', 'element','laypage'], function(){
	layer = layui.layer; //弹层
	element = layui.element; //分页
	laypage = layui.laypage; //分页
	table = layui.table; //表格
	form=layui.form;
	init()
})
//初始化云间公司
function init(){
	
	
	$.ajax({
		type: 'POST',
		url: PATH_URL + '/homePageSelect/getSubCom', // 请求地址
		contentType: "application/json; charset=utf-8",
		async: false,
		data: {}, //获取提交的表单字段
		success: function (data) {
			if(data.code == 200){
				let html = '';
				let resultObj = data.data;
				
				for (let i = 0; i < resultObj.length; i++) {
					if(i==0){
						localStorage.getItem("selectSubCom",resultObj[i].id);
					}
					html += `<option value="${resultObj[i].id}" style="color: #757575 !important;font-weight: 400 !important;">${resultObj[i].name}</option>`;
				}
				$("#subComId").html(html);
			}else{
				$("#subComId").html('<option value="">--无数据--</option>');
			}
			layui.form.render();
			
			//下拉选监听
			form.on('select(yjSelect)', function(data){
				console.log(data)
				localStorage.setItem("selectSubCom",data.value);
				var iframe = $("#indexFrame")[0];
				var iframeWindow = iframe.contentWindow;
				iframeWindow.initStation();
				iframeWindow.setData();
				
				var viewPlanFrame = $("#viewPlanFrame")[0];
				var viewPlanWindow = viewPlanFrame.contentWindow;
				viewPlanWindow.init();
				
				var staffFrame = $("#staffFrame")[0];
				var staffWindow = staffFrame.contentWindow;
				staffWindow.init();
				
				var viewStatisticsFrame = $("#viewStatisticsFrame")[0];
				var viewStatisticsWindow = viewStatisticsFrame.contentWindow;
				viewStatisticsWindow.init();
				
				var workVisaFrame = $("#workVisaFrame")[0];
				var workVisaWindow = workVisaFrame.contentWindow;
				workVisaWindow.init();
				
				var specialPatrolFrame = $("#specialPatrolFrame")[0];
				var specialPatrolWindow = specialPatrolFrame.contentWindow;
				specialPatrolWindow.init();
				
				var wagesStatisticsFrame = $("#wagesStatisticsFrame")[0];
				var wagesStatisticsWindow = wagesStatisticsFrame.contentWindow;
				wagesStatisticsWindow.init();
				
			});
		},
		error: function (XMLHttpRequest, textStatus, e) {
			layer.msg('数据请求发生异常,请稍后重试', {icon: 16, scrollbar: false});
			top.layer.close(addLoadingMsg); //再执行关闭
		}
	});
}

