gz_car_ui/js/car_settlement/child/payment_form.js

436 lines
17 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, fileList = new Array(), imgListUp = new Array();
let form, laydate, layer, upload, table, util;
let pageNum = 1, tableIns; // 定义分页
let jjDataArr = []; // 清单数据
let delIdArr = [];
let planId = ''; // 计划ID
let allDataList = [];
function setParams(obj) {
objParam = JSON.parse(obj);
$('#supName').val(objParam.supName);
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);
}
});
}
});
});
}
// 设置文件类型
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;
}
// 删除文件
$(document).on("click", ".file-iteme .handle", function (event) {
imgListUp.splice(0, imgListUp.length);
let index = $(this).next().attr('data-index');
$.each(fileList, function (inx, ele) {
//对比删除文件索引
//将未删除的存入新集合
if (index != ele.index) {
imgListUp.push(ele);
}
});
$(this).parent().remove();
//将新文件集合替换老集合
fileList.splice(0, fileList.length);
$.each(imgListUp, function (inx, ele) {
fileList.push(ele)
});
});
function saveData2() {
$('#formSubmit').trigger('click')
}
// 提交
function submitApply(data) {
// 校验附件证明是否上传
if (fileList.length === 0) {
return layer.msg('请上传付款单', { icon: 7 });
}
if (jjDataArr.length === 0) {
return layer.msg('请选择需求计划', { icon: 7 });
}
data.field.supId = objParam.supId;
let planList = [],detailsList = [];
$.each(jjDataArr, function (index, item) {
let obj = {
// id: item.id,
planId: item.id,
supId: objParam.supId,
money: item.money,
type: item.type,
proId: item.proId,
carNum: item.needNum
};
planList.push(obj);
})
const actualValues = getEditedActualValues();
data.field.actualValues = actualValues;
$.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,
proId: item.proId,
money: item.cost,
outId: item.outId,
exeGls: carActual?.exeGls || '',
inMoney: carActual?.inMoney || craneActual?.inMoney || '',
exeDay: craneActual?.exeDay || '',
};
detailsList.push(obj);
})
data.field.planList = planList;
data.field.detailsList = detailsList;
let formData = new FormData();
//遍历最终文件集合
for (let i = 0; i < fileList.length; i++) {
formData.append("file[]", fileList[i].file)
}
formData.append('params', JSON.stringify(data.field));
console.log(jjDataArr);
console.log(data.field);
let loadingMsg = layer.msg('正在提交保存,请稍等...', { icon: 16, shade: 0.01, time: '0' });
let url = dataUrl + 'backstage/carBalance/addBalanceData';
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 = item.gls || 0; // 实际公里数初始=预估公里数
const actualMoney = item.glsMoney || 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 = item.dcMoney || 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则跳过
// 获取输入框中的实际值(为空则用原值)
const actualGls = $tr.find('.actual-gls').val() || $tr.find('td:eq(9)').text(); // 实际公里数,为空取预估公里数
const actualMoney = $tr.find('.actual-money').val() || $tr.find('td:eq(12)').text().replace('¥ ', ''); // 实际金额,为空取预估金额
actualValues.carActualList.push({
outDetailId: itemId,
exeGls: actualGls,
inMoney: 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() || $tr.find('td:eq(6)').text();
const actualDcMoney = $tr.find('.actual-dc-money').val() || $tr.find('td:eq(9)').text().replace('¥ ', '');
actualValues.craneActualList.push({
outDetailId: itemId,
inMoney: actualDcMoney,
exeDay:actualPlanDay
});
});
return actualValues;
}
// 关闭页面
function closePage(type) {
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
if (type == 1) {
window.parent.reloadData();
}
parent.layer.close(index); // 再执行关闭
}