358 lines
12 KiB
Plaintext
358 lines
12 KiB
Plaintext
let form, layer, idParam, warnInfoParam, num = 0, isDel = '0';
|
||
let delRemarkList = [], warnInfoList = [], addRemarkList = [], oldRemarkList = [], delRemarkList2 = [],
|
||
mergeRemarkList = [];
|
||
|
||
function setParams(id, warnInfo) {
|
||
idParam = id;
|
||
layui.use(['form', 'layer'], function () {
|
||
layer = layui.layer;
|
||
form = layui.form;
|
||
form.render();
|
||
getWarnInfoByClassId();
|
||
});
|
||
}
|
||
|
||
layui.use(['form', 'layer', 'table'], function () {
|
||
$ = layui.jquery;
|
||
var layer = layui.layer,
|
||
form = layui.form;
|
||
form.on('checkbox(checkbox)', function (data) {
|
||
let checkbox=false;
|
||
if( data.elem.checked){
|
||
checkbox=true; //确定
|
||
}else{//取消了
|
||
checkbox=false;
|
||
}
|
||
var value = data.value; //获取选中的value值
|
||
// updeWarnConfirm(value,checkbox);
|
||
});
|
||
|
||
|
||
|
||
})
|
||
//
|
||
function updeWarnConfirm(value,confirm){
|
||
console.log(idParam);
|
||
console.log(value,confirm);
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify({
|
||
classId: idParam,
|
||
num:value,
|
||
confirm:confirm
|
||
}))
|
||
},
|
||
url: dataUrl + 'proteam/pot/todayTask/updeWarnConfirm?token=' + token,
|
||
data: {
|
||
classId: idParam,
|
||
num:value,
|
||
confirm:confirm
|
||
},
|
||
type: 'POST',
|
||
async: false,
|
||
success: function (result) {
|
||
|
||
}, error: function () {
|
||
layer.close(loadingMsg);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
|
||
function getWarnInfoByClassId() {
|
||
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify({
|
||
classId: idParam
|
||
}))
|
||
},
|
||
url: dataUrl + 'proteam/pot/todayTask/getWarnInfo?token=' + token,
|
||
data: {
|
||
classId: idParam,
|
||
},
|
||
type: 'POST',
|
||
async: false,
|
||
success: function (result) {
|
||
layer.close(loadingMsg);
|
||
console.error(result)
|
||
if (result.data) {
|
||
if (result.data.curWarnList.length > 0) {
|
||
$.each(result.data.curWarnList, function (index, item) {
|
||
let value = item.trim().substring(item.trim().lastIndexOf('@') + 1, item.trim().length)
|
||
if (value) {
|
||
addLine(2, item);
|
||
} else {
|
||
addLine(1, item);
|
||
}
|
||
})
|
||
}
|
||
if (result.data.delWarnList.length > 0) {
|
||
$.each(result.data.delWarnList, function (index, item) {
|
||
addDelLine(item);
|
||
})
|
||
} else {
|
||
$('.del-form').append('<p style="text-align: center;padding: 210px 0;font-size: 16px;">无预警信息删除数据</p>');
|
||
}
|
||
}
|
||
}, error: function () {
|
||
layer.close(loadingMsg);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 新增一行 1.原有 2.新增-入库 3.新增
|
||
function addLine(type, item) {
|
||
num++;
|
||
let html = '', warnInfo = '', remark = '', color = '#fff' ,checkbox=false;
|
||
|
||
if (item) {
|
||
var items= item.split("@");
|
||
if(items.length>1){
|
||
checkbox=true;
|
||
}
|
||
warnInfo =items[0];
|
||
//remark = item.split("@")[1];
|
||
color = '#eee';
|
||
}
|
||
let checkHtml="";
|
||
if(checkbox){
|
||
checkHtml= '<input type="checkbox" lay-filter="checkbox" checked="true" name="checkbox" value='+num+' title="确定">';
|
||
}else{
|
||
checkHtml= '<input type="checkbox" lay-filter="checkbox" name="checkbox" value='+num+' title="确定">';
|
||
}
|
||
|
||
html += '<div class="layui-form-item" isAdd = "' + type + '" num="' + num + '" >' +
|
||
'<div class="layui-inline">' +
|
||
'<div class="layui-input-inline layout">' +
|
||
'<input class="layui-input input' + num + '" name="warnInfo" maxlength="200" autocomplete="off" placeholder="请填写预警信息" value="' + warnInfo + '" style="background-color: ' + color + ';">' +
|
||
'<span style="margin: 0 5px;">-</span>' +
|
||
// '<textarea class="layui-textarea textarea' + num + '" name="remark" maxlength="500" autocomplete="off" placeholder="备注" style="background-color: ' + color + ';">' + remark + '</textarea>' +
|
||
checkHtml+
|
||
'<img src="../../../img/remotePatrol/del.png" title="删除" onclick="delLine(this)">' +
|
||
|
||
'</div>' +
|
||
'</div>' +
|
||
'</div>';
|
||
$('.add-form').append(html);
|
||
layui.form.render();
|
||
if (item && (type === 1 || type === 2)) {
|
||
$('.input' + num + '').prop('readonly', true)
|
||
$('.textarea' + num + '').prop('readonly', true)
|
||
}
|
||
}
|
||
|
||
// 预警信息-删除
|
||
function addDelLine(item) {
|
||
let html = '', warnInfo = '', remark = '';
|
||
if (item) {
|
||
warnInfo = item.split("@")[0];
|
||
remark = item.split("@")[1];
|
||
}
|
||
html += '<div class="layui-form-item">' +
|
||
'<div class="layui-inline">' +
|
||
'<div class="layui-input-inline layout">' +
|
||
'<input class="layui-input" readonly name="warnInfo2" value="' + warnInfo + '" style="background-color: #eee;">' +
|
||
'<span style="margin: 0 5px;">-</span>' +
|
||
'<textarea class="layui-textarea" name="remark2" readonly style="background-color: #eee;" >' + remark + '</textarea>' +
|
||
'</div>' +
|
||
'</div>' +
|
||
'</div>';
|
||
$('.del-form').append(html);
|
||
}
|
||
|
||
// 删除一行
|
||
function delLine(that) {
|
||
let remark = $(that).prev().val();
|
||
let warnInfo = $(that).prev().prev().prev().prev().val();
|
||
let isAdd = $(that).parents('.layui-form-item').attr('isAdd');
|
||
if(isAdd === '1' || isAdd === '2'){
|
||
let index = layer.open({
|
||
title: ['<div style="border-left: 3px solid #2F82FB;display: flex;align-items: center;height: 20px;padding: 0 10px;">删除备注填写</div>', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'],
|
||
type: 1,
|
||
maxmin: false,
|
||
shade: 0.1,
|
||
shadeClose: false,
|
||
content: addContent(warnInfo),
|
||
area: ["450px", "230px"],
|
||
move: false,
|
||
success: function (layero, index) {
|
||
layui.form.render();
|
||
}, end: function () {
|
||
if (isDel === '1') {
|
||
$(that).parents('.layui-form-item').remove()
|
||
isDel = '0'
|
||
}
|
||
}
|
||
});
|
||
}else{
|
||
$(that).parents('.layui-form-item').remove()
|
||
}
|
||
|
||
}
|
||
|
||
function addContent(warnInfo) {
|
||
console.log(warnInfo)
|
||
let html = '<div class="add-form layui-form" style="padding-top: 3%">' +
|
||
'<form class="layui-form" action="#" onsubmit="return false;">' +
|
||
'<div class="layui-form-item" style="margin-left: 5%;">' +
|
||
'<label class="layui-form-label">备注</label>' +
|
||
'<div class="layui-inline" style="width: 255px;">' +
|
||
'<textarea class="layui-textarea" id="delRemark" maxlength="500">' +
|
||
'</textarea>' +
|
||
'</div>' +
|
||
'</div>' +
|
||
'<div class="layui-form-item" style="padding-left: 0%;margin-top: 8%;margin-left: 35%;justify-content: center;">' +
|
||
'<button type="button" class="layui-btn layui-btn-normal" id="save" onclick="saveRemark(\'' + warnInfo + '\')">确定</button>' +
|
||
'<button type="button" class="layui-btn layui-btn-primary" id="cancel" onclick="layer.closeAll()">取消</button>' +
|
||
'</div>' +
|
||
'</form>' +
|
||
'</div>';
|
||
layui.form.render();
|
||
return html;
|
||
}
|
||
|
||
function saveRemark(warnInfo) {
|
||
let delRemark = $('#delRemark').val()
|
||
if (!delRemark.trim()) {
|
||
return layer.msg('删除预警信息,请填写备注', {icon: 7});
|
||
} else {
|
||
delRemarkList.push('2@' + warnInfo + '@' + delRemark)
|
||
isDel = '1'
|
||
}
|
||
layer.closeAll();
|
||
}
|
||
|
||
function isRepeat(arr) {
|
||
let hash = {};
|
||
for (let i in arr) {
|
||
if (hash[arr[i]]) {
|
||
return true
|
||
}
|
||
hash[arr[i]] = true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 提交数据
|
||
function saveData(data) {
|
||
var checkList=[];
|
||
warnInfoList.splice(0, warnInfoList.length);
|
||
addRemarkList.splice(0, addRemarkList.length);
|
||
oldRemarkList.splice(0, oldRemarkList.length);
|
||
delRemarkList2.splice(0, delRemarkList2.length);
|
||
mergeRemarkList.splice(0, mergeRemarkList.length);
|
||
let flag = false, flag2 = false, flag3 = false;
|
||
$('input[name="warnInfo"]').each(function () {
|
||
if (!$(this).val().trim()) {
|
||
flag = true;
|
||
} else {
|
||
warnInfoList.push($(this).val().trim())
|
||
}
|
||
})
|
||
$('input[name="checkbox"]:checked').each(function (e) {
|
||
checkList.push($(this).val());
|
||
})
|
||
$('textarea[name="remark"]').each(function () {
|
||
if ($(this).parents('.layui-form-item').attr('isAdd') === '3') {
|
||
if (!$(this).val().trim()) {
|
||
flag2 = true;
|
||
} else {
|
||
addRemarkList.push('1@' + $(this).prev().prev().val().trim() + "@" + $(this).val().trim())
|
||
}
|
||
} else if ($(this).parents('.layui-form-item').attr('isAdd') === '2') {
|
||
if ($(this).val().trim()) {
|
||
oldRemarkList.push('1@' + $(this).prev().prev().val().trim() + "@" + $(this).val().trim())
|
||
}
|
||
}
|
||
})
|
||
$('input[name="warnInfo2"]').each(function () {
|
||
delRemarkList2.push('2@' + $(this).val() + '@' + $(this).next().next().val())
|
||
})
|
||
flag3 = isRepeat(warnInfoList);
|
||
if (flag) {
|
||
return layer.msg('存在未填写的预警信息', {icon: 7});
|
||
}
|
||
if (flag2) {
|
||
return layer.msg('新增的预警信息存在未填写的备注', {icon: 7});
|
||
}
|
||
if (flag3) {
|
||
return layer.msg('预警信息存在相同数据', {icon: 7});
|
||
}
|
||
if (addRemarkList.length > 0) {
|
||
addRemarkList.forEach(function (item, index) {
|
||
mergeRemarkList.push(item)
|
||
})
|
||
}
|
||
if (delRemarkList.length > 0) {
|
||
delRemarkList.forEach(function (item, index) {
|
||
mergeRemarkList.push(item)
|
||
})
|
||
}
|
||
if (oldRemarkList.length > 0) {
|
||
oldRemarkList.forEach(function (item, index) {
|
||
mergeRemarkList.push(item)
|
||
})
|
||
}
|
||
if (delRemarkList2.length > 0) {
|
||
delRemarkList2.forEach(function (item, index) {
|
||
mergeRemarkList.push(item)
|
||
})
|
||
}
|
||
checkListStr=checkList.join("@")+"@";
|
||
for (var i = 0; i < warnInfoList.length; i++) {
|
||
var j=i+1+"@";
|
||
if(checkListStr.indexOf(j)!='-1'){
|
||
warnInfoList[i]=warnInfoList[i]+"@1";
|
||
}
|
||
}
|
||
let formData = {
|
||
classId: idParam,
|
||
warnType: warnInfoList.toString(),
|
||
remark: mergeRemarkList.toString()
|
||
};
|
||
// 加载提示
|
||
let loadingMsg = layer.msg('数据提交中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
||
$.ajax({
|
||
url: dataUrl + 'proteam/pot/todayTask/updateWarnInfoByClassId?token=' + token,
|
||
type: 'POST',
|
||
data: formData,
|
||
dataType: 'json',
|
||
beforeSend: function () {
|
||
$('.save').addClass("layui-btn-disabled").attr("disabled", true);
|
||
$('.cancel').addClass("layui-btn-disabled").attr("disabled", true);
|
||
},
|
||
success: function (result) {
|
||
console.log(result);
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
if (result.code === 200) {
|
||
closePage(1);
|
||
parent.layer.msg(result.msg, {icon: 1});
|
||
} else {
|
||
layer.msg(result.msg, {icon: 5});
|
||
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
|
||
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
|
||
}
|
||
},
|
||
error: function (result) {
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
layer.msg('数据上传发生异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000});
|
||
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
|
||
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 关闭页面
|
||
function closePage(type) {
|
||
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
||
parent.layer.close(index); //再执行关闭
|
||
if (type === 1) {
|
||
let frameId = parent.document.getElementById('remotePatrol').getElementsByTagName("iframe")[0];
|
||
frameId.contentWindow.reloadWarnInfo();
|
||
}
|
||
}
|
||
|
||
|