765 lines
32 KiB
JavaScript
765 lines
32 KiB
JavaScript
let idParam, objParam, fileList = new Array(), imgListUp = new Array();
|
||
let form, laydate, layer, upload, table, util;
|
||
let pageNum = 1, tableIns; // 定义分页
|
||
let jjDataArr = []; // 清单数据
|
||
let delIdArr = []; // 存储要删除的文件ID(关键:新增初始化)
|
||
let planId = ''; // 计划ID
|
||
let allDataList = [];
|
||
|
||
function setParams(obj) {
|
||
objParam = JSON.parse(obj);
|
||
// 初始化删除文件ID数组(避免残留)
|
||
delIdArr = [];
|
||
layui.use(['form', 'layer', 'laydate', 'upload', 'table'], function () {
|
||
form = layui.form;
|
||
layer = layui.layer;
|
||
laydate = layui.laydate;
|
||
upload = layui.upload;
|
||
table = layui.table;
|
||
util = layui.util;
|
||
laydate.render({
|
||
elem: '#fkTime'
|
||
});
|
||
form.verify();
|
||
form.on('submit(formData)', function (data) {
|
||
submitApply(data);
|
||
});
|
||
form.render();
|
||
let uploadObj = upload.render({
|
||
elem: '#test2',
|
||
multiple: true,
|
||
dataType: "json",
|
||
exts: 'jpg|png|jpeg|doc|docx|pdf|xlsx|xls',
|
||
acceptMime: 'image/jpg,image/png,image/jpeg,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||
number: 5, //最大上传数量
|
||
size: 1024 * 10, //最大文件大小,单位k
|
||
auto: false, //是否自动上传 ,默认为true
|
||
bindAction: '#hideUpload', //绑定的按钮
|
||
choose: function (obj) {
|
||
let length = $('.file-iteme').length;
|
||
if (length >= 5) {
|
||
return layer.msg('最多上传5个附件证明', {icon: 7});
|
||
}
|
||
uploadObj.config.elem.next()[0].value = '';
|
||
let num = 0;
|
||
obj.preview(function (index, file, result) {
|
||
num++;
|
||
if (num <= (5 - length)) {
|
||
$('#uploader-list').append(
|
||
'<div id="" class="file-iteme">' +
|
||
'<div class="handle"><p>x</p></div>' +
|
||
handleFileType(index, file, result) +
|
||
'</div>'
|
||
);
|
||
let map = new Map();//将选择的图片索引和图片写成对象存入集合
|
||
map.index = index;
|
||
map.file = file;
|
||
fileList.push(map);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
getBalanceDataDetails();
|
||
});
|
||
}
|
||
|
||
// 获取数据详情
|
||
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) {
|
||
|
||
//基本信息回显
|
||
let dataObj = result.data;
|
||
$('#supName').val(dataObj.supName);
|
||
$('#fkTime').val(util.toDateString(dataObj.fkTime, 'yyyy-MM-dd'));
|
||
$('#money').val(dataObj.money);
|
||
$('#remark').val(dataObj.remark);
|
||
$('#planListNum').val(dataObj.planList.length)
|
||
|
||
// ========== 保留:附件回显+加入 ==========
|
||
let cent = '';
|
||
// 清空原有fileList和delIdArr(避免重复)
|
||
fileList = [];
|
||
delIdArr = []; // 重置删除文件ID数组
|
||
if (dataObj.fileList.length > 0) {
|
||
for (let i = 0; i < dataObj.fileList.length; i++) {
|
||
let l = dataObj.fileList[i];
|
||
let path = fileUrl + l.fileUrl + '?token=' + sessionStorage.getItem("gz-token");
|
||
let file = { name: l.fileName, id: l.id, type: l.type };
|
||
cent += '<div id="" class="file-iteme" data-file-id="' + l.id + '">' +
|
||
'<div class="handle"><p>x</p></div>' +
|
||
handleFileType(i, file, path, l.type) +
|
||
'</div>';
|
||
// 回显附件加入fileList(标记为已存在的文件)
|
||
fileList.push({
|
||
index: i,
|
||
file: file,
|
||
isExist: true, // 标记为回显的旧文件
|
||
fileId: l.id // 存储文件ID,用于删除
|
||
});
|
||
}
|
||
}
|
||
console.log("aa==",fileList)
|
||
$('#uploader-list').append(cent);
|
||
|
||
// 计划明细回显
|
||
planDetail(dataObj.planList)
|
||
// 用车明细回显
|
||
carDetail(dataObj.detailsList)
|
||
|
||
// ========== 保留:初始化allDataList和jjDataArr ==========
|
||
allDataList = dataObj.detailsList || [];
|
||
jjDataArr = dataObj.planList || [];
|
||
}
|
||
}, 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>' +
|
||
'<td>' +
|
||
'<div class="handle">' +
|
||
'<a style="color:#f56c6c;cursor: pointer;" onclick="delPlanDetail(' + index + ')">删除</a>' +
|
||
'</div>' +
|
||
'</td>' +
|
||
'</tr>';
|
||
});
|
||
$('#plan-detail-table').append(html);
|
||
}
|
||
}
|
||
|
||
// ========== 保留:delPlanDetail删除关联用车明细+同步数据 ==========
|
||
function delPlanDetail(index) {
|
||
let planList = $('#plan-detail-table tr:not(:first)');
|
||
if (planList.length <= 1) {
|
||
return layer.msg('计划明细至少保留1条数据,无法删除!', {icon: 7});
|
||
}
|
||
let currentTr = planList.eq(index);
|
||
let delCode = currentTr.find('td:eq(2)').text().trim();
|
||
if (!delCode) {
|
||
return layer.msg('未获取到需求计划编号,无法删除!', {icon: 2});
|
||
}
|
||
|
||
layer.confirm('确定删除该计划明细及对应的用车明细数据吗?', {icon: 3, title: '提示'}, function (layIndex) {
|
||
currentTr.remove();
|
||
$('#plan-detail-table tr:not(:first)').each(function(i) {
|
||
$(this).find('td:eq(0)').text(i + 1);
|
||
});
|
||
//删除用车明细中code匹配的数据
|
||
deleteCarDetailByCode(delCode);
|
||
// 同步更新jjDataArr和allDataList
|
||
jjDataArr = jjDataArr.filter(item => item.code !== delCode);
|
||
allDataList = allDataList.filter(item => item.planCode !== delCode);
|
||
layer.close(layIndex);
|
||
})
|
||
}
|
||
|
||
// ========== 保留:deleteCarDetailByCode精准删除用车明细 ==========
|
||
function deleteCarDetailByCode(delCode) {
|
||
// 1. 删除普通车辆表格中对应code的数据
|
||
$('#dispatch-car-table tr:not(:first)').each(function() {
|
||
let $tr = $(this);
|
||
// 优先获取a标签文本,避免索引错误
|
||
let carCode = $tr.find('td:last a').text().trim() || '';
|
||
if (!carCode) {
|
||
carCode = $tr.find('td:last').text().replace(/<.*?>/g, '').trim();
|
||
}
|
||
if (carCode === delCode) {
|
||
$tr.remove();
|
||
}
|
||
});
|
||
|
||
// 2. 删除吊车表格中对应code的数据
|
||
$('#dispatch-car-table2 tr:not(:first)').each(function() {
|
||
let $tr = $(this);
|
||
// 优先获取a标签文本,避免索引错误
|
||
let dcCode = $tr.find('td:last a').text().trim() || '';
|
||
if (!dcCode) {
|
||
dcCode = $tr.find('td:last').text().replace(/<.*?>/g, '').trim();
|
||
}
|
||
if (dcCode === delCode) {
|
||
$tr.remove();
|
||
}
|
||
});
|
||
|
||
// 3. 处理删除后无数据的情况
|
||
if ($('#dispatch-car-table tr:not(:first)').length === 0) {
|
||
$('#dispatch-car-table').css('display', 'none');
|
||
}
|
||
if ($('#dispatch-car-table2 tr:not(:first)').length === 0) {
|
||
$('#dispatch-car-table2').css('display', 'none');
|
||
}
|
||
}
|
||
|
||
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 = formatToTwoDecimals(item.exeGls) || 0.00; // 实际公里数初始=预估公里数
|
||
|
||
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><input type='number' class='form-control actual-gls' value='" + actualGls +
|
||
"' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></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>" +
|
||
"</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 = formatToTwoDecimals(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.planDay + '</td>' +
|
||
"<td><input type='number' class='form-control actual-dc-planDay' value='" + actualPlanDay +
|
||
"' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></td>" +
|
||
'<td>' + setZlPrice(item) + '</td>' +
|
||
'<td> ¥ ' + item.dcMoney + '</td>' +
|
||
|
||
"<td><input type='number' class='form-control actual-dc-money' value='" + actualDcMoney +
|
||
"' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></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>" +
|
||
'</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 += '<p>' + item.monthPrice + '(' + item.dcUnit + ')' + '</p>';
|
||
} else {
|
||
html += '<p>' + item.dayPrice + '(' + item.dcUnit + ')' + '</p>';
|
||
}
|
||
if (item.isOutSet === 1) {
|
||
html += '<p>' + (item.jcMoney ? item.jcMoney : 0) + '(进出场费)</p>'
|
||
}
|
||
return html;
|
||
}
|
||
} else {
|
||
$('#dispatch-car-table2').css('display', 'none');
|
||
}
|
||
}
|
||
}
|
||
|
||
// 设置文件类型
|
||
function handleFileType(index, file, result) {
|
||
let html = '', img = '';
|
||
if (file.ext) {
|
||
file.ext = file.ext.toLowerCase();
|
||
}
|
||
if (file.name) {
|
||
file.name = file.name.toLowerCase();
|
||
}
|
||
if (file.ext === 'doc' || file.ext === 'docx') {
|
||
img = '../../../images/docx.png';
|
||
} else if (file.ext === 'xls' || file.ext === 'xlsx') {
|
||
img = '../../../images/xlsx.png';
|
||
} else if (file.ext === 'pdf') {
|
||
img = '../../../images/pdf.png';
|
||
} else {
|
||
return '<img class="img" style="width: 130px;height: 120px;" data-index=' + index + ' data-name=' + file.name + ' src=' + result + '>';
|
||
}
|
||
html += '<div class="layout upload-file" data-index=' + index + '>' +
|
||
'<img src="' + img + '">' +
|
||
'<p style="text-align: center;font-size:12px;">' + file.name + '</p>' +
|
||
'</div>';
|
||
return html;
|
||
}
|
||
|
||
// ========== 保留+优化:附件删除逻辑(兼容回显/新增,收集delIdArr) ==========
|
||
$(document).on("click", ".file-iteme .handle", function (event) {
|
||
event.stopPropagation();
|
||
let $this = $(this);
|
||
let $parent = $this.parent();
|
||
let fileId = $parent.attr('data-file-id'); // 回显文件的ID
|
||
let index = $this.next().attr('data-index'); // 新增文件的索引
|
||
|
||
// 1. 收集要删除的文件ID(用于后端删除)
|
||
if (fileId) {
|
||
delIdArr.push(fileId); // 存储要删除的旧文件ID
|
||
}
|
||
|
||
// 2. 过滤fileList数组
|
||
let newFileList = [];
|
||
$.each(fileList, function (inx, ele) {
|
||
// 排除要删除的文件(新增文件按index,回显文件按fileId)
|
||
if ((index && index != ele.index) || (fileId && ele.fileId != fileId)) {
|
||
newFileList.push(ele);
|
||
}
|
||
});
|
||
|
||
// 3. 更新fileList
|
||
fileList = newFileList;
|
||
// 4. 删除DOM
|
||
$parent.remove();
|
||
});
|
||
|
||
function saveData2() {
|
||
$('#formSubmit').trigger('click')
|
||
}
|
||
|
||
// ========== 保留+核心修改:submitApply(delFileId逗号分隔) ==========
|
||
function submitApply(data) {
|
||
// 校验附件证明是否上传(保留:兼容回显附件)
|
||
console.log('fileList:', fileList)
|
||
let totalFileCount = fileList.length;
|
||
if (totalFileCount === 0) {
|
||
return layer.msg('请上传付款单', {icon: 7});
|
||
}
|
||
if (jjDataArr.length === 0) {
|
||
return layer.msg('请选择需求计划', {icon: 7});
|
||
}
|
||
if (allDataList.length === 0) {
|
||
return layer.msg('用车明细数据为空,无法提交', {icon: 7});
|
||
}
|
||
|
||
data.field.supId = objParam.supId;
|
||
data.field.id = objParam.id; // 修改操作必须传主键ID
|
||
// ========== 核心修改:delFileId用逗号分隔 ==========
|
||
data.field.delFileId = delIdArr.join(','); // 数组转逗号分隔字符串
|
||
console.log('delFileId(逗号分隔):', data.field.delFileId); // 调试用
|
||
|
||
let planList = [], detailsList = [];
|
||
$.each(jjDataArr, function (index, item) {
|
||
let obj = {
|
||
id: item.id || '',
|
||
planId: item.planId || item.id,
|
||
supId: objParam.supId,
|
||
money: item.money,
|
||
type: item.type || '1',
|
||
proId: item.proId || '',
|
||
carNum: item.carNum || item.needNum || 0
|
||
};
|
||
planList.push(obj);
|
||
})
|
||
|
||
const actualValues = getEditedActualValues();
|
||
|
||
$.each(allDataList, function (index, item) {
|
||
const carActual = actualValues.carActualList.find(v => v.outDetailId == item.id); // 普通车辆
|
||
const craneActual = actualValues.craneActualList.find(v => v.outDetailId == item.id); // 吊车
|
||
let obj = {
|
||
id: item.id || '',
|
||
planId: item.planId || '',
|
||
type: item.type || '车辆',
|
||
supId: item.supId || objParam.supId,
|
||
proId: item.proId || '',
|
||
money: item.cost || item.money || 0,
|
||
outId: item.outId || '',
|
||
exeGls: carActual?.exeGls || item.exeGls || '',
|
||
inMoney: carActual?.inMoney || craneActual?.inMoney || '',
|
||
exeDay: craneActual?.exeDay || item.exeDay || '',
|
||
outDetailId: item.id || '',
|
||
modelId: item.modelId || '',
|
||
ton: item.ton || 0
|
||
};
|
||
detailsList.push(obj);
|
||
})
|
||
data.field.planList = planList;
|
||
data.field.detailsList = detailsList;
|
||
|
||
let formData = new FormData();
|
||
//遍历最终文件集合(仅上传新增文件)
|
||
for (let i = 0; i < fileList.length; i++) {
|
||
let fileItem = fileList[i];
|
||
if (!fileItem.isExist && fileItem.file) {
|
||
formData.append("file[]", fileItem.file)
|
||
}
|
||
}
|
||
formData.append('params', JSON.stringify(data.field));
|
||
console.log("提交参数:", data.field); // 调试用
|
||
|
||
let loadingMsg = layer.msg('正在提交保存,请稍等...', {icon: 16, shade: 0.01, time: '0'});
|
||
let url = dataUrl + 'backstage/carBalance/updateBalanceData';
|
||
ajaxRequestByUploadFile(url, formData, function () {
|
||
$('.save').addClass("layui-btn-disabled").attr("disabled", true);
|
||
$('.cancel').addClass("layui-btn-disabled").attr("disabled", true);
|
||
}, function (result) {
|
||
layer.close(loadingMsg);
|
||
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
|
||
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
|
||
if (result.code === 200) {
|
||
parent.layer.msg(result.msg, {icon: 1});
|
||
closePage(1);
|
||
} else {
|
||
layer.msg(result.msg, {icon: 2});
|
||
}
|
||
}, function (xhr, status, error) {
|
||
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);
|
||
errorFn(xhr, status, error)
|
||
}, null);
|
||
}
|
||
|
||
// 选择需求计划单据
|
||
function chooseFitType() {
|
||
let params = {
|
||
contractId: objParam.contractId,
|
||
supId: objParam.supId,
|
||
planId: planId,
|
||
jjDataArr: JSON.stringify(jjDataArr)
|
||
};
|
||
openIframeByParamObj("choose_plan_code_list", '选择需要付款的需求计划编号', "./choose_plan_code_list.html", '92%', '95%', params);
|
||
}
|
||
|
||
// 需求计划单据赋值
|
||
function addFitDatas(data, planIdArr) {
|
||
jjDataArr = JSON.parse(data);
|
||
console.error(jjDataArr);
|
||
|
||
let money = 0;
|
||
$.each(jjDataArr, function (index, item) {
|
||
const dataNum = item.money ? item.money : 0;
|
||
const num = Number(dataNum);
|
||
const cents = Math.round(num * 1000);
|
||
money += cents;
|
||
})
|
||
$('#money').val(money / 1000);
|
||
if (!planId) {
|
||
$('#chooseValue').val('选择数据(已选择 ' + planIdArr.length + ' 条)');
|
||
$('#no_data_title').css({'display': 'none'});
|
||
$('#search-info').removeAttr('style');
|
||
$('#table-box').removeAttr('style');
|
||
planId = planIdArr.join('@');
|
||
getPayCarDetails();
|
||
} else {
|
||
$('#chooseValue').val('选择数据(已选择 ' + planIdArr.length + ' 条)');
|
||
planId = planIdArr.join('@');
|
||
getPayCarDetails();
|
||
}
|
||
}
|
||
|
||
// 派车录入详情明细-派车资料等明细
|
||
function getPayCarDetails(id) {
|
||
let encryptedData = {planId: planId};
|
||
let url = dataUrl + 'backstage/carBalance/getPayCarDetails?encryptedData=' + encodeURIComponent(JSON.stringify(encryptedData));
|
||
ajaxRequest(url, "GET", null, true, function () {
|
||
}, function (result) {
|
||
if (result.code === 200) {
|
||
dataObj = result.data;
|
||
setTableData(result.data);
|
||
}
|
||
}, function (xhr, status, error) {
|
||
errorFn(xhr, status, error)
|
||
}, null);
|
||
|
||
function setTableData(list) {
|
||
allDataList.splice(0, allDataList.length);
|
||
allDataList = 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 = formatToTwoDecimals(item.gls) || 0.00; // 实际公里数初始=预估公里数
|
||
// const actualMoney = formatToTwoDecimals(0); // 实际金额初始=预估金额
|
||
|
||
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>" + item.gls + "</td>" +
|
||
|
||
"<td><input type='number' class='form-control actual-gls' value='" + actualGls +
|
||
"' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></td>" +
|
||
|
||
"<td>" + item.glsPrice + "</td>" +
|
||
"<td> ¥ " + (item.glsMoney ? item.glsMoney : 0) + "</td>" +
|
||
|
||
// "<td><input type='number' class='form-control actual-money' value='" + actualMoney +
|
||
// "' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></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>" +
|
||
"</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.planDay || 0;
|
||
const actualDcMoney = formatToTwoDecimals(0);
|
||
|
||
html += '<tr>' +
|
||
'<td>' + item.type + '</td>' +
|
||
'<td>' + item.name + '</td>' +
|
||
'<td>' + item.model + '</td>' +
|
||
'<td>' + item.carNum + '</td>' +
|
||
'<td>' + item.useAddress + '</td>' +
|
||
'<td>' + item.planDay + '</td>' +
|
||
"<td><input type='number' class='form-control actual-dc-planDay' value='" + actualPlanDay +
|
||
"' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></td>" +
|
||
'<td>' + setZlPrice(item) + '</td>' +
|
||
'<td> ¥ ' + item.dcMoney + '</td>' +
|
||
|
||
"<td><input type='number' class='form-control actual-dc-money' value='" + actualDcMoney +
|
||
"' style='width: 100%; padding: 2px; border: 1px solid #ddd;' data-id='" + item.id + "'></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>" +
|
||
'</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 += '<p>' + item.monthPrice + '(' + item.dcUnit + ')' + '</p>';
|
||
} else {
|
||
html += '<p>' + item.dayPrice + '(' + item.dcUnit + ')' + '</p>';
|
||
}
|
||
if (item.isOutSet === 1) {
|
||
html += '<p>' + (item.jcMoney ? item.jcMoney : 0) + '(进出场费)</p>'
|
||
}
|
||
return html;
|
||
}
|
||
} else {
|
||
$('#dispatch-car-table2').css('display', 'none');
|
||
}
|
||
}
|
||
}
|
||
|
||
// 需求计划详情
|
||
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 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 getEditedActualValues() {
|
||
// 存储最终收集的实际值
|
||
let actualValues = {
|
||
carActualList: [], // 普通车辆实际值(实际公里数、实际金额)
|
||
craneActualList: [] // 吊车实际值(实际金额)
|
||
};
|
||
|
||
// 1. 收集普通车辆的实际公里数、实际金额
|
||
$('#dispatch-car-table tr:not(:first)').each(function () {
|
||
const $tr = $(this);
|
||
const itemId = $tr.find('.actual-gls').data('id'); // 获取数据ID
|
||
if (!itemId) return; // 无ID则跳过
|
||
|
||
// 修复列索引:实际公里数输入框在td:eq(9),预估公里数在td:eq(8)
|
||
const actualGls = $tr.find('.actual-gls').val().trim() || $tr.find('td:eq(8)').text().trim() || '0.00';
|
||
const actualMoney = $tr.find('.actual-money').val()?.trim() || '0.00';
|
||
|
||
actualValues.carActualList.push({
|
||
outDetailId: itemId,
|
||
exeGls: formatToTwoDecimals(actualGls),
|
||
inMoney: formatToTwoDecimals(actualMoney)
|
||
});
|
||
});
|
||
|
||
// 2. 收集吊车的实际金额
|
||
$('#dispatch-car-table2 tr:not(:first)').each(function () {
|
||
const $tr = $(this);
|
||
const itemId = $tr.find('.actual-dc-money').data('id'); // 获取数据ID
|
||
if (!itemId) return; // 无ID则跳过
|
||
|
||
const actualPlanDay = $tr.find('.actual-dc-planDay').val().trim() || $tr.find('td:eq(5)').text().trim() || '0';
|
||
const actualDcMoney = $tr.find('.actual-dc-money').val().trim() || '0.00';
|
||
|
||
actualValues.craneActualList.push({
|
||
outDetailId: itemId,
|
||
inMoney: formatToTwoDecimals(actualDcMoney),
|
||
exeDay: actualPlanDay
|
||
});
|
||
});
|
||
return actualValues;
|
||
}
|
||
|
||
// 全局工具函数:格式化数字为两位小数(处理空值、非数字)
|
||
function formatToTwoDecimals(num) {
|
||
if (num === null || num === undefined || num === '' || isNaN(Number(num))) return '0.00';
|
||
return Number(num).toFixed(2);
|
||
}
|
||
|
||
// 输入框正则校验(仅正数 + 最多两位小数 + 不超过1亿元)
|
||
$(document).on('input', '.actual-gls, .actual-money, .actual-dc-money', function () {
|
||
this.value = this.value
|
||
.replace(/[^0-9.]/g, '') // 过滤非法字符
|
||
.replace(/\.{2,}/g, '.') // 单个小数点
|
||
.replace(/^0+(?=\d)/, ''); // 去除开头多余0
|
||
|
||
if (this.value.indexOf('.') !== -1) {
|
||
const parts = this.value.split('.');
|
||
this.value = parts[0] + '.' + parts[1].substring(0, 2);
|
||
}
|
||
|
||
const numValue = Number(this.value || 0);
|
||
const maxAmount = 100000000;
|
||
if (numValue > maxAmount) {
|
||
this.value = maxAmount.toFixed(2);
|
||
}
|
||
});
|
||
|
||
// 失焦格式化
|
||
$(document).on('blur', '.actual-gls, .actual-money, .actual-dc-money', function () {
|
||
this.value = formatToTwoDecimals(this.value);
|
||
});
|
||
|
||
// 关闭页面
|
||
function closePage(type) {
|
||
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
|
||
if (type == 1) {
|
||
window.parent.reloadData();
|
||
}
|
||
parent.layer.close(index); // 再执行关闭
|
||
}
|