259 lines
7.5 KiB
Plaintext
259 lines
7.5 KiB
Plaintext
|
|
let form, laydate, id, addNum = 0, jsonObj = {}, orgList = getOrgSelect(), tId, proId;
|
||
|
|
|
||
|
|
|
||
|
|
function setParams(params) {
|
||
|
|
id = params;
|
||
|
|
if (params) {
|
||
|
|
$("#typeTitle").html("修改");
|
||
|
|
} else {
|
||
|
|
$("#typeTitle").html("新增");
|
||
|
|
}
|
||
|
|
setOrg();
|
||
|
|
layui.use(["form", "laydate", "table"], function () {
|
||
|
|
form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
|
||
|
|
table = layui.table;
|
||
|
|
laydate = layui.laydate;
|
||
|
|
laydate.render({
|
||
|
|
elem: '#years', //指定元素 元素选择器
|
||
|
|
type: 'year', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
|
||
|
|
trigger: 'click',
|
||
|
|
format: 'yyyy', //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
|
||
|
|
btns: ['clear', 'now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定
|
||
|
|
done: function (value, date) { //时间回调
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
form.on('submit(formDemo)', function (data) {
|
||
|
|
if (id) {
|
||
|
|
updateData();
|
||
|
|
} else {
|
||
|
|
saveData();
|
||
|
|
}
|
||
|
|
|
||
|
|
})
|
||
|
|
});
|
||
|
|
if (id) {
|
||
|
|
getProInfoById();
|
||
|
|
} else {
|
||
|
|
addLine();
|
||
|
|
}
|
||
|
|
layui.form.render();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 编辑页面数据
|
||
|
|
function getProInfoById() {
|
||
|
|
Ajax().post({
|
||
|
|
headers: {
|
||
|
|
"encrypt": sm3(JSON.stringify({id: id}))
|
||
|
|
},
|
||
|
|
url: dataUrl + 'proteam/pot/greenBuild/getAwardsById',
|
||
|
|
data: {id: id},
|
||
|
|
async: true,
|
||
|
|
success: function (result) {
|
||
|
|
console.log(result)
|
||
|
|
if (result.code === 200) {
|
||
|
|
setData(result.data)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 编辑页面赋值数据
|
||
|
|
function setData(data) {
|
||
|
|
$("#id").val(id);
|
||
|
|
$("#years").val(data.years);
|
||
|
|
$('#proName').val(data.proName)
|
||
|
|
$('#proCode').val(data.proCode)
|
||
|
|
$('#orgId').val(data.orgId)
|
||
|
|
let jxNameList = data.jxName.split(";");
|
||
|
|
if (jxNameList.length > 0) {
|
||
|
|
jxNameList.forEach((item, index) => {
|
||
|
|
addLine();
|
||
|
|
$('input[name="jxName"]').eq(index).val(item);
|
||
|
|
})
|
||
|
|
} else {
|
||
|
|
addLine();
|
||
|
|
}
|
||
|
|
layui.form.render();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 添加行
|
||
|
|
function addLine() {
|
||
|
|
let html = "";
|
||
|
|
addNum++;
|
||
|
|
let obj = $(".btn-box");
|
||
|
|
html +=
|
||
|
|
'<div class="layui-form-item item-' + addNum + '" itemNum="item-' + addNum + '">' +
|
||
|
|
'<div class="layui-inline" style="display: flex;align-items: center">' +
|
||
|
|
'<label class="layui-form-label"></label>' +
|
||
|
|
'<input type="text" name="jxName" style="width: 600px;" class="layui-input" lay-verify="required" autocomplete="off" maxlength="255" placeholder="请输入奖项名称">' +
|
||
|
|
'<img src="../../img/main/del.png" title="删除" style="cursor: pointer;height: 24px" onclick="delLine(this)">' +
|
||
|
|
'</div>' +
|
||
|
|
'</div>' +
|
||
|
|
'</div>';
|
||
|
|
obj.before(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() {
|
||
|
|
getProFormData();
|
||
|
|
if (jsonObj.jxName) {
|
||
|
|
requestAddOrEdit();
|
||
|
|
} else {
|
||
|
|
layer.msg('至少输入一个奖项', {icon: 2})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 修改-验证数据是否合法
|
||
|
|
function updateData() {
|
||
|
|
getProFormData();
|
||
|
|
if (jsonObj.jxName) {
|
||
|
|
requestEdit();
|
||
|
|
} else {
|
||
|
|
layer.msg('至少输入一个奖项', {icon: 2})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 工程信息/标段工程数据
|
||
|
|
function getProFormData() {
|
||
|
|
let jxNameList = [];
|
||
|
|
$('input[name="jxName"]').each(function (index) {
|
||
|
|
if ($(this).val().replace(/^\s+|\s+$/g, "")) {
|
||
|
|
jxNameList.push($(this).val());
|
||
|
|
} else {
|
||
|
|
jxNameList.push("-1");
|
||
|
|
}
|
||
|
|
});
|
||
|
|
jxNameList = jxNameList.toString().split(",").join(";");
|
||
|
|
jsonObj = {
|
||
|
|
id: $("#id").val(),
|
||
|
|
years: $("#years").val(),
|
||
|
|
orgId: $('#orgId').val(),
|
||
|
|
proName: $('#proName').val(),
|
||
|
|
proCode: $('#proCode').val(),
|
||
|
|
jxName: jxNameList
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
// 提交数据
|
||
|
|
function requestAddOrEdit() {
|
||
|
|
let loadingMsg = layer.msg("数据上传中,请稍候...", {icon: 16, scrollbar: false, time: 0});
|
||
|
|
$.ajax({
|
||
|
|
type: "post",
|
||
|
|
headers: {
|
||
|
|
"encrypt": sm3(JSON.stringify(jsonObj))
|
||
|
|
},
|
||
|
|
url: dataUrl + "proteam/pot/greenBuild/addAwards?token=" + token,
|
||
|
|
data: jsonObj,
|
||
|
|
async: false,
|
||
|
|
dataType: "json",
|
||
|
|
success: function (data) {
|
||
|
|
layer.close(loadingMsg); // 关闭提示层
|
||
|
|
if (data.code === 200) {
|
||
|
|
parent.layer.msg('新增成功', {icon: 1});
|
||
|
|
closePage();
|
||
|
|
parent.window.reloadData();
|
||
|
|
top.reloadHomeData(3);
|
||
|
|
} else if (data.code === 500) {
|
||
|
|
layer.alert(data.msg, {icon: 2})
|
||
|
|
} else if (data.code === 401) {
|
||
|
|
logout(1)
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
||
|
|
layer.close(loadingMsg);
|
||
|
|
layer.msg("数据上传发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000,});
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// 提交数据
|
||
|
|
function requestEdit() {
|
||
|
|
let loadingMsg = layer.msg("数据上传中,请稍候...", {icon: 16, scrollbar: false, time: 0});
|
||
|
|
$.ajax({
|
||
|
|
type: "post",
|
||
|
|
headers: {
|
||
|
|
"encrypt": sm3(JSON.stringify(jsonObj))
|
||
|
|
},
|
||
|
|
url: dataUrl + "proteam/pot/greenBuild/updateAwards?token=" + token,
|
||
|
|
data: jsonObj,
|
||
|
|
async: false,
|
||
|
|
dataType: "json",
|
||
|
|
success: function (data) {
|
||
|
|
if (data.code === 200) {
|
||
|
|
parent.layer.msg('修改成功', {icon: 1});
|
||
|
|
closePage();
|
||
|
|
parent.window.reloadData();
|
||
|
|
top.reloadHomeData(3);
|
||
|
|
} else if (data.code === 500) {
|
||
|
|
layer.alert(data.msg, {icon: 2})
|
||
|
|
} else if (data.code === 401) {
|
||
|
|
logout(1)
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
||
|
|
layer.close(loadingMsg);
|
||
|
|
layer.msg("数据上传发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000,});
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 格式化数量
|
||
|
|
function isRange(_that) {
|
||
|
|
let value = $(_that).val();
|
||
|
|
if (value) {
|
||
|
|
$(_that).val(parseInt(value));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 取消
|
||
|
|
function resetData() {
|
||
|
|
closePage();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 清空表单
|
||
|
|
function resetFormData() {
|
||
|
|
$(".pro-form")[0].reset();
|
||
|
|
$(".bid-form").empty();
|
||
|
|
addLine();
|
||
|
|
$("#tId").val(tId);
|
||
|
|
$("#id").val(proId);
|
||
|
|
layui.form.render();
|
||
|
|
}
|
||
|
|
|
||
|
|
/*建管单位赋值*/
|
||
|
|
function setOrg() {
|
||
|
|
let html = '<option value="">请选择</option>';
|
||
|
|
$.each(orgList, function (index, item) {
|
||
|
|
/*if(orgId === item.name){
|
||
|
|
html += '<option selected value="' + item.code + '">' + item.name + '</option>';
|
||
|
|
}else{
|
||
|
|
html += '<option value="' + item.code + '">' + item.name + '</option>';
|
||
|
|
}*/
|
||
|
|
html += '<option value="' + item.code + '">' + item.name + '</option>';
|
||
|
|
})
|
||
|
|
$('#orgId').empty().append(html);
|
||
|
|
layui.form.render();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 关闭页面
|
||
|
|
function closePage(type) {
|
||
|
|
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
||
|
|
parent.layer.close(index); //再执行关闭
|
||
|
|
}
|