let form, laydate, id, addNum = 0, jsonObj = {},tId,proId; function setParams(params) { id = params; if (params) { $("#typeTitle").html("编辑"); } else { $("#typeTitle").html("新增"); } layui.use(["form", "laydate", "table"], function () { form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功 table = layui.table; laydate = layui.laydate; let startDate = laydate.render({ elem: "#planStartTime", type: "datetime", format: "yyyy-MM-dd HH:mm:ss", btns: ["clear", "confirm"], done: function (value, date) { if (value !== "") { endDate.config.min.year = date.year; endDate.config.min.month = date.month - 1; endDate.config.min.date = date.date; endDate.config.min.hours = date.hours; endDate.config.min.minutes = date.minutes; } else { endDate.config.min.year = ""; endDate.config.min.month = ""; endDate.config.min.date = ""; endDate.config.min.hours = ""; endDate.config.min.minutes = ""; } }, }); let endDate = laydate.render({ elem: "#planEndTime", type: "datetime", format: "yyyy-MM-dd HH:mm:ss", btns: ["clear", "confirm"], done: function (value, date) { if (value !== "") { startDate.config.max.year = date.year; startDate.config.max.month = date.month - 1; startDate.config.max.date = date.date; startDate.config.max.hours = date.hours; startDate.config.max.minutes = date.minutes; } else { startDate.config.max.year = ""; startDate.config.max.month = ""; startDate.config.max.date = ""; startDate.config.max.hours = ""; startDate.config.max.minutes = ""; } }, }); let startDate2 = laydate.render({ elem: "#startTime", type: "datetime", format: "yyyy-MM-dd HH:mm:ss", btns: ["clear", "confirm"], done: function (value, date) { if (value !== "") { endDate2.config.min.year = date.year; endDate2.config.min.month = date.month - 1; endDate2.config.min.date = date.date; endDate2.config.min.hours = date.hours; endDate2.config.min.minutes = date.minutes; } else { endDate2.config.min.year = ""; endDate2.config.min.month = ""; endDate2.config.min.date = ""; endDate2.config.min.hours = ""; endDate2.config.min.minutes = ""; } }, }); let endDate2 = laydate.render({ elem: "#endTime", type: "datetime", format: "yyyy-MM-dd HH:mm:ss", btns: ["clear", "confirm"], done: function (value, date) { if (value !== "") { startDate2.config.max.year = date.year; startDate2.config.max.month = date.month - 1; startDate2.config.max.date = date.date; startDate2.config.max.hours = date.hours; startDate2.config.max.minutes = date.minutes; } else { startDate2.config.max.year = ""; startDate2.config.max.month = ""; startDate2.config.max.date = ""; startDate2.config.max.hours = ""; startDate2.config.max.minutes = ""; } }, }); }); loadOrgName(); getVoltegeLevelList(); if (id) { getProInfoById(); } else { addLine(); } // addLine(); layui.form.render(); } // 编辑页面数据 function getProInfoById() { $.ajax({ type: "GET", url: dataUrl + "newPro/getProInfoById?token=" + token, data: { params: encrypt(JSON.stringify({ 'id': id })), }, async: false, dataType: "json", success: function (data) { console.log(data); setData(data.obj); }, error: function (jqXHR, textStatus, errorThrown) { }, }); } // 编辑页面赋值数据 function setData(data) { if (data.newProEntity) { tId = data.newProEntity.tid; proId = data.newProEntity.id; $("#tId").val(data.newProEntity.tid); $("#id").val(data.newProEntity.id).addClass('readonly').attr('readonly',true); $("#proName").val(data.newProEntity.proName); $("#proAbbName").val(data.newProEntity.proAbbName); $("#proType").val(data.newProEntity.proType); $("#volate").val(data.newProEntity.volate); $("#cityCompany").val(data.newProEntity.orgId); $("#workUnit").val(data.newProEntity.workUnit); $("#countUnit").val(data.newProEntity.countUnit); $("#lon").val(data.newProEntity.lon); $("#lat").val(data.newProEntity.lat); $("input:radio[name=isStop][value="+ data.newProEntity.isStop +"]").attr("checked", "true"); $("#cotrUnitManage").val(data.newProEntity.cotrUnitManage); $("#cotrUnitManageTel").val(data.newProEntity.cotrUnitManageTel); $("#owerManager").val(data.newProEntity.owerManager); $("#owerManagerTel").val(data.newProEntity.owerManagerTel); $("#consManage").val(data.newProEntity.consManage); $("#consManageTel").val(data.newProEntity.consManageTel); $("#planStartTime").val(data.newProEntity.planStartTime); $("#planEndTime").val(data.newProEntity.planEndTime); $("#startTime").val(data.newProEntity.startTime); $("#endTime").val(data.newProEntity.endTime); $("#status").val(data.newProEntity.status); $("#progess").val(data.newProEntity.progess); } if(data.newProBidLists && data.newProBidLists.length > 0){ debugger; data.newProBidLists.forEach((item,index)=>{ addLine(); $('.bid-num').eq(index).attr('id',item.id); $('input[name="proCode"]').eq(index).val(item.proCode); $('input[name="singName"]').eq(index).val(item.singName); $('input[name="bidCode"]').eq(index).val(item.bidCode); $('input[name="bidName"]').eq(index).val(item.bidName); $('input[name="towerNum"]').eq(index).val(item.towerNum); }) }else{ addLine(); } layui.form.render(); } // 添加行 function addLine() { let html = ""; addNum++; let length = $(".bid-form > .layui-form-item").length; let obj = $(".bid-form"); html += '
' + '
' +(length + 1) +"
" + '
' + '
' + '

' + '
' + '

' + '
' + '

' + '
' + '

' + '
' + '

' + '
' + '' + '
' + ''; obj.append(html); } // 删除行 function delLine(_that) { let obj = $(".bid-form > .layui-form-item"); let classId = $(_that).parents(".layui-form-item").attr("itemNum"); obj.remove("." + classId); let length = $(".bid-form > .layui-form-item").length; let obj2 = $(".bid-form > .layui-form-item"); if (length) { obj2.each(function (index) { $(this).find(".bid-num").html(index + 1); }); } } // 保存-验证数据是否合法 function saveData() { let flag = volidateForm(); if (flag) { console.log("上传"); getProFormData(); console.log(JSON.stringify(jsonObj)); requestAddOrEdit(); } else { console.log("不上传"); } } // 工程信息/标段工程数据 function getProFormData() { let proCodeList = [], singNameList = [], bidCodeList = [], bidNameList = [], towerNumList = [], bidIdList = []; $('input[name="proCode"]').each(function (index) { if ($(this).val().replace(/^\s+|\s+$/g, "")) { proCodeList.push($(this).val()); } else { proCodeList.push("-1"); } }); $('input[name="singName"]').each(function (index) { if ($(this).val().replace(/^\s+|\s+$/g, "")) { singNameList.push($(this).val()); } else { singNameList.push("-1"); } }); $('input[name="bidCode"]').each(function (index) { if ($(this).val().replace(/^\s+|\s+$/g, "")) { bidCodeList.push($(this).val()); } else { bidCodeList.push("-1"); } }); $('input[name="bidName"]').each(function (index) { if ($(this).val().replace(/^\s+|\s+$/g, "")) { bidNameList.push($(this).val()); } else { bidNameList.push("-1"); } }); $('input[name="towerNum"]').each(function (index) { if ($(this).val().replace(/^\s+|\s+$/g, "")) { towerNumList.push($(this).val()); } else { towerNumList.push("-1"); } }); $(".bid-num").each(function (index) { if ($(this).attr("id")) { bidIdList.push($(this).attr("id")); } else { bidIdList.push("-1"); } }); jsonObj = { tId: $("#tId").val(), id: $("#id").val(), proName: $("#proName").val(), proAbbName: $("#proAbbName").val(), proType: $("#proType").val(), volate: $("#volate").val(), orgId: $("#cityCompany").val(), workUnit: $("#workUnit").val(), countUnit: $("#countUnit").val(), lon: $("#lon").val(), lat: $("#lat").val(), isStop: $("input[name='isStop']:checked").val(), cotrUnitManage: $("#cotrUnitManage").val(), cotrUnitManageTel: $("#cotrUnitManageTel").val(), owerManager: $("#owerManager").val(), owerManagerTel: $("#owerManagerTel").val(), consManage: $("#consManage").val(), consManageTel: $("#consManageTel").val(), planStartTime: $("#planStartTime").val(), planEndTime: $("#planEndTime").val(), startTime: $("#startTime").val(), endTime: $("#endTime").val(), status: $("#status").val(), progess: $("#progess").val(), proCodeList: proCodeList.toString(), singNameList: singNameList.toString(), bidCodeList: bidCodeList.toString(), bidNameList: bidNameList.toString(), towerNumList: towerNumList.toString(), bidIdList: bidIdList.toString(), }; } // 提交数据 function requestAddOrEdit() { let loadingMsg = layer.msg("数据上传中,请稍候...", { icon: 16, scrollbar: false, time: 0 }); $.ajax({ type: "post", url: dataUrl + "newPro/addOrUpdatePro?token=" + token, data: { params: encrypt(JSON.stringify(jsonObj)), }, async: false, dataType: "json", success: function (data) { layer.close(loadingMsg); // 关闭提示层 if (data.resMsg === "保存成功") { closePage(1, data.resMsg); } else { doneConfirm(data.resMsg); } }, error: function (jqXHR, textStatus, errorThrown) { layer.close(loadingMsg); layer.msg("数据上传发生异常,请稍后重试", { icon: 16, scrollbar: false, time: 2000, }); }, }); } // 加载地市公司 function loadOrgName() { let html = ""; $.ajax({ type: "POST", url: dataUrl + "map/getOrgName?token=" + token, data: { data: getDefatData() }, async: false, dataType: "json", success: function (data) { if (data && data.length > 0) { data.forEach((item) => { html += ""; }); } }, }); $("#cityCompany").empty().append(html); } //加载电压等级 function getVoltegeLevelList() { let html = ""; $.ajax({ type: "GET", url: dataUrl + "map/getVoltegeLevelList?token=" + token, async: false, dataType: "json", success: function (data) { let obj = data.obj; if (obj && obj.length > 0) { obj.forEach((item) => { html += ""; }); } }, }); $("#volate").empty().append(html); } // 格式化数量 function isRange(_that) { let value = $(_that).val(); if (value) { $(_that).val(parseInt(value)); } } // 重置 function resetData() { resetForm(); resetFormData(); jsonObj = {}; } // 清空表单 function resetFormData() { $(".pro-form")[0].reset(); $(".bid-form").empty(); addLine(); $("#tId").val(tId); $("#id").val(proId); layui.form.render(); } // 关闭页面 function closePage(type) { let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引 parent.layer.close(index); //再执行关闭 if (type === 1) { let frameId = parent.document.getElementById('proMge').getElementsByTagName("iframe")[0]; frameId.contentWindow.reloadData(1); } } // 请求--回调 function doneConfirm(status) { let path = "../../../img/fail-circle.png"; let height = getConfirmHeight().toFixed(0) + "px"; let width = getComfrimWidth().toFixed(0) + "px"; let html = '
' + '
' + '' + '

' + status + "

" + "
" + "
"; layer.open({ type: 1, time: 2000, title: false, closeBtn: 0, //不显示关闭按钮 shadeClose: false, //开启遮罩关闭 content: html, area: [width, height], success: function (layero, index) { // 浏览器分辨率发生变化时,自适应 $(window).resize(function () { if (autoComfrimResizeWidth) { autoComfrimResizeWidth(index); } if (autoConfrimResizeHeight) { autoConfrimResizeHeight(index); } }); }, }); }