126 lines
3.7 KiB
JavaScript
126 lines
3.7 KiB
JavaScript
let form, layer, formSelects, dataObj = {};
|
|
|
|
function setParams(params) {
|
|
dataObj = JSON.parse(params);
|
|
console.log(dataObj);
|
|
layui.config({
|
|
base: "../../../js/layui/", //此处路径请自行处理, 可以使用绝对路径
|
|
}).extend({
|
|
formSelects: 'formSelects-v4',
|
|
}).use(['form', 'layer', 'formSelects'], function () {
|
|
layer = layui.layer;
|
|
form = layui.form;
|
|
formSelects = layui.formSelects;
|
|
form.render();
|
|
if (dataObj.type === 1 || dataObj.type === 2) {
|
|
$('#setChildData').remove();
|
|
$('#enterpriseName').removeAttr('style');
|
|
} else {
|
|
$('#enterpriseName').remove();
|
|
$('#setChildData').removeAttr('style');
|
|
setUnits();
|
|
getBandUnit(dataObj.enterpriseId);
|
|
}
|
|
if (dataObj.type === 2) {
|
|
form.val('formInfo', dataObj);
|
|
}
|
|
form.on('submit(formData)', function (data) {
|
|
submitApply(data);
|
|
});
|
|
});
|
|
}
|
|
|
|
// 施工单位
|
|
function setUnits() {
|
|
let orgList = [];
|
|
let url = dataUrl + 'proteam/pot/todayTask/getSgdwList';
|
|
ajaxRequest2(url, "POST", {}, false, function (result) {
|
|
console.log(result);
|
|
|
|
if (result.code === 200) {
|
|
orgList = result.data;
|
|
} else {
|
|
layer.msg(result.msg, { icon: 2 })
|
|
}
|
|
}, function (xhr) {
|
|
error(xhr)
|
|
}, null, token);
|
|
let keys = [];
|
|
$.each(orgList, function (index, item) {
|
|
let temp = {
|
|
name: item.unit_name,
|
|
value: item.id,
|
|
};
|
|
keys.push(temp);
|
|
})
|
|
formSelects.data('unitCode', 'local', {
|
|
arr: keys
|
|
});
|
|
layui.form.render();
|
|
}
|
|
|
|
// 获取绑定施工单位
|
|
function getBandUnit(id){
|
|
let url = dataUrl + 'proteam/pot/collectiveEnterprise/getData';
|
|
ajaxRequest2(url, "POST", {enterpriseId:id}, false, function (result) {
|
|
console.log(result);
|
|
if (result.code === 200) {
|
|
value = result.data;
|
|
if(value){
|
|
formSelects.value('unitCode',value.split(','));
|
|
}
|
|
} else {
|
|
layer.msg(result.msg, { icon: 2 })
|
|
}
|
|
}, function (xhr) {
|
|
error(xhr)
|
|
}, null, token);
|
|
}
|
|
|
|
// 提交
|
|
function submitApply(data) {
|
|
let loadingMsg = layer.msg('正在提交保存,请稍等...', { icon: 16, shade: 0.01, time: '0' });
|
|
let params = {};
|
|
let url =null;
|
|
//let url = dataUrl + "proteam/pot/collectiveEnterprise/addOrUpdateData";
|
|
url = dataUrl + "proteam/pot/collectiveEnterprise/addOrUpdateCollectiveEnterprise";
|
|
params = Object.assign({}, data.field);
|
|
if (dataObj.type === 2) { // 修改
|
|
params.enterpriseId = dataObj.enterpriseId;
|
|
} else if (dataObj.type === 3) { // 配置施工单位
|
|
url = dataUrl + "proteam/pot/collectiveEnterprise/addOrUpdateData";
|
|
let units = formSelects.value('unitCode', 'val');
|
|
params.enterpriseId = dataObj.enterpriseId;
|
|
params.unitId = units.toString();
|
|
}
|
|
console.log(params);
|
|
ajaxRequest2(url, "POST", params, true, function (result) {
|
|
layer.close(loadingMsg); // 关闭提示层
|
|
console.log(result);
|
|
if (result.code === 200) {
|
|
top.layer.msg(result.msg, { icon: 1 })
|
|
closePage(1);
|
|
} else {
|
|
layer.msg(result.msg, { icon: 2 })
|
|
}
|
|
}, function (xhr) {
|
|
layer.close(loadingMsg); // 关闭提示层
|
|
error(xhr)
|
|
}, null, token);
|
|
}
|
|
|
|
|
|
// 保存
|
|
function saveData2() {
|
|
$('#formSubmit').trigger('click')
|
|
}
|
|
|
|
// 关闭页面
|
|
function closePage(type) {
|
|
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
|
parent.layer.close(index); //再执行关闭
|
|
if (type === 1) {
|
|
parent.query(1);
|
|
}
|
|
}
|