gz_car_ui/js/car_application_audit/car_audit_detail.js

709 lines
26 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let idParam, objParam;
let details;
let form, layer, table;
let isPage = getUrlParam('isPage');
let token;
if (isPage) { // 首页跳转
$('#plan-detail-box>div').eq(0).remove();
$('#plan-detail-box').css({'justify-content': 'end', 'height': '50px'});
$('body').css('margin', '0');
let obj = decodeURIComponent(getUrlParam('obj'))
setParams(obj);
}
// 获取 URL 参数
function getParamsFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
const result = {};
for (const [key, value] of urlParams.entries()) {
result[key] = value;
}
return result;
}
// 页面加载完成后执行
window.addEventListener("DOMContentLoaded", () => {
const params = getParamsFromUrl();
console.log(params)
if (!params.token) {
return;
}
token = params.token;
sessionStorage.setItem('gz-token', params.token);
let url = dataUrl + `backstage/carPlanAudit/getCarAuditById/${params.id}`;
ajaxRequest(url, "GET", {}, true, function () {
}, function (result) {
if (result.code === 200) {
params.isFinish === '1' ? result.data.checkType = 0 : result.data.checkType = 2
setParams(JSON.stringify(result.data));
} else {
}
}, function (xhr, status, error) {
errorFn(xhr, status, error)
}, null);
});
function setParams(obj) {
objParam = JSON.parse(obj);
if (objParam.checkType === 2) {
$('#print').before('<button type="button" class="layui-btn layui-bg-orange" onclick="check()">审核</button>');
}
idParam = objParam.id;
layui.use(['form', 'layer', 'table'], function () {
form = layui.form;
layer = layui.layer;
table = layui.table;
getBalanceDataDetails();
// initTable();
});
}
// 详情
function getBalanceDataDetails() {
let encryptedData = {id: objParam.id};
let url = dataUrl + 'backstage/carBalance/getBalanceDataDetails?encryptedData=' + encodeURIComponent(JSON.stringify(encryptedData));
ajaxRequest(url, "GET", null, true, function () {
}, function (result) {
if (result.code === 200) {
setPlanBasicTableInfo(result.data);
setOperRecordInfo(result.data.aulditList, result.data);
// setCheckStatus(result.data);
// 计划明细回显
planDetail(result.data.planList)
// 用车明细回显
carDetail(result.data.detailsList)
}
}, function (xhr, status, error) {
errorFn(xhr, status, error)
}, null);
}
function planDetail(list) {
$('#plan-detail-table tr:not(:first)').remove();
if (list.length > 0) {
let html = '';
$.each(list, function (index, item) {
html += '<tr>' +
'<td>' + (index + 1) + '</td>' +
'<td>' + item.proName + '</td>' +
'<td>' + item.code + '</td>' +
'<td>' + item.supName + '</td>' +
'<td>' + item.carNum + '</td>' +
'<td>' + item.money + '</td>' +
'<td>' + item.ygMoney + '</td>' +
'</tr>';
});
$('#plan-detail-table').append(html);
}
}
function carDetail(list) {
// 派车明细
let carList = list.filter(item => {
return item.type === '车辆';
})
let dcList = list.filter(item => {
return item.type === '吊车';
})
setDispatchCarTable(carList);
setDispatchCarTable2(dcList);
// 派车明细-车辆
function setDispatchCarTable(list) {
$('#dispatch-car-table tr:not(:first)').remove();
if (list.length > 0) {
let html = '';
if (list && list.length > 0) {
$.each(list, function (index, item) {
let imgNum = 0;
imgNum += item.carImage.filter(item => {
return item.type !== '6'
}).length;
imgNum += item.driverUserImage.filter(item => {
return item.type !== '6'
}).length;
imgNum += item.fileList.length;
const actualGls = item.exeGls; // 实际公里数初始=预估公里数
html += "<tr>" +
"<td>" + item.type + "</td>" +
"<td>" + item.name + "</td>" +
"<td>" + item.model + "</td>" +
"<td>" + item.carNum + "</td>" +
"<td>" + (item.ton + '吨') + "</td>" +
"<td>" + item.goodsName + "</td>" +
"<td>" + item.startAddress + "</td>" +
"<td>" + item.endAddress + "</td>" +
"<td>" + actualGls + "</td>" +
"<td>" + item.glsPrice + "</td>" +
"<td> ¥ " + (item.glsMoney ? item.glsMoney : 0) + "</td>" +
"<td style='color:#409eff'>" + imgNum + "<a style='color:#409eff;margin:0 5px;cursor: pointer;' onclick='viewFileDetail(" + JSON.stringify(item) + ",1)'>查看附件>></a></td>" +
"<td><a style='color:#409eff;margin:0 5px;cursor: pointer;' onclick='viewPlanDetail(" + JSON.stringify(item) + ")'>" + item.planCode + "</a></td>" +
'<td>' + item.remark + '</td>' +
"</tr>";
})
} else {
html = '<tr><td colspan="13" style="text-align: center;">暂无数据</td></tr>';
}
$('#dispatch-car-table').removeAttr('style').append(html);
} else {
$('#dispatch-car-table').css('display', 'none');
}
}
// 派车明细-吊车
function setDispatchCarTable2(list) {
$('#dispatch-car-table2 tr:not(:first)').remove();
if (list.length > 0) {
let html = '';
if (list && list.length > 0) {
$.each(list, function (index, item) {
let imgNum = 0;
imgNum += item.driverUserImage.filter(item => {
return item.type === '2' || item.type === '3'
}).length;
imgNum += item.operaImage.filter(item => {
return item.type === '2' || item.type === '3' || item.type === '6'
}).length;
imgNum += item.fileList.length;
const actualPlanDay = item.exeDay || 0;
const actualDcMoney = item.money;
html += '<tr>' +
'<td>' + item.type + '</td>' +
'<td>' + item.name + '</td>' +
'<td>' + item.model + '</td>' +
'<td>' + item.carNum + '</td>' +
'<td>' + item.useAddress + '</td>' +
'<td>' + item.exeDay + '</td>' +
'<td>' + setZlPrice(item) + '</td>' +
'<td> ¥ ' + item.dcMoney + '</td>' +
'<td>' + actualDcMoney + '</td>' +
"<td style='color:#409eff'>" + imgNum + "<a style='color:#409eff;margin:0 5px;cursor: pointer;' onclick='viewFileDetail(" + JSON.stringify(item) + ",2)'>查看附件>></a></td>" +
"<td><a style='color:#409eff;margin:0 5px;cursor: pointer;' onclick='viewPlanDetail(" + JSON.stringify(item) + ")'>" + item.planCode + "</a></td>" +
'<td>' + item.remark + '</td>' +
'</tr>';
})
} else {
html = '<tr><td colspan="10" style="text-align: center;">暂无数据</td></tr>';
}
$('#dispatch-car-table2').removeAttr('style').append(html);
// 设置租赁单价
function setZlPrice(item) {
let html = '';
if (item.dcUnit === '元/月/台') {
html += '<span>' + item.monthPrice + '' + item.dcUnit + '' + '</span>';
} else {
html += '<span>' + item.dayPrice + '' + item.dcUnit + '' + '</span>';
}
if (item.isOutSet === 1) {
html += '<span>' + (item.jcMoney ? item.jcMoney : 0) + '(进出场费)</span>'
}
return html;
}
} else {
$('#dispatch-car-table2').css('display', 'none');
}
}
}
// 基本信息
function setPlanBasicTableInfo(dataObj) {
$('#supId').html(dataObj.supId);
$('#supName').html(dataObj.supName);
$('#fkTime').html(dataObj.fkTime);
$('#money').html(dataObj.money);
$('#remark').html(dataObj.remark);
$('#planListNum').html(dataObj.planList.length)
// 附件文档
setFileTable(dataObj.fileList);
}
// 附件文档赋值
function setFileTable(fileList) {
$('#file-table tr:not(:first)').remove();
let html = '';
if (fileList && fileList.length > 0) {
$.each(fileList, function (index, item) {
html += '<tr>' +
'<td>' + handleFileType(item.fileName) + item.fileName + '</td>' +
'<td>' + (item.type) + '</td>' +
'<td><img src="../../../images/user_head_icon.png" width="20px" height="20px">' + item.createName + '</td>' +
'<td>' + item.createTime + '</td>' +
'<td><a style="margin:0 5px;color:#409EFF;cursor: pointer;" onclick=\'viewFile(' + JSON.stringify(item) + ')\'>预览</a>' +
'<a style="margin:0 5px;color:#409EFF;cursor: pointer;" onclick=\'downLoadFile(' + JSON.stringify(item) + ')\'>下载</a>' +
'</td>' +
'</tr>';
})
} else {
html = '<tr><td colspan="5" style="text-align: center;">暂无数据</td></tr>';
}
$('#file-table tbody').after(html);
}
// 处理文件类型
function handleFileType(value) {
value = value.toLowerCase();
let src = '';
if (value.indexOf('docx') > -1 || value.indexOf('doc') > -1) {
src = '../../../images/docx.png'
} else if (value.indexOf('xls') > -1 || value.indexOf('xlsx') > -1) {
src = '../../../images/xlsx.png'
} else if (value.indexOf('pdf') > -1) {
src = '../../../images/pdf.png'
} else if (value.indexOf('png') > -1 || value.indexOf('jpg') > -1 || value.indexOf('jpeg') > -1) {
src = '../../../images/img_icon.png'
}
return '<img width="20px" height="20px" src = "' + src + '" style="margin:0 5px;">'
}
// 预览文件
function viewFile(obj) {
let fileName = obj.fileName.toLowerCase();
if (fileName.indexOf('png') > -1 || fileName.indexOf('jpg') > -1 || fileName.indexOf('jpeg') > -1) {
layer.photos({
shade: 0.5,
photos: {
"title": "图片预览",
"start": 0,
"data": [
{
"alt": "layer",
"pid": 1,
"src": fileUrl + obj.fileUrl + '?token=' + sessionStorage.getItem("gz-token"),
}
]
}
});
} else {
// 调用公司的预览文件的服务
commonViewFile(obj.fileUrl);
}
}
// 下载文件
function downLoadFile(obj) {
let url = dataUrl + "sys/file/download?fileId=" + obj.id;
downLoadFileUtil(url, obj.fileName, null);
}
// 查询/重置
function queryTable(type) {
if (type === 1) {
let name = $('#name').val();
let flag = checkValue(name);
if (flag) {
$('#name').val('');
return layer.msg('名称查询包含特殊字符,请重新输入', {icon: 2});
}
let model = $('#model').val();
let flag2 = checkValue(model);
if (flag2) {
$('#model').val('');
return layer.msg('规格查询包含特殊字符,请重新输入', {icon: 2});
}
reloadTable(1);
} else if (type === 2) {
$('#name').val('');
$('#model').val('');
layui.form.render();
reloadTable(1);
}
}
// 刷新页面数据
function reloadData() {
reloadTable(1);
}
// 重载表格
function reloadTable(pageNum) {
table.reload("currentTableId", {
page: {
curr: pageNum ? pageNum : 1,
},
where: {
encryptedData: JSON.stringify({
'name': $('#name').val(),
'model': $('#model').val(),
'id': objParam.id
}),
},
},
);
}
// 初始化表格
function initTable() {
tableIns = table.render({
elem: "#currentTableId",
id: 'currentTableId',
headers: {
authorization: sessionStorage.getItem("gz-token"),
},
height: "full",
url: dataUrl + "backstage/carNeedPlan/getNeedPlanDetailsList",
where: {
encryptedData: JSON.stringify({
'name': $('#name').val(),
'model': $('#model').val(),
'id': objParam.id
}),
},
request: {
pageName: 'pageNum',
limitName: 'pageSize'
},
parseData: function (res) { // res 即为原始返回的数据
if (res.code === 401) {
closeWindowOpen();
}
return {
"code": 0, // 解析接口状态
"msg": '获取成功', // 解析提示文本
"count": res.total, // 解析数据长度
"data": res.list // 解析数据列表
};
},
cols: [
[
{
width: '8%',
title: "序号",
align: "center",
templet: function (d) {
return d.LAY_NUM;
},
},
{
field: "type",
width: '10%',
title: "类型",
unresize: true,
align: "center",
sort: true,
},
{
field: "name",
width: '10%',
title: "名称",
unresize: true,
align: "center",
sort: true,
},
{
field: "model",
width: '15%',
title: "规格",
unresize: true,
align: "center",
sort: true,
},
{
field: "unit",
width: '10%',
title: "单位",
unresize: true,
align: "center",
sort: true,
templet: function (d) {
return setNullValue(d.unit);
},
},
{
field: "carSpec",
width: '14%',
title: "所需规格",
unresize: true,
align: "center",
},
{
field: "needNum",
width: '10%',
title: "需用量",
unresize: true,
align: "center",
sort: true,
templet: function (d) {
return setNumColor(d.needNum);
},
},
{
field: "backDate",
width: '12%',
title: "预计使用时间(天)",
unresize: true,
align: "center",
sort: true,
templet: function (d) {
return d.backDate;
},
},
{
field: "remark",
width: '10%',
title: "备注",
sort: true,
unresize: true,
align: "center",
templet: function (d) {
if (d.remark) {
if (d.remark.length > 60) {
return '<span title="' + d.remark + '">' + d.remark.substring(0, 60) + '...</span>'
} else {
return '<span title="' + d.remark + '">' + d.remark + '</span>'
}
} else {
return '';
}
},
},
],
],
limits: [10, 15, 20, 25, 50, 100],
limit: 10,
page: true,
done: function (res, curr, count) {
pageNum = tableIns.config.page.curr;
table.resize("currentTableId");
},
});
}
// 数量颜色
function setNumColor(value, isNeedNum) {
if (isNeedNum) {
return '<span style="color:#409Eff;font-weight:bold;">' + value + "</span>";
} else {
return '<span style="color:#409Eff;font-weight:bold;">' + value + "</span>";
}
}
// 导出
function exportData() {
let params = {
"id": objParam.id,
'name': $('#name').val(),
'model': $('#model').val(),
}
let url = dataUrl + "backstage/carNeedPlan/exportDetails";
exportExcelUtil(url, '申请明细', JSON.stringify(params));
}
// 操作记录
function setOperRecordInfo(list, obj) {
let html = '';
if (list && list.length > 0) {
let imgUrl = '../../../images/user_head_icon.png';
let imgUrl2 = '../../../images/time_icon.png';
$.each(list, function (index, item) {
const creator = item.auditUser;
// 1. 容错处理(统一处理空值、类型转换)
const remark = setNullValue(item.auditReason); // 已有空值处理,保留
const auditType = item.auditType + ''; // 确保为字符串(匹配原条件的字符串判断)
const auditStatus = item.auditStatus + ''; // 确保为字符串
const times = setNullValue(item.auditTime) || '0'; // 时间间隔容错(避免拼接 undefined
// 2. 部门映射表(替代多 if-else清晰直观
const deptMap = {
'0': '分包商',
'1': '项目部',
'2': '放线队',
'3': '分公司',
'4': '经营部',
'5': '总经理'
};
const dept = deptMap[auditType] || '未知部门'; // 默认值容错
// 3. 操作流程规则(按「优先级+条件组合」定义,避免逻辑冲突)
const operRules = [
// 规则:[条件函数, 操作文案],按优先级排序(先匹配先执行)
[() => index === 0 && auditType == '0', '发起申请'],
[() => auditType === '0' && auditStatus == '0', `发起申请,时间:${times} 原因备注:${remark}`],
[() => auditType === '1' && auditStatus == '1', `审核确认通过,时间:${times} 原因备注:${remark}`], // 原逻辑:无 index 限制
[() => auditType === '1' && auditStatus == '2', `驳回-给发起人${creator},共间隔:${times} 原因备注:${remark}`],
[() => auditType === '2' && auditStatus == '1', `审核确认通过,时间:${times} 原因备注:${remark}`],
[() => auditType === '2' && auditStatus == '2', `驳回-给发起人${creator},共间隔:${times} 原因备注:${remark}`],
[() => auditType === '3' && auditStatus == '1', `完结-审核确认通过,时间:${times} 原因备注:${remark}`],
[() => auditType === '3' && auditStatus == '2', `驳回-给发起人${creator},共间隔:${times} 原因备注:${remark}`],
[() => auditType === '4' && auditStatus == '1', `完结-审核确认通过,时间:${times} 原因备注:${remark}`],
[() => auditType === '4' && auditStatus == '2', `驳回-给发起人${creator},共间隔:${times} 原因备注:${remark}`],
[() => auditType === '5' && auditStatus == '1', `完结-审核确认通过,时间:${times} 原因备注:${remark}`],
[() => auditType === '5' && auditStatus == '2', `驳回-给发起人${creator},共间隔:${times} 原因备注:${remark}`],
];
// 匹配操作文案(默认值容错)
let operData = '未知操作';
for (const [condition, text] of operRules) {
if (condition()) {
operData = text;
break; // 找到匹配规则,立即退出(保证优先级)
}
}
html += '<div class="layui-timeline-item">' +
'<i class="layui-icon layui-timeline-axis"></i>' +
'<div class="layui-timeline-content layui-text">' +
'<h3 class="layui-timeline-title">' + item.auditTime.substring(0, 10) + '</h3>' +
'<div class="layui-panel">' +
'<div class="oper-info layout">' +
'<div class="layout">' +
'<img src="' + imgUrl + '">' +
'</div>' +
'<div class="user-oper layout">' +
'<div style="width: 100%">' +
'<span>' + dept+ '</span>-<span>' + item.auditUser + '</span>' +
'</div>' +
'<div style="width: 100%">' +
'<span>' + operData + '</span>' +
'</div>' +
'</div>' +
'<div class="layout">' +
'<img src="' + imgUrl2 + '">' +
'<span style="margin: 0 5px 0 5px;">' + item.auditTime + '</span>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
})
}
$('.layui-timeline').empty().append(html);
}
// 设置计划编号/审核状态
function setCheckStatus(obj) {
$('#code').empty().html(obj.code);
$('#checkStatus').html(getCheckStatus(obj.statusType, obj.status));
if (obj.statusType === 2 && obj.status === 1 && objParam.checkType !== 2) { // 待分公司审核可以撤回 && 申请人可以撤回 && 不是审核页面跳转
let user = sessionStorage.getItem('us');
if (user) {
let userObj = JSON.parse(user);
if (userObj.username === obj.userName) {
$('#print').before("<button type='button' style='margin-left:10px;' class='layui-btn layui-bg-orange' onclick='withdrawData(" + JSON.stringify(obj) + ")'>撤回</button>");
}
}
}
}
// 审核状态
function getCheckStatus(statusType, status) {
var company = "";
if (statusType === 0 && status === 0) {
return "<span style='color:#FF9900;margin:0 5px 0 5px;font-size:16px'>●</span>已撤回";
}
if (statusType === 1) {
return "<span style='color:#19BE6B;margin:0 5px 0 5px;font-size:16px;'>●</span>审核通过";
} else if (statusType === 2) {
company = "分公司";
} else if (statusType === 3) {
company = "项管中心";
} else if (statusType === 4) {
company = "智联装备云控公司";
}
if (status === 1) {
return "<span style='color:#FF9900;margin:0 5px 0 5px;font-size:16px'>●</span>待" + company + "审核";
} else if (status === 2) {
return "<span style='color:#19BE6B;margin:0 5px 0 5px;font-size:16px;'>●</span>审核通过";
} else if (status === 3) {
return "<span style='color:#F56C6C;margin:0 5px 0 5px;font-size:16px'>●</span>" + company + "审核驳回";
}
return "<span style='color:#FF9900;margin:0 5px 0 5px;font-size:16px'>●</span>待审核";
}
// 打印
function print() {
$("#main-box").print({
globalStyles: true,
mediaPrint: false,
stylesheet: '../../../css/aq_demand_plan/apply_plan_detail.css',
noPrintSelector: ".no-print",
iframe: true,
append: null,
prepend: null,
manuallyCopyFormValues: true,
deferred: $.Deferred()
});
}
// 撤回
function withdrawData(data) {
layer.confirm("确定撤回此条数据吗?", {'title': '操作提示', move: false}, function () {
let loadingMsg = layer.msg('数据撤回中,请稍候...', {icon: 16, scrollbar: false, time: 0});
let url = dataUrl + "backstage/carNeedPlan/withdrawData"
let obj = {id: data.id}
let params = {
encryptedData: JSON.stringify(obj)
}
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
console.error(result);
layer.close(loadingMsg); // 关闭提示层
if (result.code === 200) {
parent.layer.msg(result.msg, {icon: 1})
closePage();
} else {
layer.msg(result.msg, {icon: 2})
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
});
})
}
// 查看附件
function viewFileDetail(obj, type) {
let title = '行驶证/挂靠协议驾驶证/身份证/导航图'
if (type === 1) {
title = '行驶证/挂靠协议驾驶证/身份证/导航图'
} else if (type === 2) {
title = '操作证/身份证/导航图'
}
obj.type = type;
openIframeByParamObj("viewFileDetail", title, '../../car_demand_plan/child/view_file_detail.html', "92%", "95%", obj);
}
// 需求计划详情
function viewPlanDetail(obj) {
obj.id = obj.planId;
obj.code = obj.planCode;
let content = '../car_demand_plan/child/apply_plan_detail.html';
if (obj.code.indexOf('spec-') > -1) {
content = '../car_demand_plan/child/emerg_internal_car_detail.html';
}
openIframeByParamObj2("viewPlanDetail", "车辆需求计划", content, "92%", "95%", obj);
}
// 需求计划申请审核
function check() {
objParam.token = token;
openIframeByParamObj("check", "审核", "./car_audit_form.html", "40%", "50%", objParam, 1);
}
function closePage() {
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
window.parent.queryTable(1);
parent.layer.close(index); // 再执行关闭
}