|
|
@ -90,9 +90,9 @@ |
|
|
|
type="digit" |
|
|
|
placeholder="请输入电表号" |
|
|
|
border="none" |
|
|
|
:disabled="!!item.electricMeterNumber" |
|
|
|
:disabled="item.isSystemElectricMeterNumber" |
|
|
|
:custom-style=" |
|
|
|
item.electricMeterNumber ? 'background:#fff;color:#bbb;' : '' |
|
|
|
item.isSystemElectricMeterNumber ? 'background:#fff;color:#666;' : '' |
|
|
|
" |
|
|
|
/> |
|
|
|
</view> |
|
|
@ -211,6 +211,7 @@ export default { |
|
|
|
fileList: [], |
|
|
|
remark: "", |
|
|
|
electricMeterNumber: "", |
|
|
|
isSystemElectricMeterNumber: false, // 是否为系统预设的电表号 |
|
|
|
}, |
|
|
|
// 可以有多个水表对象 |
|
|
|
], |
|
|
@ -276,6 +277,13 @@ export default { |
|
|
|
async onPickerChange(e, type) { |
|
|
|
if (type == "乐业社区") { |
|
|
|
const apartmentInfo = this.deptOptions[e.detail.value]; |
|
|
|
|
|
|
|
// 添加数据验证 |
|
|
|
if (!apartmentInfo) { |
|
|
|
console.warn("未获取到社区信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.blockForm.apartmentName = apartmentInfo.deptName; |
|
|
|
this.blockForm.apartmentId = apartmentInfo.deptId; |
|
|
|
// 楼 |
|
|
@ -283,6 +291,13 @@ export default { |
|
|
|
"2", |
|
|
|
apartmentInfo.deptId |
|
|
|
); |
|
|
|
|
|
|
|
// 验证楼数据 |
|
|
|
if (!buildingArray || buildingArray.length === 0) { |
|
|
|
console.warn("未获取到楼信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.buildingOptions = buildingArray; |
|
|
|
const buildingNames = buildingArray.map((item) => item.name); |
|
|
|
|
|
|
@ -292,12 +307,26 @@ export default { |
|
|
|
"3", |
|
|
|
buildingArray[0].id |
|
|
|
); |
|
|
|
|
|
|
|
// 验证单元数据 |
|
|
|
if (!unitArray || unitArray.length === 0) { |
|
|
|
console.warn("未获取到单元信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.unitOptions = unitArray; |
|
|
|
|
|
|
|
const unitNames = unitArray.map((item) => item.name); |
|
|
|
this.blockForm.unitId = unitArray[0].id; |
|
|
|
// 户 |
|
|
|
const houseArray = await this.getListByParentId("4", unitArray[0].id); |
|
|
|
|
|
|
|
// 验证户数据 |
|
|
|
if (!houseArray || houseArray.length === 0) { |
|
|
|
console.warn("未获取到户信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.houseOptions = houseArray; |
|
|
|
const houseNames = houseArray.map((item) => item.name); |
|
|
|
this.blockForm.houseId = houseArray[0].id; |
|
|
@ -335,6 +364,13 @@ export default { |
|
|
|
"3", |
|
|
|
this.buildingOptions[e.detail.value].id |
|
|
|
); |
|
|
|
|
|
|
|
// 验证单元数据 |
|
|
|
if (!unitArray || unitArray.length === 0) { |
|
|
|
console.warn("未获取到单元信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.unitOptions = unitArray; |
|
|
|
const unitNames = unitArray.map((item) => item.name); |
|
|
|
this.blockForm.unitId = unitArray[0].id; |
|
|
@ -343,6 +379,13 @@ export default { |
|
|
|
"4", |
|
|
|
unitArray[0].id |
|
|
|
); |
|
|
|
|
|
|
|
// 验证户数据 |
|
|
|
if (!houseArray || houseArray.length === 0) { |
|
|
|
console.warn("未获取到户信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.houseOptions = houseArray; |
|
|
|
const houseNames = houseArray.map((item) => item.name); |
|
|
|
this.blockForm.houseId = houseArray[0].id; |
|
|
@ -360,6 +403,13 @@ export default { |
|
|
|
"4", |
|
|
|
this.unitOptions[e.detail.value].id |
|
|
|
); |
|
|
|
|
|
|
|
// 验证户数据 |
|
|
|
if (!houseArray || houseArray.length === 0) { |
|
|
|
console.warn("未获取到户信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.houseOptions = houseArray; |
|
|
|
const houseNames = houseArray.map((item) => item.name); |
|
|
|
this.blockForm.houseId = houseArray[0].id; |
|
|
@ -378,11 +428,16 @@ export default { |
|
|
|
this.houseOptions[e.detail.value].energyMeterConfig; |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.energyMeterConfig == 1) { |
|
|
|
this.getHouseInfoBy(this.blockForm.houseId); |
|
|
|
} else if (this.energyMeterConfig == 2) { |
|
|
|
this.getRoomByHouseId(this.blockForm.houseId); |
|
|
|
|
|
|
|
// 确保在调用方法之前有有效的配置 |
|
|
|
if (this.energyMeterConfig && this.blockForm.houseId) { |
|
|
|
if (this.energyMeterConfig == 1) { |
|
|
|
this.getHouseInfoBy(this.blockForm.houseId); |
|
|
|
} else if (this.energyMeterConfig == 2) { |
|
|
|
this.getRoomByHouseId(this.blockForm.houseId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.$forceUpdate(); |
|
|
|
}, |
|
|
|
onDelete(event, index) { |
|
|
@ -440,21 +495,33 @@ export default { |
|
|
|
async getHouseInfoBy(id) { |
|
|
|
const res = await getHouseInfo(id); |
|
|
|
if (res.code == 200) { |
|
|
|
// 添加安全检查 |
|
|
|
if (!res.data) { |
|
|
|
console.warn("未获取到房屋信息"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.energyMeterConfig == 1) { |
|
|
|
this.getRoomByHouseId(id); |
|
|
|
|
|
|
|
this.form = [ |
|
|
|
{ |
|
|
|
electricMeterNumber: res.data.electricMeterNumber, |
|
|
|
electricMeterNumber: res.data.electricMeterNumber && res.data.electricMeterNumber.trim() !== '' ? res.data.electricMeterNumber : "", |
|
|
|
isSystemElectricMeterNumber: !!(res.data.electricMeterNumber && res.data.electricMeterNumber.trim() !== ''), |
|
|
|
}, |
|
|
|
]; |
|
|
|
} else if (this.energyMeterConfig == 2) { |
|
|
|
this.form = this.form.map((item) => ({ |
|
|
|
...item, |
|
|
|
electricMeterNumber: res.data.electricMeterNumber, |
|
|
|
electricMeterNumber: res.data.electricMeterNumber && res.data.electricMeterNumber.trim() !== '' ? res.data.electricMeterNumber : "", |
|
|
|
isSystemElectricMeterNumber: !!(res.data.electricMeterNumber && res.data.electricMeterNumber.trim() !== ''), |
|
|
|
})); |
|
|
|
} |
|
|
|
this.getLastMeter(res.data.electricMeterNumber); |
|
|
|
|
|
|
|
// 只有当电表号存在时才调用获取上次读数 |
|
|
|
if (res.data.electricMeterNumber && res.data.electricMeterNumber.trim() !== '') { |
|
|
|
this.getLastMeter(res.data.electricMeterNumber); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
// 获取上次抄表 |
|
|
@ -472,11 +539,19 @@ export default { |
|
|
|
meterNumber: item, |
|
|
|
}; |
|
|
|
const res = await queryLastMeterReading(params); |
|
|
|
|
|
|
|
// 添加安全检查,确保res.data存在且不为空 |
|
|
|
if (!res.data || !Array.isArray(res.data) || res.data.length === 0) { |
|
|
|
console.warn("未获取到电表读数数据"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.energyMeterConfig == 1) { |
|
|
|
this.form = this.form.map((item) => ({ |
|
|
|
...item, |
|
|
|
lastMeterReading: res.data[0].thisMeterReading, |
|
|
|
electricMeterNumber: res.data[0].meterNumber, |
|
|
|
lastMeterReading: res.data[0].thisMeterReading || 0, |
|
|
|
electricMeterNumber: res.data[0].meterNumber || "", |
|
|
|
isSystemElectricMeterNumber: !!(res.data[0].meterNumber && res.data[0].meterNumber.trim() !== ''), |
|
|
|
})); |
|
|
|
} else if (this.energyMeterConfig == 2) { |
|
|
|
this.form = this.form.map((item) => { |
|
|
@ -488,8 +563,9 @@ export default { |
|
|
|
if (meter) { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
lastMeterReading: meter.thisMeterReading, |
|
|
|
electricMeterNumber: meter.meterNumber, |
|
|
|
lastMeterReading: meter.thisMeterReading || 0, |
|
|
|
electricMeterNumber: meter.meterNumber || "", |
|
|
|
isSystemElectricMeterNumber: !!(meter.meterNumber && meter.meterNumber.trim() !== ''), |
|
|
|
}; |
|
|
|
} |
|
|
|
return item; |
|
|
@ -499,13 +575,19 @@ export default { |
|
|
|
async getRoomByHouseId(id) { |
|
|
|
const res = await getRoomByHouseId({ houseId: id }); |
|
|
|
if (res.code == 200) { |
|
|
|
// 添加安全检查 |
|
|
|
if (!res.data || !Array.isArray(res.data) || res.data.length === 0) { |
|
|
|
console.warn("未获取到房间数据"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.energyMeterConfig == 1) { |
|
|
|
this.form = this.form.map((item) => ({ |
|
|
|
...item, |
|
|
|
id: res.data[0].id, |
|
|
|
id: res.data[0].id || "", |
|
|
|
})); |
|
|
|
} else if (this.energyMeterConfig == 2) { |
|
|
|
this.form = res.data; |
|
|
|
this.form = res.data; |
|
|
|
this.getLastMeter(); |
|
|
|
} |
|
|
|
} |
|
|
@ -533,13 +615,13 @@ export default { |
|
|
|
// }); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
if (!item.lastMeterReading && item.lastMeterReading !== 0) { |
|
|
|
uni.showToast({ |
|
|
|
title: `第${i + 1}个房间请填写上次表数`, |
|
|
|
icon: "none", |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
// if (!item.lastMeterReading && item.lastMeterReading !== 0) { |
|
|
|
// uni.showToast({ |
|
|
|
// title: `第${i + 1}个房间请填写上次表数`, |
|
|
|
// icon: "none", |
|
|
|
// }); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
if (!item.thisMeterReading && item.thisMeterReading !== 0) { |
|
|
|
uni.showToast({ |
|
|
|
title: `第${i + 1}个房间请填写本次表数`, |
|
|
@ -588,42 +670,87 @@ export default { |
|
|
|
this.submitAdd(); |
|
|
|
}, |
|
|
|
async submitAdd() { |
|
|
|
let params = this.form.map((item) => ({ |
|
|
|
meterNumber: item.electricMeterNumber, |
|
|
|
meterType: 1, |
|
|
|
houseId: this.blockForm.houseId, |
|
|
|
roomId: item.id || "", |
|
|
|
// lastMeterReading: isNaN(parseFloat(item.lastMeterReading)) ? '' : parseFloat(item.lastMeterReading).toFixed(4), |
|
|
|
lastMeterReading: item.lastMeterReading?item.lastMeterReading:item.thisMeterReading, |
|
|
|
thisMeterReading: parseFloat(item.thisMeterReading).toFixed(4), |
|
|
|
images: (item.fileList || []).map((f) => ({ |
|
|
|
url: f.url, |
|
|
|
name: f.name, |
|
|
|
type: f.type, |
|
|
|
format: f.format || (f.url ? f.url.split(".").pop() : ""), |
|
|
|
})), |
|
|
|
remark: item.remark || "", |
|
|
|
})); |
|
|
|
console.log(params, "params"); |
|
|
|
const res = await submitWaterAndElectricity(params); |
|
|
|
if (res.code == 200) { |
|
|
|
// 验证form数据 |
|
|
|
if (!this.form || !Array.isArray(this.form) || this.form.length === 0) { |
|
|
|
uni.showToast({ |
|
|
|
icon: "success", |
|
|
|
title: "提交成功!", |
|
|
|
success: () => { |
|
|
|
setTimeout(() => { |
|
|
|
uni.switchTab({ |
|
|
|
url: "/pages/tabBar/work/index", |
|
|
|
success: () => { |
|
|
|
this.fileList = []; |
|
|
|
}, |
|
|
|
}); |
|
|
|
}, 1500); |
|
|
|
}, |
|
|
|
title: "表单数据无效", |
|
|
|
icon: "none", |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 验证blockForm数据 |
|
|
|
if (!this.blockForm.houseId) { |
|
|
|
uni.showToast({ |
|
|
|
title: "房屋信息无效", |
|
|
|
icon: "none", |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
let params = this.form.map((item) => { |
|
|
|
// 验证每个表单项 |
|
|
|
if (!item) { |
|
|
|
console.warn("表单项数据无效:", item); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
meterNumber: item.electricMeterNumber || "", |
|
|
|
meterType: 1, |
|
|
|
houseId: this.blockForm.houseId, |
|
|
|
roomId: item.id || "", |
|
|
|
// lastMeterReading: isNaN(parseFloat(item.lastMeterReading)) ? '' : parseFloat(item.lastMeterReading).toFixed(4), |
|
|
|
lastMeterReading: item.lastMeterReading ? item.lastMeterReading : item.thisMeterReading, |
|
|
|
thisMeterReading: parseFloat(item.thisMeterReading || 0).toFixed(4), |
|
|
|
images: (item.fileList || []).map((f) => ({ |
|
|
|
url: f.url || "", |
|
|
|
name: f.name || "", |
|
|
|
type: f.type || "", |
|
|
|
format: f.format || (f.url ? f.url.split(".").pop() : ""), |
|
|
|
})), |
|
|
|
remark: item.remark || "", |
|
|
|
}; |
|
|
|
}).filter(item => item !== null); // 过滤掉无效的项 |
|
|
|
|
|
|
|
// 验证处理后的参数 |
|
|
|
if (params.length === 0) { |
|
|
|
uni.showToast({ |
|
|
|
title: "没有有效的表单数据", |
|
|
|
icon: "none", |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
console.log(params, "params"); |
|
|
|
|
|
|
|
try { |
|
|
|
const res = await submitWaterAndElectricity(params); |
|
|
|
if (res.code == 200) { |
|
|
|
uni.showToast({ |
|
|
|
icon: "success", |
|
|
|
title: "提交成功!", |
|
|
|
success: () => { |
|
|
|
setTimeout(() => { |
|
|
|
uni.switchTab({ |
|
|
|
url: "/pages/tabBar/work/index", |
|
|
|
success: () => { |
|
|
|
this.fileList = []; |
|
|
|
}, |
|
|
|
}); |
|
|
|
}, 1500); |
|
|
|
}, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: res.msg || "提交失败", |
|
|
|
icon: "none", |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error("提交失败:", error); |
|
|
|
uni.showToast({ |
|
|
|
title: res.msg || "提交失败", |
|
|
|
title: "提交失败,请重试", |
|
|
|
icon: "none", |
|
|
|
}); |
|
|
|
} |
|
|
|