维修记录重复及价格计算优化

This commit is contained in:
hayu 2025-12-30 12:27:04 +08:00
parent 87deb0ceab
commit 8408fb9bac
3 changed files with 323 additions and 47 deletions

View File

@ -431,9 +431,13 @@ const saveCode = () => {
}
//
const saveCodeApi = async () => {
uni.showLoading({
title: '提交中...',
mask: true
})
try {
//
rowData.value.repairDeviceList = queryParams.value.selectedDevices
console.log("llllllllllllllll",queryParams.value)
//
for (let i = 0; i < rowData.value.repairDeviceList.length; i++) {
//
@ -462,15 +466,30 @@ const saveCodeApi = async () => {
rowData.value.repairDeviceList[i].repairType = 1;
}
console.log(rowData.value.repairDeviceList)
saveLossAssessmentRow(rowData.value.repairDeviceList).then(async (response) => {
console.log("uuuuuuuuuuu",response)
const response = await saveLossAssessmentRow(rowData.value.repairDeviceList)
// Loading
uni.hideLoading()
if (response.code == 200) {
uni.showToast({ title: '定损成功', icon: 'none' })
uni.navigateBack({
delta: 2, //
})
}
} else {
uni.showToast({
title: response.msg || '提交失败',
icon: 'none'
})
}
} catch (error) {
// Loading
uni.hideLoading()
console.error('定损提交失败:', error)
uni.showToast({
title: '网络错误,请重试',
icon: 'none'
})
}
}

View File

@ -226,6 +226,83 @@ import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
import PreviewImg from '@/components/PreviewImg/index.vue'
// const query = defineProps() //
// const queryParams = JSON.parse(query.queryParams)
//
const floatUtils = {
//
add: (...nums) => {
return parseFloat(nums.reduce((sum, num) => {
const value = Number(num || 0);
if (isNaN(value)) return sum;
return parseFloat((sum + value).toFixed(6));
}, 0).toFixed(6));
},
//
subtract: (a, b) => {
const aVal = Number(a || 0);
const bVal = Number(b || 0);
if (isNaN(aVal) || isNaN(bVal)) return 0;
return parseFloat((aVal - bVal).toFixed(6));
},
//
isEqual: (a, b) => {
const aVal = Number(a);
const bVal = Number(b);
if (isNaN(aVal) || isNaN(bVal)) return false;
return Math.abs(aVal - bVal) < 1e-10;
},
//
format: (num) => {
const value = Number(num);
if (isNaN(value)) return 0;
const formatted = parseFloat(value.toFixed(6));
return Math.abs(formatted) < 1e-10 ? 0 : formatted;
},
//
multiply: (a, b) => {
const aVal = Number(a || 0);
const bVal = Number(b || 0);
if (isNaN(aVal) || isNaN(bVal)) return 0;
return parseFloat((aVal * bVal).toFixed(6));
},
// 0
isEmptyOrZero: (num) => {
const value = Number(num);
if (isNaN(value)) return true;
return Math.abs(value) < 1e-10;
},
//
isEmpty: (num) => {
// null undefined
if (num === null || num === undefined) {
return true;
}
//
if (typeof num === 'string' && num.trim() === '') {
return true;
}
//
const value = Number(num);
// NaN
if (isNaN(value)) {
return true;
}
// 00
// false 0
return false;
},
};
const queryParams = ref({})
const rowData = ref({})
onLoad((options) => {
@ -429,6 +506,53 @@ const deleteImage2 = (index) => {
fileData.value.fileList.splice(index, 1)
}
//
const validateParts = () => {
let isValid = true;
let errorMessage = "";
for (let i = 0; i < partItems.value.length; i++) {
const item = partItems.value[i];
// 0
const partPrice = floatUtils.format(item.partPrice);
const partNum = floatUtils.format(item.partNum);
// 0
if (!floatUtils.isEmptyOrZero(partPrice)) {
// 0
if (floatUtils.isEmptyOrZero(partNum)) {
isValid = false;
errorMessage = `${i + 1}行配件单价已填写,请填写配件数量!`;
break;
}
}
// 0
if (!floatUtils.isEmptyOrZero(partNum)) {
// 0
if (floatUtils.isEmpty(partPrice)) {
isValid = false;
errorMessage = `${i + 1}行配件数量已填写,请填写配件单价!`;
break;
}
}
// //
// if ((!floatUtils.isEmptyOrZero(partNum) || !floatUtils.isEmptyOrZero(partPrice)) && !item.partId) {
// isValid = false;
// errorMessage = `${i + 1}`;
// break;
// }
}
if (!isValid) {
uni.showToast({ title: errorMessage, icon: 'none' });
}
return isValid;
}
//
const saveNumAll = async () => {
@ -445,6 +569,16 @@ const saveNumAll = async () => {
// uni.showToast({ title: ' 0 ', icon: 'none' })
// }
else {
//
if (!validateParts()) {
return;
}
uni.showLoading({
title: '提交中...',
mask: true
})
try {
//
rowData.value.repairDeviceList[0].repairList=[
{
@ -464,61 +598,135 @@ const saveNumAll = async () => {
})
}
console.log("yyyyyyyyyy",rowData.value)
saveLossAssessmentRow(rowData.value.repairDeviceList).then(async (response) => {
console.log("yxxxxxyyyy",response)
if (response.code === 200) {
const response = await saveLossAssessmentRow(rowData.value.repairDeviceList)
// Loading
uni.hideLoading()
if (response.code == 200) {
uni.showToast({ title: '定损成功', icon: 'none' })
setTimeout(() => {
uni.navigateBack({
delta: 1, //
})
}, 1000)
}
} else {
uni.showToast({
title: response.msg || '提交失败',
icon: 'none'
})
}
// saveLossAssessmentRow(rowData.value.repairDeviceList).then(async (response) => {
// console.log("yxxxxxyyyy",response)
// if (response.code === 200) {
// uni.showToast({ title: '', icon: 'none' })
// setTimeout(() => {
// uni.navigateBack({
// delta: 1, //
// })
// }, 1000)
// }
// })
} catch (error) {
// Loading
uni.hideLoading()
console.error('定损提交失败:', error)
uni.showToast({
title: '网络错误,请重试',
icon: 'none'
})
}
}
}
// 使
// const maxRepairNum = computed(() => {
// return queryParams.value.typeRepairNum - queryParams.value.typeRepairedNum - queryParams.value.typeScrapNum;
// });
const maxRepairNum = computed(() => {
return queryParams.value.typeRepairNum - queryParams.value.typeRepairedNum - queryParams.value.typeScrapNum;
const total = floatUtils.subtract(
queryParams.value.typeRepairNum,
floatUtils.add(queryParams.value.typeRepairedNum, queryParams.value.typeScrapNum)
);
return floatUtils.format(total);
});
//
// const currentTotalRepairNum = computed(() => {
// let total = 0;
// partItems.value.forEach(item => {
// total += Number(item.repairNum) || 0;
// });
// return total;
// });
const currentTotalRepairNum = computed(() => {
let total = 0;
partItems.value.forEach(item => {
total += Number(item.repairNum) || 0;
});
return total;
return partItems.value.reduce((sum, item) => {
return floatUtils.add(sum, item.repairNum || 0);
}, 0);
});
// change
const repairCheckNum1 = (index) => {
setTimeout(() => {
const item = partItems.value[index];
if (queryParams.value.unitValue === 1) {
item.repairNum = Number(String(item.repairNum).replace(/[^\d.]/g, ''));
} else {
item.repairNum = Number(String(item.repairNum).replace(/[^\d]/g, ''));
}
if (Number(item.repairNum) < 0) {
item.repairNum = 0;
}
// 使
const originalValue = item.repairNum;
const cleanedValue = Number(String(originalValue).replace(/[^\d.]/g, ''));
const formattedValue = floatUtils.format(cleanedValue);
if (currentTotalRepairNum.value > maxRepairNum.value) {
item.repairNum = formattedValue < 0 ? 0 : formattedValue;
//
const currentTotal = partItems.value.reduce((sum, it, idx) => {
const value = idx === index ? item.repairNum : (it.repairNum || 0);
return floatUtils.add(sum, value);
}, 0);
const maxNum = maxRepairNum.value;
if (currentTotal > maxNum && !floatUtils.isEqual(currentTotal, maxNum)) {
uni.showToast({
title: '已达到当前物资最大定损数量!',
icon: 'none',
});
//
const excess = currentTotalRepairNum.value - maxRepairNum.value;
//
item.repairNum = Math.max(0, item.repairNum - excess);
//
const excess = floatUtils.subtract(currentTotal, maxNum);
//
const newValue = floatUtils.format(
floatUtils.subtract(item.repairNum, excess)
);
//
item.repairNum = Math.max(0, newValue);
}
//
calculateCostAll();
// item.repairNum = Number(String(item.repairNum).replace(/[^\d.]/g, ''));
// if (Number(item.repairNum) < 0) {
// item.repairNum = 0;
// }
//
// if (currentTotalRepairNum.value > maxRepairNum.value) {
// uni.showToast({
// title: '',
// icon: 'none',
// });
// //
// const excess = currentTotalRepairNum.value - maxRepairNum.value;
// //
// item.repairNum = Math.max(0, item.repairNum - excess);
// }
//
// //
// calculateCostAll();
}, 500);
};

View File

@ -744,6 +744,55 @@ const saveNumAll = async () => {
return
}
// ======= =======
// 1. 0
let isPartValid = true;
for (let i = 0; i < partItems.value.length; i++) {
const item = partItems.value[i];
// trim()
const partIdStr = String(item.partId || '');
//
const isPartNotEmpty = partIdStr.trim() !== '';
// 0
const partNum = Number(item.partNum) || 0;
// 0
if (isPartNotEmpty && partNum <= 0) {
uni.showToast({ title: `内部维修第${i+1}个配件数量必须大于0`, icon: 'none' })
isPartValid = false;
break; //
}
}
//
if (!isPartValid) {
loading.value = false;
return;
}
// 2. 0
let isMidPartValid = true;
for (let i = 0; i < partItemsMiddle.value.length; i++) {
const item = partItemsMiddle.value[i];
//
const partNameStr = String(item.partName || '');
//
const isPartNotEmpty = partNameStr.trim() !== '';
// 0
const partNum = Number(item.partNum) || 0;
// 0
if (isPartNotEmpty && partNum <= 0) {
uni.showToast({ title: `返厂维修第${i+1}个配件数量必须大于0`, icon: 'none' })
isMidPartValid = false;
break; //
}
}
//
if (!isMidPartValid) {
loading.value = false;
return;
}
// ======= =======
rowData.value.repairDeviceList[0].repairList = [
{ repairer: repairPerson.value }