refactor(report): 优化事件列表打印功能

- 重构工作压力和气瓶容积的处理逻辑,提高数据处理的准确性和灵活性
- 改进产品信息处理方法,优化 ID 匹配逻辑,增加部分匹配功能
- 新增车辆 VIN 码处理方法,用于提取和展示车辆 VIN 信息
- 优化页面布局,调整保存并下载按钮的位置
master
Tuzki 6 months ago
parent 41a5a50a84
commit b0f6217851
  1. 355
      src/views/report/eventList/printDemo.vue

@ -56,7 +56,8 @@
@click="mockFetchData">重新识别</el-button>
<EquipmentRegistrationForm ref="ERF" v-else :initialData="formData" />
</div>
<el-button style="position: absolute;bottom: 20px;z-index: 9999;right: 50%;transform: translateX(50%);" @click="exportToWord">保存并下载</el-button>
<el-button style="position: absolute;bottom: 20px;z-index: 9999;right: 50%;transform: translateX(50%);"
@click="exportToWord">保存并下载</el-button>
</div>
@ -217,19 +218,29 @@
//
processNominalPressure(formData) {
try {
//
const validEntries = formData.certificateList
.filter(item =>
item.type === 'productQualified' &&
item.nominalWorkingPressure?.trim()
)
.map(item => ({
original: item.nominalWorkingPressure,
numeric: parseFloat(item.nominalWorkingPressure)
}))
.filter(entry => !isNaN(entry.numeric));
// 1.
const collectEntries = (type) => {
return formData.certificateList
.filter(item =>
item.type === type &&
item.nominalWorkingPressure?.trim()
)
.map(item => ({
original: item.nominalWorkingPressure,
numeric: parseFloat(item.nominalWorkingPressure)
}))
.filter(entry => !isNaN(entry.numeric));
};
// 2.
let validEntries = collectEntries('certificateOfApproval');
// 3.
if (validEntries.length === 0) {
validEntries = collectEntries('productQualified');
}
//
// 4.
if (validEntries.length > 0) {
const maxEntry = validEntries.reduce((a, b) =>
a.numeric > b.numeric ? a : b
@ -263,22 +274,41 @@
formData.contractor = '';
}
},
//
//
processCylinderVolume(formData) {
try {
// 1.
const validVolumes = formData.certificateList
// 1.
const processVolume = (item) => {
const volumeStr = item.cylinderVolume
.replace(/L/gi, '')
.replace(/,/g, '.');
return parseFloat(volumeStr);
};
// 2.
let validVolumes = formData.certificateList
.filter(item =>
item.type === 'productQualified' &&
item.cylinderVolume?.trim()
)
.map(item => parseFloat(item.cylinderVolume))
.map(processVolume)
.filter(num => !isNaN(num));
// 2.
// 3.
if (validVolumes.length === 0) {
validVolumes = formData.certificateList
.filter(item =>
item.type === 'certificateOfApproval' &&
item.cylinderVolume?.trim()
)
.map(processVolume)
.filter(num => !isNaN(num));
}
// 4.
if (validVolumes.length > 0) {
const sum = validVolumes.reduce((acc, cur) => acc + cur, 0);
formData.cylinderVolume = sum.toFixed(2); //
formData.cylinderVolume = sum.toFixed(2);
} else {
formData.cylinderVolume = 0;
}
@ -315,37 +345,60 @@
//
processInfoList(formData) {
try {
// 1. certificateOfApprovalproductId
const longestApprovalId = formData.certificateList
.filter(item => item.type === 'certificateOfApproval')
.map(item => item.productId?.trim() || '')
.reduce((maxId, current) =>
current.length > maxId.length ? current : maxId,
'');
// 1. productId
let availableIds = [];
// certificateOfApprovalID
const approvalIds = formData.certificateList
.filter(item => item.type === 'certificateOfApproval' && item.productId?.trim())
.map(item => item.productId.trim());
// 2. IDID
const availableIds = longestApprovalId.includes('/')
? longestApprovalId.split('/').map(s => s.trim())
: [longestApprovalId];
if (approvalIds.length > 0) {
// ID
const longestId = approvalIds.reduce((a, b) => a.length > b.length ? a : b);
availableIds = longestId.includes('/')
? longestId.split('/').map(s => s.trim())
: [longestId];
}
// productQualifiedID
else {
availableIds = formData.certificateList
.filter(item =>
item.type === 'productQualified' &&
item.productId?.trim()
)
.map(item => item.productId.trim())
.filter(Boolean);
}
// 3.
// 2.
const supervisionItems = formData.certificateList
.filter(item => item.type === 'supervisionAndInspection')
.slice(0, 3);
// 4. IDIDID
// 3. ID
let remainingIds = [...availableIds];
formData.infoList = supervisionItems.map(item => {
const supervisionProductId = item.productId?.trim() || '';
const supervisionProductId = item.productBatchNumber?.trim() || '';
let matchedId = '';
//
//
if (supervisionProductId) {
// ......
}
// supervisionproductIdID
else if (remainingIds.length > 0) {
const exactMatch = remainingIds.find(id => id === supervisionProductId);
const partialMatch = remainingIds.find(id =>
id.includes(supervisionProductId) ||
supervisionProductId.includes(id)
);
if (exactMatch) {
matchedId = exactMatch;
remainingIds = remainingIds.filter(id => id !== exactMatch);
} else if (partialMatch) {
matchedId = partialMatch;
remainingIds = remainingIds.filter(id => id !== partialMatch);
}
} else if (remainingIds.length > 0) {
matchedId = remainingIds.shift();
}
@ -357,13 +410,32 @@
};
});
//
formData.infoList = Array.isArray(formData.infoList) ? formData.infoList : [];
} catch (e) {
console.error('infoList处理失败:', e);
formData.infoList = [];
}
},
// VIN
processVehicleVin(formData) {
try {
// 1.
const validVins = formData.certificateList
.filter(item =>
item.type === 'certificateOfApproval' &&
item.vehicleVin?.trim() //
)
.map(item => item.vehicleVin.trim());
// 2.
formData.vehicleVin = validVins.length > 0
? validVins[0]
: '';
} catch (e) {
console.error('车辆VIN码处理失败:', e);
formData.vehicleVin = '';
}
},
//
async mockFetchData() {
// setTimeout(() => {
@ -490,6 +562,7 @@
certificateList: [], //
infoList: []
});
console.log('合并结果', mergedData);
// const mergedData = {
// registrationCategory: "",
// unifiedSocialCode: "91130185MAE5XYHG9W",
@ -528,7 +601,7 @@
// unifiedSocialCode: null,
// userAddress: null,
// userUnit: null,
// vehicleVin: null,
// vehicleVin: 'LVSHJCAM6AE012342',
// }, {
// commissionDate: null,
// contractor: "XX",
@ -586,7 +659,7 @@
// unifiedSocialCode: null,
// userAddress: null,
// userUnit: null,
// vehicleVin: null,
// vehicleVin: 'LVSHJCAM6AE012345',
// }, {
// commissionDate: null,
// contractor: null,
@ -768,6 +841,205 @@
// }
// ]
// }
// const mergedData = {
// "registrationCategory": "",
// "equipmentType": "",
// "productName": "",
// "cylinderQuantity": 2,
// "fillingMedium": "CNG",
// "nominalWorkingPressure": "20MPa",
// "cylinderVolume": "100.70",
// "manufacturer": "",
// "productionDate": "",
// "productId": "",
// "internalId": "",
// "contractor": "",
// "supervisionAgency": "/ 绿",
// "userUnit": "",
// "userAddress": "鹿3",
// "unifiedSocialCode": "130185198912101360",
// "postalCode": "050200",
// "licensePlate": "A0SC80",
// "vehicleVin": "LS4ASL2K5RG809594",
// "commissionDate": "2025-02-10",
// "telephone": "",
// "safetyManager": "",
// "mobilePhone": "",
// "certificateList": [
// {
// "id": null,
// "registrationCategory": null,
// "equipmentType": "",
// "productName": "",
// "cylinderQuantity": "1",
// "fillingMedium": "CNG",
// "nominalWorkingPressure": "20MPa",
// "cylinderVolume": "70.4",
// "manufacturer": null,
// "productionDate": null,
// "productId": "C",
// "internalId": null,
// "contractor": null,
// "supervisionAgency": null,
// "userUnit": null,
// "userAddress": null,
// "unifiedSocialCode": null,
// "postalCode": null,
// "licensePlate": null,
// "vehicleVin": null,
// "commissionDate": null,
// "telephone": null,
// "safetyManager": null,
// "mobilePhone": null,
// "infoList": null,
// "createTime": null,
// "productBatchNumber": null,
// "type": "productQualified"
// },
// {
// "id": null,
// "registrationCategory": null,
// "equipmentType": "",
// "productName": "",
// "cylinderQuantity": "1",
// "fillingMedium": "CNG",
// "nominalWorkingPressure": "20MPa",
// "cylinderVolume": "30.3",
// "manufacturer": null,
// "productionDate": null,
// "productId": "NI054039",
// "internalId": null,
// "contractor": null,
// "supervisionAgency": null,
// "userUnit": null,
// "userAddress": null,
// "unifiedSocialCode": null,
// "postalCode": null,
// "licensePlate": null,
// "vehicleVin": null,
// "commissionDate": null,
// "telephone": null,
// "safetyManager": null,
// "mobilePhone": null,
// "infoList": null,
// "createTime": null,
// "productBatchNumber": null,
// "type": "productQualified"
// },
// {
// "id": null,
// "registrationCategory": null,
// "equipmentType": "",
// "productName": "",
// "cylinderQuantity": null,
// "fillingMedium": null,
// "nominalWorkingPressure": "20MPa",
// "cylinderVolume": null,
// "manufacturer": null,
// "productionDate": null,
// "productId": "NI054039/128240627132",
// "internalId": null,
// "contractor": "",
// "supervisionAgency": null,
// "userUnit": null,
// "userAddress": null,
// "unifiedSocialCode": null,
// "postalCode": null,
// "licensePlate": null,
// "vehicleVin": "LS4ASL2K5RG809594",
// "commissionDate": null,
// "telephone": null,
// "safetyManager": null,
// "mobilePhone": null,
// "infoList": null,
// "createTime": null,
// "productBatchNumber": null,
// "type": "certificateOfApproval"
// },
// {
// "id": null,
// "registrationCategory": null,
// "equipmentType": "",
// "productName": "",
// "cylinderQuantity": null,
// "fillingMedium": null,
// "nominalWorkingPressure": null,
// "cylinderVolume": null,
// "manufacturer": "",
// "productionDate": "20240901",
// "productId": null,
// "internalId": null,
// "contractor": null,
// "supervisionAgency": "",
// "userUnit": null,
// "userAddress": null,
// "unifiedSocialCode": null,
// "postalCode": null,
// "licensePlate": null,
// "vehicleVin": null,
// "commissionDate": null,
// "telephone": null,
// "safetyManager": null,
// "mobilePhone": null,
// "infoList": null,
// "createTime": null,
// "productBatchNumber": "128240627",
// "type": "supervisionAndInspection"
// },
// {
// "id": null,
// "registrationCategory": null,
// "equipmentType": "",
// "productName": "",
// "cylinderQuantity": null,
// "fillingMedium": null,
// "nominalWorkingPressure": null,
// "cylinderVolume": null,
// "manufacturer": "绿",
// "productionDate": "20240801",
// "productId": null,
// "internalId": null,
// "contractor": null,
// "supervisionAgency": "绿",
// "userUnit": null,
// "userAddress": null,
// "unifiedSocialCode": null,
// "postalCode": null,
// "licensePlate": null,
// "vehicleVin": null,
// "commissionDate": null,
// "telephone": null,
// "safetyManager": null,
// "mobilePhone": null,
// "infoList": null,
// "createTime": null,
// "productBatchNumber": "NI054",
// "type": "supervisionAndInspection"
// }
// ],
// "infoList": [
// {
// "manufacturer": "",
// "productionDate": "20240901",
// "productId": "NI054039",
// "internalId": ""
// },
// {
// "manufacturer": "绿",
// "productionDate": "20240801",
// "productId": "128240627132",
// "internalId": ""
// },
// {
// "manufacturer": "",
// "productionDate": "",
// "productId": "",
// "internalId": ""
// }
// ],
// "total_pages": 1,
// "processing_time": "7.94s"
// }
this.calculateCylinderQuantity(mergedData);//
this.processFillingMedium(mergedData);//
this.processNominalPressure(mergedData);//
@ -775,6 +1047,7 @@
this.processContractor(mergedData); //
this.processSupervisionAgency(mergedData); //
this.processInfoList(mergedData); //
this.processVehicleVin(mergedData); // VIN
this.formData = mergedData;
console.log(this.formData)
} catch (error) {

Loading…
Cancel
Save