Browse Source

电量接口提交

fenbao
wangyx 1 month ago
parent
commit
12254979f1
  1. 179
      pagesA/sdPage/dfReport.vue

179
pagesA/sdPage/dfReport.vue

@ -25,9 +25,10 @@
:range="deptNames" :range="deptNames"
@change="onPickerChange($event, '乐业社区')" @change="onPickerChange($event, '乐业社区')"
> >
<view :style="{ color: !form.apartmentName ? '#cbcbcb' : '' }">{{ <view
form.apartmentName || pickerPlaceholder :style="{ color: !blockForm.apartmentName ? '#cbcbcb' : '' }"
}}</view> >{{ blockForm.apartmentName || pickerPlaceholder }}</view
>
</picker> </picker>
<image <image
class="arrow-r" class="arrow-r"
@ -52,11 +53,9 @@
:range="multiArray" :range="multiArray"
> >
<view class="uni-input">{{ <view class="uni-input">{{
multiIndex[0] multiArray[0][multiIndex[0]] +
? "请选择" multiArray[1][multiIndex[1]] +
: multiArray[0][multiIndex[0]] + multiArray[2][multiIndex[2]]
multiArray[1][multiIndex[1]] +
multiArray[2][multiIndex[2]]
}}</view> }}</view>
</picker> </picker>
</view> </view>
@ -74,41 +73,42 @@
<scroll-view class="house-view" scroll-y="true"> <scroll-view class="house-view" scroll-y="true">
<view <view
class="section-card" class="section-card"
v-for="(item, index) in form.waterMeters" v-for="(item, index) in form"
:key="item.id || index" :key="item.id || index"
style="margin-bottom: 24rpx" style="margin-bottom: 24rpx"
> >
<view class="section-title">水表{{ index + 1 }}</view> <view class="section-title">水表{{ index + 1 }}</view>
<view class="meter-row"> <view class="meter-row">
<text class="meter-label">表号</text> <text class="meter-label">表号</text>
<u-input <u-input
v-model="item.meterNumber" v-model="form[index].meterNumber"
type="digit" type="digit"
placeholder="请输入水表号" placeholder="请输入水表号"
border="none" border="none"
:disabled="!!item.meterNumber" :disabled="!!form[index].meterNumber"
:custom-style=" :custom-style="
item.meterNumber ? 'background:#fff;color:#bbb;' : '' form[index].meterNumber ? 'background:#fff;color:#bbb;' : ''
" "
/> />
</view> </view>
<!-- :disabled="!!item.lastMeterReading" -->
<view class="meter-row"> <view class="meter-row">
<text class="meter-label">上次表数</text> <text class="meter-label">上次表数</text>
<u-input <u-input
v-model="item.lastMeterReading" v-model="form[index].lastMeterReading"
type="digit" type="digit"
placeholder="请输入上次表数" :placeholder="`上次表数${item.lastMeterReading}`"
border="none" border="none"
:disabled="!!item.lastMeterReading"
:custom-style=" :custom-style="
item.meterNumber ? 'background:#fff;color:#bbb;' : '' form[index].meterNumber ? 'background:#fff;color:#bbb;' : ''
" "
/> />
</view> </view>
<view class="meter-row"> <view class="meter-row">
<text class="meter-label">本次表数</text> <text class="meter-label">本次表数</text>
<u-input <u-input
v-model="item.thisMeterReading" v-model="form[index].thisMeterReading"
type="digit" type="digit"
placeholder="请输入本次表数" placeholder="请输入本次表数"
border="none" border="none"
@ -122,7 +122,7 @@
:preview-full-image="true" :preview-full-image="true"
:deletable="true" :deletable="true"
:show-upload-list="true" :show-upload-list="true"
:fileList="item.fileList || []" :fileList="form[index].fileList || []"
:auto-upload="false" :auto-upload="false"
accept="all" accept="all"
:maxSize="10 * 1024 * 1024" :maxSize="10 * 1024 * 1024"
@ -169,32 +169,35 @@ export default {
remark: "", remark: "",
deptNames: [], deptNames: [],
deptOptions: [], deptOptions: [],
blockForm: {},
buildingOptions: [], buildingOptions: [],
unitOptions: [], unitOptions: [],
houseOptions: [], houseOptions: [],
currentHouse: {}, currentHouse: {},
multiArray: [[], [], []], multiArray: [[], [], []],
multiIndex: [-1, -1, -1], multiIndex: [0, 0, 0],
form: { form: [
apartmentId: "", {
apartmentName: "", meterNumber: "",
buildingId: "", meterType: 1, // 1: 2:
unitId: "", houseId: "", //
houseId: "", roomId: "",
waterMeters: [], lastMeterReading: "",
roomId: "", thisMeterReading: "",
fileList: [], fileList: [],
}, remark: "",
},
//
],
}; };
}, },
watch: { watch: {
"form.apartmentId": { "blockForm.apartmentId": {
handler(newVal, oldVal) { handler(newVal, oldVal) {
if (newVal !== oldVal) { if (newVal !== oldVal) {
this.form.buildingId = null; this.blockForm.buildingId = null;
this.form.unitId = null; this.blockForm.unitId = null;
this.form.houseId = null; this.blockForm.houseId = null;
this.buildingOptions = []; this.buildingOptions = [];
this.unitOptions = []; this.unitOptions = [];
this.houseOptions = []; this.houseOptions = [];
@ -252,8 +255,8 @@ export default {
console.log("社区信息", apartmentInfo); console.log("社区信息", apartmentInfo);
console.log("社区信息11", this.deptOptions); console.log("社区信息11", this.deptOptions);
this.form.apartmentName = apartmentInfo.deptName; this.blockForm.apartmentName = apartmentInfo.deptName;
this.form.apartmentId = apartmentInfo.deptId; this.blockForm.apartmentId = apartmentInfo.deptId;
// //
const buildingArray = await this.getListByParentId( const buildingArray = await this.getListByParentId(
"2", "2",
@ -264,7 +267,7 @@ export default {
const buildingNames = buildingArray.map((item) => item.name); const buildingNames = buildingArray.map((item) => item.name);
console.log("buildingNames:", buildingNames); console.log("buildingNames:", buildingNames);
this.form.buildingId = buildingArray[0].id; this.blockForm.buildingId = buildingArray[0].id;
// //
const unitArray = await this.getListByParentId( const unitArray = await this.getListByParentId(
"3", "3",
@ -274,12 +277,12 @@ export default {
console.log("unitArray:", unitArray); console.log("unitArray:", unitArray);
const unitNames = unitArray.map((item) => item.name); 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); const houseArray = await this.getListByParentId("4", unitArray[0].id);
this.houseOptions = houseArray; this.houseOptions = houseArray;
const houseNames = houseArray.map((item) => item.name); const houseNames = houseArray.map((item) => item.name);
this.form.houseId = houseArray[0].id; this.blockForm.houseId = houseArray[0].id;
let house = houseArray[0]; let house = houseArray[0];
// for (let index = 0; index < house.type; index++) { // for (let index = 0; index < house.type; index++) {
// this.form.waterMeters.push({ // this.form.waterMeters.push({
@ -309,7 +312,7 @@ export default {
); );
this.unitOptions = unitArray; this.unitOptions = unitArray;
const unitNames = unitArray.map((item) => item.name); const unitNames = unitArray.map((item) => item.name);
this.form.unitId = unitArray[0].id; this.blockForm.unitId = unitArray[0].id;
const houseArray = await this.getListByParentId( const houseArray = await this.getListByParentId(
"4", "4",
@ -317,8 +320,8 @@ export default {
); );
this.houseOptions = houseArray; this.houseOptions = houseArray;
const houseNames = houseArray.map((item) => item.name); const houseNames = houseArray.map((item) => item.name);
this.form.houseId = houseArray[0].id; this.blockForm.houseId = houseArray[0].id;
this.form.roomId = houseArray[0].roomId; this.blockForm.roomId = houseArray[0].roomId;
this.multiArray[1] = unitNames; this.multiArray[1] = unitNames;
this.multiArray[2] = houseNames; this.multiArray[2] = houseNames;
} //1 } //1
@ -333,16 +336,16 @@ export default {
); );
this.houseOptions = houseArray; this.houseOptions = houseArray;
const houseNames = houseArray.map((item) => item.name); const houseNames = houseArray.map((item) => item.name);
this.form.houseId = houseArray[0].id; this.blockForm.houseId = houseArray[0].id;
this.form.roomId = houseArray[0].roomId; this.blockForm.roomId = houseArray[0].roomId;
this.multiArray[2] = houseNames; this.multiArray[2] = houseNames;
} //2 } //2
this.multiIndex.splice(2, 1, 0); this.multiIndex.splice(2, 1, 0);
break; break;
case 2: { case 2: {
this.form.houseId = this.houseOptions[e.detail.value].id; this.blockForm.houseId = this.houseOptions[e.detail.value].id;
this.form.roomId = this.houseOptions[e.detail.value].roomId; this.blockForm.roomId = this.houseOptions[e.detail.value].roomId;
console.log(this.houseOptions[e.detail.value]); console.log(this.houseOptions[e.detail.value]);
} }
} }
@ -350,22 +353,19 @@ export default {
this.$forceUpdate(); this.$forceUpdate();
}, },
onDelete(event, index) { onDelete(event, index) {
if ( if (this.form[index] && Array.isArray(this.form[index].fileList)) {
this.form.waterMeters[index] && this.form[index].fileList.splice(event.index, 1);
Array.isArray(this.form.waterMeters[index].fileList)
) {
this.form.waterMeters[index].fileList.splice(event.index, 1);
// this.form.waterMeters[index].imageList = this.form.waterMeters[ // this.form.waterMeters[index].imageList = this.form.waterMeters[
// index // index
// ].fileList.map((v) => v.url); // ].fileList.map((v) => v.url);
} }
}, },
chooseMedia(index) { chooseMedia(index) {
if (!this.form.waterMeters[index].fileList) { if (!this.form[index].fileList) {
this.$set(this.form.waterMeters[index], "fileList", []); this.$set(this.form[index], "fileList", []);
} }
uni.chooseMedia({ uni.chooseMedia({
count: 10 - this.form.waterMeters[index].fileList.length, count: 10 - this.form[index].fileList.length,
mediaType: ["image", "video"], mediaType: ["image", "video"],
sourceType: ["album", "camera"], sourceType: ["album", "camera"],
maxDuration: 60, maxDuration: 60,
@ -384,10 +384,11 @@ export default {
: "image"); : "image");
// //
const uploadRes = await uploadImage(filePath); const uploadRes = await uploadImage(filePath);
this.form.waterMeters[index].fileList.push({ this.form[index].fileList.push({
url: uploadRes.data?.url || uploadRes.url || uploadRes.path, url: uploadRes.data?.url || uploadRes.url || uploadRes.path,
name: uploadRes.data?.name || uploadRes.name || "", name: uploadRes.data?.name || uploadRes.name || "",
type: type, type: type,
format: filePath.split(".").pop() || "",
status: "success", status: "success",
}); });
} }
@ -405,59 +406,71 @@ export default {
// //
async getLastMeter(item) { async getLastMeter(item) {
const params = { const params = {
houseId: this.form.houseId, houseId: this.blockForm.houseId,
roomId: this.form.roomId, roomId: this.blockForm.roomId,
meterType: 1, meterType: 1,
meterNumber: "", meterNumber: "",
}; };
const res = await queryLastMeterReading(params); const res = await queryLastMeterReading(params);
if (Array.isArray(res.data) && res.data.length > 0) { 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, lastMeterReading: item.thisMeterReading,
meterNumber: item.meterNumber, meterNumber: item.meterNumber,
thisMeterReading: "", // thisMeterReading: item.thisMeterReading || "",
fileList: [], // fileList: [],
// id: item.id || idx, // id: item.id || idx,
})); }));
} else { } else {
// res.data // res.data
this.form.waterMeters = [ this.form = [
{ {
lastMeterReading: "", lastMeterReading: "",
meterNumber: "", meterNumber: "",
thisMeterReading: "", thisMeterReading: "",
fileList: [],
// id: 1,
}, },
]; ];
} }
}, },
onSubmit() { onSubmit() {
let { buildingId, unitId, houseId } = this.form; let { buildingId, unitId, houseId } = this.blockForm;
// if (!this.form.apartmentName) { //
// uni.showToast({ title: "", icon: "none" }); if (!this.blockForm.apartmentName) {
// return; uni.showToast({ title: "请选择乐业社区", icon: "none" });
// } else if (!buildingId && !unitId && !houseId) { return;
// uni.showToast({ title: "", icon: "none" }); }
//
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; // return;
// } // }
this.submitAdd(); this.submitAdd();
console.log("onSubmit", this.form); console.log("onSubmit", this.form);
}, },
async submitAdd() { async submitAdd() {
let params = []; let params = this.form.map((item) => ({
this.form.waterMeters.forEach((item) => { meterNumber: item.meterNumber,
params.push({ meterType: 1,
meterNumber: item.meterNumber, houseId: this.blockForm.houseId,
meterType: 1, roomId: this.blockForm.roomId,
houseId: this.form.houseId, lastMeterReading: parseFloat(item.lastMeterReading).toFixed(2),
roomId: this.form.roomId, thisMeterReading: parseFloat(item.thisMeterReading).toFixed(2),
lastMeterReading: item.lastMeterReading, images: (item.fileList || []).map((f) => ({
thisMeterReading: item.thisMeterReading, url: f.url,
images: item.fileList, name: f.name,
remark: this.form.remark, type: f.type,
}); format: f.format || (f.url ? f.url.split(".").pop() : ""),
}); })),
remark: item.remark || "",
}));
console.log(params, "params"); console.log(params, "params");
const res = await submitWaterAndElectricity(params); const res = await submitWaterAndElectricity(params);

Loading…
Cancel
Save