var layer;
var parentData;
var parentProId;
layui.use(['layer', 'form'], function () {
    var form = layui.form;
    layer = layui.layer;


 

    $("#closeBt").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
        parent.layer.close(index); //再执行关闭
    });

    // 验证成功后才会执行下面的操作
    form.on('submit(formDemo)', function (data) {
		updData(data); // 新增
    });
});
 
 function setData(data, proId){
	 parentData = data;
	 parentProId = proId;
	 
	 $("#gtName").val(parentData[0].gtName);
 }


/**
 * 新增
 * @param formData
 */
function updData(formData) {
	if(parentData[0].gtName === $("#gtName").val()){
		layer.msg("您想要修改的杆塔名称与原名称一致，无法修改!", { icon: 0, time: 3000 });
		$("#gtName").focus();
		return;
	}
	
	
	// 加载提示
	let loadingMsg = layer.msg('数据上传中,请稍候...', {icon: 16, scrollbar: false, time: 0, shade: [0.8, '#393D49']});
	
	formData.field.gtId = parentData[0].gtId;
	formData.field.proId = parentProId;
	
	// form请求地址
	let formUrl = PATH_URL + "/lineProject/updatePower";
	$.ajax({
		type: 'POST',
		url: formUrl, // 请求地址
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(formData.field),
		success: function (data) {
			layer.close(loadingMsg); // 关闭提示层
			if(data.code == 200){
				parent.layer.msg("修改成功", { icon: 1 });
				var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
				parent.layer.close(index); //再执行关闭
				// reloading();
			}else{
				layer.alert(data.msg);
			}
		},
		error: function (XMLHttpRequest, textStatus, e) {
			layer.close(loadingMsg);
			layer.msg('数据请求发生异常,请稍后重试', {icon: 16, scrollbar: false});
		}
	});
}






/**
 * 关闭页面 刷新页面
 */
function reloading() {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
    parent.layer.close(index); //再执行关闭
    window.parent.location.reload();
}