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('');
}
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 += '
' +
'| ' + (index + 1) + ' | ' +
'' + item.proName + ' | ' +
'' + item.code + ' | ' +
'' + item.supName + ' | ' +
'' + item.carNum + ' | ' +
'' + item.money + ' | ' +
'' + item.ygMoney + ' | ' +
'
';
});
$('#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 += "" +
"| " + item.type + " | " +
"" + item.name + " | " +
"" + item.model + " | " +
"" + item.carNum + " | " +
"" + (item.ton + '吨') + " | " +
"" + item.goodsName + " | " +
"" + item.startAddress + " | " +
"" + item.endAddress + " | " +
"" + actualGls + " | " +
"" + item.glsPrice + " | " +
" ¥ " + (item.glsMoney ? item.glsMoney : 0) + " | " +
"" + imgNum + "查看附件>> | " +
"" + item.planCode + " | " +
'' + item.remark + ' | ' +
"
";
})
} else {
html = '| 暂无数据 |
';
}
$('#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 += '' +
'| ' + item.type + ' | ' +
'' + item.name + ' | ' +
'' + item.model + ' | ' +
'' + item.carNum + ' | ' +
'' + item.useAddress + ' | ' +
'' + item.exeDay + ' | ' +
'' + setZlPrice(item) + ' | ' +
' ¥ ' + item.dcMoney + ' | ' +
'' + actualDcMoney + ' | ' +
"" + imgNum + "查看附件>> | " +
"" + item.planCode + " | " +
'' + item.remark + ' | ' +
'
';
})
} else {
html = '| 暂无数据 |
';
}
$('#dispatch-car-table2').removeAttr('style').append(html);
// 设置租赁单价
function setZlPrice(item) {
let html = '';
if (item.dcUnit === '元/月/台') {
html += '' + item.monthPrice + '(' + item.dcUnit + ')' + '';
} else {
html += '' + item.dayPrice + '(' + item.dcUnit + ')' + '';
}
if (item.isOutSet === 1) {
html += '' + (item.jcMoney ? item.jcMoney : 0) + '(进出场费)'
}
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 += '' +
'| ' + handleFileType(item.fileName) + item.fileName + ' | ' +
'' + (item.type) + ' | ' +
' ' + item.createName + ' | ' +
'' + item.createTime + ' | ' +
'预览' +
'下载' +
' | ' +
'
';
})
} else {
html = '| 暂无数据 |
';
}
$('#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 '
'
}
// 预览文件
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 '' + d.remark.substring(0, 60) + '...'
} else {
return '' + d.remark + ''
}
} 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 '' + value + "";
} else {
return '' + value + "";
}
}
// 导出
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.userName;
// 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 += '' +
'
' +
'
' +
'
' + item.auditTime.substring(0, 10) + '
' +
'
' +
'
' +
'
' +
'

' +
'
' +
'
' +
'
' +
'' + dept+ '-' + item.auditUser + '' +
'
' +
'
' +
'' + operData + '' +
'
' +
'
' +
'
' +
'

' +
'
' + item.auditTime + '' +
'
' +
'
' +
'
' +
'
' +
'
';
})
}
$('.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("");
}
}
}
}
// 审核状态
function getCheckStatus(statusType, status) {
var company = "";
if (statusType === 0 && status === 0) {
return "●已撤回";
}
if (statusType === 1) {
return "●审核通过";
} else if (statusType === 2) {
company = "分公司";
} else if (statusType === 3) {
company = "项管中心";
} else if (statusType === 4) {
company = "智联装备云控公司";
}
if (status === 1) {
return "●待" + company + "审核";
} else if (status === 2) {
return "●审核通过";
} else if (status === 3) {
return "●" + company + "审核驳回";
}
return "●待审核";
}
// 打印
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); // 再执行关闭
}