From 12254979f1b410d1e981fbfbe4429d5383f70893 Mon Sep 17 00:00:00 2001 From: wangyx <2838268875@qq.com> Date: Wed, 23 Jul 2025 09:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E9=87=8F=E6=8E=A5=E5=8F=A3=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagesA/sdPage/dfReport.vue | 179 ++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 83 deletions(-) diff --git a/pagesA/sdPage/dfReport.vue b/pagesA/sdPage/dfReport.vue index 016d457..2ba4591 100644 --- a/pagesA/sdPage/dfReport.vue +++ b/pagesA/sdPage/dfReport.vue @@ -25,9 +25,10 @@ :range="deptNames" @change="onPickerChange($event, '乐业社区')" > - {{ - form.apartmentName || pickerPlaceholder - }} + {{ blockForm.apartmentName || pickerPlaceholder }} {{ - multiIndex[0] - ? "请选择" - : multiArray[0][multiIndex[0]] + - multiArray[1][multiIndex[1]] + - multiArray[2][multiIndex[2]] + multiArray[0][multiIndex[0]] + + multiArray[1][multiIndex[1]] + + multiArray[2][multiIndex[2]] }} @@ -74,41 +73,42 @@ 水表{{ index + 1 }} - 水表号 + 电表号 + + 上次表数 本次表数 item.name); console.log("buildingNames:", buildingNames); - this.form.buildingId = buildingArray[0].id; + this.blockForm.buildingId = buildingArray[0].id; // 单元 const unitArray = await this.getListByParentId( "3", @@ -274,12 +277,12 @@ export default { console.log("unitArray:", unitArray); const unitNames = unitArray.map((item) => item.name); - this.form.unitId = unitArray[0].id; + this.blockForm.unitId = unitArray[0].id; // 户 const houseArray = await this.getListByParentId("4", unitArray[0].id); this.houseOptions = houseArray; const houseNames = houseArray.map((item) => item.name); - this.form.houseId = houseArray[0].id; + this.blockForm.houseId = houseArray[0].id; let house = houseArray[0]; // for (let index = 0; index < house.type; index++) { // this.form.waterMeters.push({ @@ -309,7 +312,7 @@ export default { ); this.unitOptions = unitArray; const unitNames = unitArray.map((item) => item.name); - this.form.unitId = unitArray[0].id; + this.blockForm.unitId = unitArray[0].id; const houseArray = await this.getListByParentId( "4", @@ -317,8 +320,8 @@ export default { ); this.houseOptions = houseArray; const houseNames = houseArray.map((item) => item.name); - this.form.houseId = houseArray[0].id; - this.form.roomId = houseArray[0].roomId; + this.blockForm.houseId = houseArray[0].id; + this.blockForm.roomId = houseArray[0].roomId; this.multiArray[1] = unitNames; this.multiArray[2] = houseNames; } //拖动第1列 @@ -333,16 +336,16 @@ export default { ); this.houseOptions = houseArray; const houseNames = houseArray.map((item) => item.name); - this.form.houseId = houseArray[0].id; - this.form.roomId = houseArray[0].roomId; + this.blockForm.houseId = houseArray[0].id; + this.blockForm.roomId = houseArray[0].roomId; this.multiArray[2] = houseNames; } //拖动第2列 this.multiIndex.splice(2, 1, 0); break; case 2: { - this.form.houseId = this.houseOptions[e.detail.value].id; - this.form.roomId = this.houseOptions[e.detail.value].roomId; + this.blockForm.houseId = this.houseOptions[e.detail.value].id; + this.blockForm.roomId = this.houseOptions[e.detail.value].roomId; console.log(this.houseOptions[e.detail.value]); } } @@ -350,22 +353,19 @@ export default { this.$forceUpdate(); }, onDelete(event, index) { - if ( - this.form.waterMeters[index] && - Array.isArray(this.form.waterMeters[index].fileList) - ) { - this.form.waterMeters[index].fileList.splice(event.index, 1); + if (this.form[index] && Array.isArray(this.form[index].fileList)) { + this.form[index].fileList.splice(event.index, 1); // this.form.waterMeters[index].imageList = this.form.waterMeters[ // index // ].fileList.map((v) => v.url); } }, chooseMedia(index) { - if (!this.form.waterMeters[index].fileList) { - this.$set(this.form.waterMeters[index], "fileList", []); + if (!this.form[index].fileList) { + this.$set(this.form[index], "fileList", []); } uni.chooseMedia({ - count: 10 - this.form.waterMeters[index].fileList.length, + count: 10 - this.form[index].fileList.length, mediaType: ["image", "video"], sourceType: ["album", "camera"], maxDuration: 60, @@ -384,10 +384,11 @@ export default { : "image"); // 上传 const uploadRes = await uploadImage(filePath); - this.form.waterMeters[index].fileList.push({ + this.form[index].fileList.push({ url: uploadRes.data?.url || uploadRes.url || uploadRes.path, name: uploadRes.data?.name || uploadRes.name || "", type: type, + format: filePath.split(".").pop() || "", status: "success", }); } @@ -405,59 +406,71 @@ export default { // 获取上次抄表 async getLastMeter(item) { const params = { - houseId: this.form.houseId, - roomId: this.form.roomId, + houseId: this.blockForm.houseId, + roomId: this.blockForm.roomId, meterType: 1, meterNumber: "", }; const res = await queryLastMeterReading(params); if (Array.isArray(res.data) && res.data.length > 0) { - this.form.waterMeters = res.data.map((item, idx) => ({ + this.form = res.data.map((item, idx) => ({ lastMeterReading: item.thisMeterReading, meterNumber: item.meterNumber, - thisMeterReading: "", - fileList: [], + // thisMeterReading: item.thisMeterReading || "", + // fileList: [], // id: item.id || idx, })); } else { // res.data 为空时,显示一个空表单 - this.form.waterMeters = [ + this.form = [ { lastMeterReading: "", meterNumber: "", thisMeterReading: "", - fileList: [], - // id: 1, }, ]; } }, onSubmit() { - let { buildingId, unitId, houseId } = this.form; - // if (!this.form.apartmentName) { - // uni.showToast({ title: "请选择乐业社区", icon: "none" }); - // return; - // } else if (!buildingId && !unitId && !houseId) { - // uni.showToast({ title: "请选择房屋", icon: "none" }); + let { buildingId, unitId, houseId } = this.blockForm; + // 检查是否选择了社区 + if (!this.blockForm.apartmentName) { + uni.showToast({ title: "请选择乐业社区", icon: "none" }); + return; + } + // 检查是否选择了房屋 + if (!buildingId || !unitId || !houseId) { + uni.showToast({ title: "请选择房屋", icon: "none" }); + return; + } + console.log("当前的 waterMeters 数据:", this.form.waterMeters); + // // 检查本次表数是否都已输入 + // const hasEmptyThisMeterReading = this.form.waterMeters.some( + // (item) => !item.thisMeterReading + // ); + // if (hasEmptyThisMeterReading) { + // uni.showToast({ title: "请输入所有水表的本次表数", icon: "none" }); // return; // } this.submitAdd(); console.log("onSubmit", this.form); }, async submitAdd() { - let params = []; - this.form.waterMeters.forEach((item) => { - params.push({ - meterNumber: item.meterNumber, - meterType: 1, - houseId: this.form.houseId, - roomId: this.form.roomId, - lastMeterReading: item.lastMeterReading, - thisMeterReading: item.thisMeterReading, - images: item.fileList, - remark: this.form.remark, - }); - }); + let params = this.form.map((item) => ({ + meterNumber: item.meterNumber, + meterType: 1, + houseId: this.blockForm.houseId, + roomId: this.blockForm.roomId, + lastMeterReading: parseFloat(item.lastMeterReading).toFixed(2), + thisMeterReading: parseFloat(item.thisMeterReading).toFixed(2), + 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);