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

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 () => { const saveCodeApi = async () => {
uni.showLoading({
title: '提交中...',
mask: true
})
try {
// //
rowData.value.repairDeviceList = queryParams.value.selectedDevices rowData.value.repairDeviceList = queryParams.value.selectedDevices
console.log("llllllllllllllll",queryParams.value)
// //
for (let i = 0; i < rowData.value.repairDeviceList.length; i++) { for (let i = 0; i < rowData.value.repairDeviceList.length; i++) {
// //
@ -462,15 +466,30 @@ const saveCodeApi = async () => {
rowData.value.repairDeviceList[i].repairType = 1; rowData.value.repairDeviceList[i].repairType = 1;
} }
console.log(rowData.value.repairDeviceList) console.log(rowData.value.repairDeviceList)
saveLossAssessmentRow(rowData.value.repairDeviceList).then(async (response) => { const response = await saveLossAssessmentRow(rowData.value.repairDeviceList)
console.log("uuuuuuuuuuu",response) // Loading
uni.hideLoading()
if (response.code == 200) { if (response.code == 200) {
uni.showToast({ title: '定损成功', icon: 'none' }) uni.showToast({ title: '定损成功', icon: 'none' })
uni.navigateBack({ uni.navigateBack({
delta: 2, // 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' import PreviewImg from '@/components/PreviewImg/index.vue'
// const query = defineProps() // // const query = defineProps() //
// const queryParams = JSON.parse(query.queryParams) // 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 queryParams = ref({})
const rowData = ref({}) const rowData = ref({})
onLoad((options) => { onLoad((options) => {
@ -429,6 +506,53 @@ const deleteImage2 = (index) => {
fileData.value.fileList.splice(index, 1) 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 () => { const saveNumAll = async () => {
@ -445,6 +569,16 @@ const saveNumAll = async () => {
// uni.showToast({ title: ' 0 ', icon: 'none' }) // uni.showToast({ title: ' 0 ', icon: 'none' })
// } // }
else { else {
//
if (!validateParts()) {
return;
}
uni.showLoading({
title: '提交中...',
mask: true
})
try {
// //
rowData.value.repairDeviceList[0].repairList=[ rowData.value.repairDeviceList[0].repairList=[
{ {
@ -464,61 +598,135 @@ const saveNumAll = async () => {
}) })
} }
console.log("yyyyyyyyyy",rowData.value) console.log("yyyyyyyyyy",rowData.value)
saveLossAssessmentRow(rowData.value.repairDeviceList).then(async (response) => { const response = await saveLossAssessmentRow(rowData.value.repairDeviceList)
console.log("yxxxxxyyyy",response) // Loading
if (response.code === 200) { uni.hideLoading()
if (response.code == 200) {
uni.showToast({ title: '定损成功', icon: 'none' }) uni.showToast({ title: '定损成功', icon: 'none' })
setTimeout(() => { setTimeout(() => {
uni.navigateBack({ uni.navigateBack({
delta: 1, // delta: 1, //
}) })
}, 1000) }, 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(() => { 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(() => { const currentTotalRepairNum = computed(() => {
let total = 0; return partItems.value.reduce((sum, item) => {
partItems.value.forEach(item => { return floatUtils.add(sum, item.repairNum || 0);
total += Number(item.repairNum) || 0; }, 0);
});
return total;
}); });
// change // change
const repairCheckNum1 = (index) => { const repairCheckNum1 = (index) => {
setTimeout(() => { setTimeout(() => {
const item = partItems.value[index]; 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({ uni.showToast({
title: '已达到当前物资最大定损数量!', title: '已达到当前物资最大定损数量!',
icon: 'none', icon: 'none',
}); });
//
const excess = currentTotalRepairNum.value - maxRepairNum.value; //
// const excess = floatUtils.subtract(currentTotal, maxNum);
item.repairNum = Math.max(0, item.repairNum - excess);
//
const newValue = floatUtils.format(
floatUtils.subtract(item.repairNum, excess)
);
//
item.repairNum = Math.max(0, newValue);
} }
// //
calculateCostAll(); 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); }, 500);
}; };

View File

@ -744,6 +744,55 @@ const saveNumAll = async () => {
return 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 = [ rowData.value.repairDeviceList[0].repairList = [
{ repairer: repairPerson.value } { repairer: repairPerson.value }