From 77c628c1d7a66634861a7d580045fc36544e9bad Mon Sep 17 00:00:00 2001 From: wangyx <2838268875@qq.com> Date: Tue, 22 Jul 2025 11:44:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B0=B4=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagesA/sdPage/sfReport.vue | 313 ++++++++++++++++++++++++++++--------- 1 file changed, 237 insertions(+), 76 deletions(-) diff --git a/pagesA/sdPage/sfReport.vue b/pagesA/sdPage/sfReport.vue index 5a64246..731657d 100644 --- a/pagesA/sdPage/sfReport.vue +++ b/pagesA/sdPage/sfReport.vue @@ -27,8 +27,19 @@ - - {{multiArray[0][multiIndex[0]] + multiArray[1][multiIndex[1]] + multiArray[2][multiIndex[2]]}} + + {{ + multiIndex[0] === -1 + ? "请选择" + : multiArray[0][multiIndex[0]] + + multiArray[1][multiIndex[1]] + + multiArray[2][multiIndex[2]] + }} 请选择社区 @@ -40,32 +51,54 @@ 水表号 - - + 上次表数 - + 本次表数 - + - 上传图片 + 上传图片/视频 - + @@ -86,7 +119,11 @@ import { queryDeptDropdownList, } from "@/common/rec"; import { getdeptList } from '@/common/api'; -import { uploadImage } from '@/pages/api'; +import { + uploadImage, + queryLastMeterReading, + submitWaterAndElectricity +} from '@/pages/api'; export default { data() { @@ -102,15 +139,17 @@ export default { buildingOptions: [], unitOptions: [], houseOptions: [], - multiArray: [[],[],[]], - multiIndex: [0, 0, 0], + multiArray: [[], [], []], + multiIndex: [-1, -1, -1], form:{ apartmentId: '', apartmentName:'', buildingId: '', unitId: '', houseId: '', - waterMeters: [] + roomId: '', + waterMeters: [], + remark: '' }, } }, @@ -142,10 +181,16 @@ export default { "children", 2 ); - const deptInfo = this.deptOptions[0].children.filter(item=>item.deptName == '城阳区')[0] - this.deptOptions = await this.getListByParentId('1', deptInfo.deptId); - const array = JSON.parse(JSON.stringify(this.deptOptions)) - this.deptNames = array.map(item=>item.name) + // const deptInfo = this.deptOptions[0].children.filter( + // (item) => item.deptName == "城阳区" + // )[0]; + const newArr = this.deptOptions.map((item) => ({ + name: item.deptName, + })); + // this.deptOptions = newArr + // this.deptOptions = await this.getListByParentId("1", deptInfo.deptId); + // const array = JSON.parse(JSON.stringify(this.deptOptions)); + this.deptNames = newArr.map((item) => item.name); }); }, // 三级联动通用接口 @@ -156,35 +201,54 @@ export default { }); }); }, - async onPickerChange(e,type){ - if(type == '乐业社区'){ - const apartmentInfo = this.deptOptions[e.detail.value] - this.form.apartmentName = apartmentInfo.name - this.form.apartmentId = apartmentInfo.id + async onPickerChange(e, type) { + if (type == "乐业社区") { + console.log("e", e); + + const apartmentInfo = this.deptOptions[e.detail.value]; + console.log("社区信息", apartmentInfo); + console.log("社区信息11", this.deptOptions); + + this.form.apartmentName = apartmentInfo.deptName; + this.form.apartmentId = apartmentInfo.deptId; // 楼 - const buildingArray = await this.getListByParentId("2", apartmentInfo.id); - this.buildingOptions = buildingArray - const buildingNames = buildingArray.map(item=> item.name) - this.form.buildingId = buildingArray[0].id + const buildingArray = await this.getListByParentId( + "2", + apartmentInfo.deptId + ); + this.buildingOptions = buildingArray; + console.log("楼信息", buildingArray); + const buildingNames = buildingArray.map((item) => item.name); + console.log("buildingNames:", buildingNames); + + this.form.buildingId = buildingArray[0].id; // 单元 - const unitArray = await this.getListByParentId("3", buildingArray[0].id); - this.unitOptions = unitArray - const unitNames = unitArray.map(item=> item.name) - this.form.unitId = unitArray[0].id + const unitArray = await this.getListByParentId( + "3", + buildingArray[0].id + ); + this.unitOptions = unitArray; + console.log("unitArray:", unitArray); + + const unitNames = unitArray.map((item) => item.name); + this.form.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 - let house = houseArray[0] - for (let index = 0; index < house.type; index++) { - this.form.waterMeters.push({ - waterMeter: '', - imageList: [], - fileList: [] - }) - } - this.multiArray = [buildingNames, unitNames, houseNames] + this.houseOptions = houseArray; + const houseNames = houseArray.map((item) => item.name); + this.form.houseId = houseArray[0].id; + this.form.roomId = houseArray[0].roomId; + let house = houseArray[0]; + // for (let index = 0; index < house.type; index++) { + // this.form.waterMeters.push({ + // meterNumber: "", + // lastMeterReading: "", + // thisMeterReading: "", + // imageList: [], + // fileList: [], + // }); + // } + this.multiArray = [buildingNames, unitNames, houseNames]; } }, handleShowToast(){ @@ -205,6 +269,7 @@ 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.multiArray[1] = unitNames this.multiArray[2] = houseNames @@ -218,6 +283,7 @@ 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.multiArray[2] = houseNames } //拖动第2列 @@ -225,45 +291,99 @@ export default { break case 2:{ this.form.houseId = this.houseOptions[e.detail.value].id + this.form.roomId = this.houseOptions[e.detail.value].roomId console.log(this.houseOptions[e.detail.value]); } } + this.getLastMeter() this.$forceUpdate() }, - async afterRead(event,index) { - let lists = [].concat(event.file); - let fileListLen = this.form.waterMeters[index][`fileList${event.name}`].length; - lists.map((item) => { - this.form.waterMeters[index][`fileList${event.name}`].push({ - ...item, - status: "uploading", - message: "上传中", - }); - }); - for (let i = 0; i < lists.length; i++) { - const result = await uploadImage(lists[i].url); - let item = this.form.waterMeters[index][`fileList${event.name}`][fileListLen]; - - this.form.waterMeters[index][`fileList${event.name}`].splice( - fileListLen, - 1, - Object.assign(item, { - status: "success", - message: "", - url: result.url, - }) - ); - fileListLen++; + //图片超过大小时取消上传 + oversize(e) { + this.$u.toast("请传10MB以内大小的图片/视频!"); + return false; + }, + chooseMedia(index) { + if (!this.form.waterMeters[index].fileList) { + this.$set(this.form.waterMeters[index], "fileList", []); } - var arry = []; - this.form.waterMeters[index].fileList.filter((v, i) => { - arry.push(v.url); + uni.chooseMedia({ + count: 10 - this.form.waterMeters[index].fileList.length, + mediaType: ["image", "video"], + sourceType: ["album", "camera"], + maxDuration: 60, + camera: "back", + success: async (res) => { + uni.showLoading({ title: "上传中...", mask: true }); + try { + const files = res.tempFiles; + for (let i = 0; i < files.length; i++) { + const file = files[i]; + const filePath = file.tempFilePath; + const type = + file.fileType || + (filePath.match(/\.(mp4|mov|avi|wmv|flv|mkv)$/i) + ? "video" + : "image"); + // 上传 + const uploadRes = await uploadImage(filePath); + this.form.waterMeters[index].fileList.push({ + url: uploadRes.data?.url || uploadRes.url || uploadRes.path, + name: uploadRes.data?.name || uploadRes.name || "", + type: type, + status: "success", + }); + } + // 更新 imageList + this.form.waterMeters[index].imageList = this.form.waterMeters[index].fileList.map((v) => v.url); + } catch (e) { + uni.showToast({ title: "上传失败", icon: "none" }); + } finally { + uni.hideLoading(); + } + }, + fail: () => { + uni.hideLoading(); + }, }); - this.form.waterMeters[index].imageList = arry }, - onDelete(event,index) { - this.form.waterMeters[index].fileList.splice(event.index, 1) - this.form.waterMeters[index].imageList.splice(event.index, 1) + // 获取上次抄表 + async getLastMeter() { + const params = { + houseId: this.form.houseId, + roomId: this.form.roomId, + meterType: 1, // 1是水表,2是电表 + meterNumber: "", + }; + const res = await queryLastMeterReading(params); + if (Array.isArray(res.data) && res.data.length > 0) { + this.form.waterMeters = res.data.map((item, idx) => ({ + lastMeterReading: item.thisMeterReading, + meterNumber: item.meterNumber, + thisMeterReading: "", + fileList: [], + })); + } else { + // res.data 为空时,显示一个空表单 + this.form.waterMeters = [ + { + lastMeterReading: "", + meterNumber: "", + thisMeterReading: "", + fileList: [], + }, + ]; + } + }, + onDelete(event, index) { + if ( + this.form.waterMeters[index] && + Array.isArray(this.form.waterMeters[index].fileList) + ) { + this.form.waterMeters[index].fileList.splice(event.index, 1); + // 更新 imageList + this.form.waterMeters[index].imageList = this.form.waterMeters[index].fileList.map((v) => v.url); + } }, onSubmit() { let {buildingId, unitId, houseId} = this.form @@ -274,7 +394,48 @@ export default { 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, // 1是水表,2是电表 + houseId: this.form.houseId, + roomId: this.form.roomId, + lastMeterReading: item.lastMeterReading, + thisMeterReading: item.thisMeterReading, + images: item.fileList, + remark: this.form.remark, + }); + }); + console.log(params, "params"); + + 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", + }); + } + console.log(res, "reeees"); } } }