hn_cloud_web/smz-web/js/work/smallSubManagement/periodAdjustForm.js

111 lines
4.2 KiB
JavaScript
Raw Normal View History

2025-11-27 16:55:35 +08:00
var example = null;
var pers = null;
var form,laydate = null;
var lumpSumContractId = "";
function periodAdjustDetail(id){
lumpSumContractId = id;
layui.use(['layer', 'laydate', 'form'], function () {
form = layui.form;
form.render();
form.verify();
pers = checkPermission();
laydate = layui.laydate;
laydate.render({
elem: '#planStartTime' //指定元素 元素选择器
, type: 'date' //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
, trigger: 'click'
, format: 'yyyy-MM-dd' //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
// , value: new Date() //初始值 今天
, btns: ['clear', 'now', 'confirm'] //选择框右下角显示的按钮 清除-现在-确定
, done: function (value, date) {//时间回调
}
});
laydate.render({
elem: '#planEndTime' //指定元素 元素选择器
, type: 'date' //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
, trigger: 'click'
, format: 'yyyy-MM-dd' //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
// , value: new Date() //初始值 今天
, btns: ['clear', 'now', 'confirm'] //选择框右下角显示的按钮 清除-现在-确定
, done: function (value, date) {//时间回调
}
});
init(id);
form.on('submit(formDemo)', function (data) {
var startTime = $("#planStartTime").val();
var endTime = $("#planEndTime").val();
if (startTime && endTime && startTime > endTime) {
layer.msg("开始时间不能大于结束时间", { icon: 2 });
return false;
}
// 构造最终对象
const submitData = {
id: lumpSumContractId, // 转换为整数
type: "3",
planStartTime: $("#planStartTime").val(),
planEndTime: $("#planEndTime").val()
};
// 提交到后端
$.ajax({
2025-12-09 18:44:29 +08:00
url: smz_ht_url + "/teamSmallBagDryTreaty/operContract", // 替换为你的实际接口
2025-11-27 16:55:35 +08:00
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(submitData),
success: function (res) {
if (res.res === 1) {
layer.msg("保存成功", { icon: 1, time: 2000 });
setTimeout("reloading()", 2001);
} else {
layer.msg(res.resMsg || "保存失败", { icon: 2, time: 2000 });
}
},
error: function (xhr, status, error) {
console.error("保存失败:", error);
layer.msg("网络错误,请重试", { icon: 5, time: 2000 });
}
});
return false; // 阻止表单刷新页面
});
});
}
function init(id) {
$.ajax({
type: 'get',
contentType: "application/x-www-form-urlencoded",
2025-12-09 18:44:29 +08:00
url: smz_ht_url + '/teamSmallBagDryTreaty/getDataDetail',
2025-11-27 16:55:35 +08:00
data: {"contractId":id},
dataType: 'json',
success: function (data) {
if (data.res === 1){
var planStartTime = data.obj.planStartTime;
var planEndTime = data.obj.planEndTime;
// 替换 \n\t 转义字符为真实换行符 \n
$("#planStartTime").val(planStartTime);
$("#planEndTime").val(planEndTime);
layui.form.render();
}else{
layer.msg("未查询到", { icon: 2, time: 2000 });
}
},
error: function (xhr, status, error) {
console.error("请求失败:", error);
layer.msg("网络异常,请重试", { icon: 5, time: 2000 });
}
})
}
function reloading() {
var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
window.parent.location.reload();
}