fix(report): 优化设备注册表单数据初始化和更新逻辑

- 修复了表单数据更新时可能导致原始数据丢失的问题
- 优化了表单初始化逻辑,确保信息列表始终至少有 3 个空项
- 添加了 formData 变化的监听器,用于调试和可能的进一步处理
master
Tuzki 6 months ago
parent ecb3976f89
commit 2ebda16068
  1. 28
      src/views/report/eventList/EquipmentRegistrationForm.vue

@ -300,8 +300,8 @@
deep: true,
immediate: true,
handler(newVal) {
const localData = JSON.parse(JSON.stringify(newVal))
if (!newVal.infoList || newVal.infoList.length < 3) {
const copiedData = JSON.parse(JSON.stringify(newVal));
if (!copiedData.infoList || copiedData.infoList.length < 3) {
const requiredLength = 3;
const emptyItem = {
manufacturer: '',
@ -310,17 +310,22 @@
internalId: ''
};
while (newVal.infoList.length < requiredLength) {
newVal.infoList.push({ ...emptyItem });
while (copiedData.infoList.length < requiredLength) {
copiedData.infoList.push({ ...emptyItem });
}
}
this.formData = {
...this.formData, //
infoList: localData.infoList //
}
this.formData = { ...this.formData, ...copiedData }
console.log(this.formData)
}
},
formData: {
deep: true,
immediate: true,
handler(newVal) {
console.log(newVal)
}
},
'formData.cylinderQuantity': {
handler(newVal) {
//
@ -331,7 +336,12 @@
}
},
created() {
this.formData = JSON.parse(JSON.stringify(this.initialData));
//
if (!this.formData.infoList) this.formData.infoList = [];
while (this.formData.infoList.length < 3) {
this.formData.infoList.push({ manufacturer: '', productionDate: '', productId: '', internalId: '' });
}
},
methods: {
shouldValidate(index) {

Loading…
Cancel
Save