代码优化

This commit is contained in:
BianLzhaoMin 2025-02-19 16:19:26 +08:00
parent bedfe05015
commit c0269c0f03
2 changed files with 310 additions and 277 deletions

View File

@ -157,17 +157,47 @@
}
} else {
if (cellData.field === 'examineAndApprove') {
cellData.templet = function (d) {
//如果d.isApprove == 1 去除当前行的编辑功能
// let text = "";
// if (d.isTwoApprove == 1) {
// text += '<a style="color: #009688;cursor: pointer;font-size: 15px"' +
// ' id="pass">已通过</a>';
// }
// if (d.isTwoApprove == 2) {
// text += '<a style="color: #a59e9e;cursor: pointer;font-size: 15px"' +
// ' id="reject">已驳回</a>';
// }
// text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
// ' id="pass">通过</a>';
// text +=
// '<a lay-event="reject" style="color: #a59e9e;cursor: pointer;font-size: 15px;margin-left: 10px"' +
// ' id="reject">驳回</a>';
// return text;
let text = "";
if (d.isTwoApprove == 1) {
text += '<a style="color: #009688;cursor: pointer;font-size: 15px"' +
' id="pass">已通过</a>';
}
if (d.isTwoApprove == 2) {
text += '<a style="color: #a59e9e;cursor: pointer;font-size: 15px"' +
' id="reject">已驳回</a>';
if (d.isTwoApprove == 1 && d.isApprove == 1 && d.isThreeApprove == 0) {
text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
' id="pass">通过</a>';
text +=
'<a lay-event="reject" style="color: #a59e9e;cursor: pointer;font-size: 15px;margin-left: 10px"' +
' id="reject">驳回</a>';
} else {
if (d.isTwoApprove == 1 && d.isApprove == 1 && d.isThreeApprove == 1) {
text += '<a style="color: #009688;cursor: pointer;font-size: 15px"' +
' id="pass">已通过</a>';
} else if (d.isThreeApprove == 2 && d.isTwoApprove == 1) {
text += '<a style="color: #a59e9e;cursor: pointer;font-size: 15px"' +
' id="reject">已驳回</a>';
} else {
noMessage++
return ''
}
}
// text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
// ' id="pass">通过</a>';
// text +=

View File

@ -1,152 +1,154 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>汇总审核查看审批</title>
<link rel="stylesheet" href="../../../layui/css/layui.css"/>
<link rel="stylesheet" href="../../../layui/css/layui.css" />
</head>
<body>
<div style="padding: 10px;">
<div class="layui-btn-container" id="auditBtnGroup">
<div style="padding: 10px;">
<div class="layui-btn-container" id="auditBtnGroup">
</div>
<table class="layui-table" id="baseTable" lay-filter="test"></table>
</div>
<table class="layui-table" id="baseTable" lay-filter="test"></table>
</div>
<script src="../../../js/publicJs.js"></script>
<script src="../../../js/common_methon.js"></script>
<script type="text/javascript" src="../../../js/common.js"></script>
<script type="text/javascript" src="../../../js/libs/jquery-2.1.1.min.js"></script>
<script src="../../../layui/layui.js"></script>
<script type="text/javascript" src="../../../js/jq.js"></script>
<script type="text/javascript" src="../../../js/my/permission.js"></script>
<script>
let headerRows;
let layer, laydate, table;
let tableLoading;
let code = 0;
$(function () {
layui.use(['layer', 'laydate', 'table'], function () {
layer = layui.layer;
laydate = layui.laydate;
table = layui.table;
//自定义loading
tableLoading = layer.load(2, {shade: [0.1, '#fff']});
getAuditBtn();
initTable();
bindToolbarEvents();
<script src="../../../js/publicJs.js"></script>
<script src="../../../js/common_methon.js"></script>
<script type="text/javascript" src="../../../js/common.js"></script>
<script type="text/javascript" src="../../../js/libs/jquery-2.1.1.min.js"></script>
<script src="../../../layui/layui.js"></script>
<script type="text/javascript" src="../../../js/jq.js"></script>
<script type="text/javascript" src="../../../js/my/permission.js"></script>
<script>
let headerRows;
let layer, laydate, table;
let tableLoading;
let code = 0;
$(function () {
layui.use(['layer', 'laydate', 'table'], function () {
layer = layui.layer;
laydate = layui.laydate;
table = layui.table;
//自定义loading
tableLoading = layer.load(2, { shade: [0.1, '#fff'] });
getAuditBtn();
initTable();
bindToolbarEvents();
});
});
function getAuditBtn() {
$.ajax({
url: ctxPath + '/outsourcer/getAuditBtn',
type: 'post',
data: {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('evaluateId'),
type: 'audit',
},
success: function (res) {
if (res.res == '1') {
let data = res.obj;
let btnGroup = $('#auditBtnGroup');
btnGroup.empty();
for (let i = 0; i < data.length; i++) {
let btn = '';
if (data[i].isApprove == '0') {
btn =
`<button class="layui-btn layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','0')">${data[i].name}评价审批</button>`;
}else if (data[i].isApprove == '1') {
btn =
`<button class="layui-btn layui-btn-primary layui-border layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','1')">${data[i].name}</button>`;
}else if (data[i].isApprove == '2') {
btn =
`<button class="layui-btn layui-btn-primary layui-border-red layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','2')">${data[i].name}</button>`;
}
if (localStorage.getItem("AllAuditTitle") === '查看'){
btn =
`<button class="layui-btn layui-btn-primary layui-border layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','1')">${data[i].name}</button>`;
}
btnGroup.append(btn);
}
}
}
})
}
function initTable() {
code = 0;
getTitle();
}
function setCols(data, msg) {
//重新加载表格 清空之前的表头和内容
table.reload('baseTable', {
cols: []
});
headerRows = [];
headerRows = JSON.parse(data);
// Clear existing headers
const thead = document.querySelector('#baseTable thead');
if (thead) {
thead.innerHTML = '';
} else {
const newThead = document.createElement('thead');
document.querySelector('#baseTable').appendChild(newThead);
}
//动态生成表头
headerRows.forEach(rowData => {
rowData.forEach(cellData => {
cellData.align = 'center';
if (cellData.title === '序号') {
cellData.type = 'numbers';
cellData.fixed = 'left';
}
if (!['审核', '序号', '施工业务外包商', '工程名称'].includes(cellData.title)) {
if (cellData.field.split('-').length === 2) {
cellData.title =
`${cellData.title}<i class="layui-icon layui-icon-tips layui-font-14" lay-event="checkTips"
title="计算方法" style="margin-left: 5px;"></i>`;
}
} else {
if (cellData.title === '施工业务外包商') {
cellData.fixed = 'left';
}
if (cellData.title === '工程名称') {
cellData.fixed = 'left';
}
}
if (cellData.mergeType === "colspan") {
cellData.colspan = cellData.num;
} else if (cellData.mergeType === "rowspan") {
cellData.rowspan = cellData.num;
}
if (cellData.field === 'examineAndApprove') {
cellData.templet = function (d) {
//如果d.isApprove == 1 去除当前行的编辑功能
let text = "";
if (d.isApprove == 0) {
text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
' id="pass">通过</a>';
text +=
'<a lay-event="reject" style="color: #a59e9e;cursor: pointer;font-size: 15px;margin-left: 10px"' +
' id="reject">驳回</a>';
}
// text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
// ' id="pass">通过</a>';
// text +=
// '<a lay-event="reject" style="color: #a59e9e;cursor: pointer;font-size: 15px;margin-left: 10px"' +
// ' id="reject">驳回</a>';
return text;
}
}
});
});
table.render({
function getAuditBtn() {
$.ajax({
url: ctxPath + '/outsourcer/getAuditBtn',
type: 'post',
data: {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('evaluateId'),
type: 'audit',
},
success: function (res) {
if (res.res == '1') {
let data = res.obj;
let btnGroup = $('#auditBtnGroup');
btnGroup.empty();
for (let i = 0; i < data.length; i++) {
let btn = '';
if (data[i].isApprove == '0') {
btn =
`<button class="layui-btn layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','0')">${data[i].name}评价审批</button>`;
} else if (data[i].isApprove == '1') {
btn =
`<button class="layui-btn layui-btn-primary layui-border layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','1')">${data[i].name}</button>`;
} else if (data[i].isApprove == '2') {
btn =
`<button class="layui-btn layui-btn-primary layui-border-red layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','2')">${data[i].name}</button>`;
}
if (localStorage.getItem("AllAuditTitle") === '查看') {
btn =
`<button class="layui-btn layui-btn-primary layui-border layui-btn-sm" onclick="openPage('${data[i].id}', '${data[i].name}','1')">${data[i].name}</button>`;
}
btnGroup.append(btn);
}
}
}
})
}
function initTable() {
code = 0;
getTitle();
}
function setCols(data, msg) {
//重新加载表格 清空之前的表头和内容
table.reload('baseTable', {
cols: []
});
headerRows = [];
headerRows = JSON.parse(data);
// Clear existing headers
const thead = document.querySelector('#baseTable thead');
if (thead) {
thead.innerHTML = '';
} else {
const newThead = document.createElement('thead');
document.querySelector('#baseTable').appendChild(newThead);
}
//动态生成表头
headerRows.forEach(rowData => {
rowData.forEach(cellData => {
cellData.align = 'center';
if (cellData.title === '序号') {
cellData.type = 'numbers';
cellData.fixed = 'left';
}
if (!['审核', '序号', '施工业务外包商', '工程名称'].includes(cellData.title)) {
if (cellData.field.split('-').length === 2) {
cellData.title =
`${cellData.title}<i class="layui-icon layui-icon-tips layui-font-14" lay-event="checkTips"
title="计算方法" style="margin-left: 5px;"></i>`;
}
} else {
if (cellData.title === '施工业务外包商') {
cellData.fixed = 'left';
}
if (cellData.title === '工程名称') {
cellData.fixed = 'left';
}
}
if (cellData.mergeType === "colspan") {
cellData.colspan = cellData.num;
} else if (cellData.mergeType === "rowspan") {
cellData.rowspan = cellData.num;
}
if (cellData.field === 'examineAndApprove') {
cellData.templet = function (d) {
//如果d.isApprove == 1 去除当前行的编辑功能
let text = "";
if (d.isApprove == 0) {
text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
' id="pass">通过</a>';
text +=
'<a lay-event="reject" style="color: #a59e9e;cursor: pointer;font-size: 15px;margin-left: 10px"' +
' id="reject">驳回</a>';
}
// text += '<a lay-event="pass" style="color: #009688;cursor: pointer;font-size: 15px"' +
// ' id="pass">通过</a>';
// text +=
// '<a lay-event="reject" style="color: #a59e9e;cursor: pointer;font-size: 15px;margin-left: 10px"' +
// ' id="reject">驳回</a>';
return text;
}
}
});
});
table.render({
elem: '#baseTable',
cols: headerRows,
data: JSON.parse(msg), // 使用从 API 获取的数据
@ -329,7 +331,7 @@
});
if (typeof value === 'number') {
itemData[totalField] = t.toFixed(2);
}else {
} else {
itemData[totalField] = t;
}
@ -338,7 +340,7 @@
})
//计算总得分
layui.each(res.data, function (i, itemData) {
//对每一行所有total结尾的进行加和
//对每一行所有total结尾的进行加和
let map = {};
for (let key in itemData) {
map[key] = itemData[key];
@ -409,139 +411,140 @@
}
}
)
;
table.on('tool(test)', function (obj) {
var data = obj.data; //当前行数据
var rowIndex = obj.index;
var layEvent = obj.event; //当前点击的事件名
if (layEvent === 'pass') {
data.isApprove = 1;
audit(obj, 1, data);
}
if (layEvent === 'reject') {
data.isApprove = 2;
audit(obj, 2, data);
}
});
// 表头自定义元素工具事件 --- 2.8.8+
table.on('colTool(test)', function (obj) {
var event = obj.event;
if (event === 'checkTips') {
let text = `<span><span style="color: red">*</span>指标定义及计算方法:</span> ${obj.col.method}`;
text += `<br/><span><span style="color: red">*</span>积分标准:</span> ${obj.col.standard}`;
//设置500ms内仅弹出一次
if (!layer.alert.isShown) {
layer.alert.isShown = true;
layer.alert(text, {
title: `${obj.col.title}`,
end: function () {
setTimeout(function () {
layer.alert.isShown = false;
}, 500);
}
});
)
;
table.on('tool(test)', function (obj) {
var data = obj.data; //当前行数据
var rowIndex = obj.index;
var layEvent = obj.event; //当前点击的事件名
if (layEvent === 'pass') {
data.isApprove = 1;
audit(obj, 1, data);
}
if (layEvent === 'reject') {
data.isApprove = 2;
audit(obj, 2, data);
}
});
// 表头自定义元素工具事件 --- 2.8.8+
table.on('colTool(test)', function (obj) {
var event = obj.event;
if (event === 'checkTips') {
let text = `<span><span style="color: red">*</span>指标定义及计算方法:</span> ${obj.col.method}`;
text += `<br/><span><span style="color: red">*</span>积分标准:</span> ${obj.col.standard}`;
//设置500ms内仅弹出一次
if (!layer.alert.isShown) {
layer.alert.isShown = true;
layer.alert(text, {
title: `${obj.col.title}`,
end: function () {
setTimeout(function () {
layer.alert.isShown = false;
}, 500);
}
});
}
}
});
}
function getTitle() {
$.ajax({
url: ctxPath + '/outsourcer/getCollectData',
type: 'get',
data: {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('evaluateId'),
type: 'audit',
},
success: function (res) {
setCols(res.obj, res.resMsg);
}
})
}
function getTableData() {
//获取表格填写的数据
var tableData = table.cache.baseTable;
let filed = [];
//定义一个map
let obj = tableData[0];
for (let key in obj) {
if (key.indexOf('LAY') === -1 && !['subName', 'proName', 'subId', 'proId'].includes(key)) {
filed.push(key);
}
}
});
}
function getTitle() {
$.ajax({
url: ctxPath + '/outsourcer/getCollectData',
type: 'get',
data: {
//TODO 校验数据
let data = {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('evaluateId'),
type: 'audit',
},
success: function (res) {
setCols(res.obj, res.resMsg);
}
})
}
function getTableData() {
//获取表格填写的数据
var tableData = table.cache.baseTable;
let filed = [];
//定义一个map
let obj = tableData[0];
for (let key in obj) {
if (key.indexOf('LAY') === -1 && !['subName', 'proName', 'subId', 'proId'].includes(key)) {
filed.push(key);
}
}
//TODO 校验数据
let data = {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('id'),
jsonData: JSON.stringify(tableData),
titleFiled: filed.join(',')
};
$.ajax({
url: ctxPath + '/outsourcer/saveEvaluateData',
type: 'post',
data: data,
success: function (res) {
if (res.res == '1') {
layer.msg('保存成功');
closePage();
} else {
layer.msg(res.resMsg);
evaluateId: getUrlParam('id'),
jsonData: JSON.stringify(tableData),
titleFiled: filed.join(',')
};
$.ajax({
url: ctxPath + '/outsourcer/saveEvaluateData',
type: 'post',
data: data,
success: function (res) {
if (res.res == '1') {
layer.msg('保存成功');
closePage();
} else {
layer.msg(res.resMsg);
}
}
}
})
}
function bindToolbarEvents() {
table.on('toolbar(test)', function (obj) {
var id = obj.config.id;
switch (obj.event) {
case 'getCheckData':
//获取带按钮的名称
const title = $(this).text();
const layerIndex = layer.open({
type: 2,
title: title,
shade: 0.3,
area: ['80%', '90%'],
scrollbar: true,
move: true,
anim: 2,
shadeClose: false,
content: './reviewPage.html',
});
break;
case 'getData':
var getData = table.getData(id);
layer.alert(layui.util.escape(JSON.stringify(getData)));
break;
}
});
}
function openPage(id, name,type) {
let url = './otherEvaluateAuditForm.html?deptId=' + id + '&evaluateId=' + getUrlParam('evaluateId') +
'&templateId=' + getUrlParam('templateId') + '&type=' + type;
if (id == '0') {
url = './proEvaluateAuditForm.html?deptId=' + id + '&evaluateId=' + getUrlParam('evaluateId') +
'&templateId=' + getUrlParam('templateId') + '&type=' + type;
})
}
const layerIndex = layer.open({
type: 2,
title: name + "评价审批",
shade: 0.3,
area: ['98%', '98%'],
scrollbar: true,
move: true,
anim: 2,
shadeClose: false,
content: url,
});
}
</script>
function bindToolbarEvents() {
table.on('toolbar(test)', function (obj) {
var id = obj.config.id;
switch (obj.event) {
case 'getCheckData':
//获取带按钮的名称
const title = $(this).text();
const layerIndex = layer.open({
type: 2,
title: title,
shade: 0.3,
area: ['80%', '90%'],
scrollbar: true,
move: true,
anim: 2,
shadeClose: false,
content: './reviewPage.html',
});
break;
case 'getData':
var getData = table.getData(id);
layer.alert(layui.util.escape(JSON.stringify(getData)));
break;
}
});
}
function openPage(id, name, type) {
let url = './otherEvaluateAuditForm.html?deptId=' + id + '&evaluateId=' + getUrlParam('evaluateId') +
'&templateId=' + getUrlParam('templateId') + '&type=' + type;
if (id == '0') {
url = './proEvaluateAuditForm.html?deptId=' + id + '&evaluateId=' + getUrlParam('evaluateId') +
'&templateId=' + getUrlParam('templateId') + '&type=' + type;
}
const layerIndex = layer.open({
type: 2,
title: name + "评价审批",
shade: 0.3,
area: ['98%', '98%'],
scrollbar: true,
move: true,
anim: 2,
shadeClose: false,
content: url,
});
}
</script>
</body>
</html>
</html>