Browse Source

电量接口提交

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

165
pagesA/sdPage/dfReport.vue

@ -25,9 +25,10 @@
:range="deptNames"
@change="onPickerChange($event, '乐业社区')"
>
<view :style="{ color: !form.apartmentName ? '#cbcbcb' : '' }">{{
form.apartmentName || pickerPlaceholder
}}</view>
<view
:style="{ color: !blockForm.apartmentName ? '#cbcbcb' : '' }"
>{{ blockForm.apartmentName || pickerPlaceholder }}</view
>
</picker>
<image
class="arrow-r"
@ -52,9 +53,7 @@
:range="multiArray"
>
<view class="uni-input">{{
multiIndex[0]
? "请选择"
: multiArray[0][multiIndex[0]] +
multiArray[0][multiIndex[0]] +
multiArray[1][multiIndex[1]] +
multiArray[2][multiIndex[2]]
}}</view>
@ -74,41 +73,42 @@
<scroll-view class="house-view" scroll-y="true">
<view
class="section-card"
v-for="(item, index) in form.waterMeters"
v-for="(item, index) in form"
:key="item.id || index"
style="margin-bottom: 24rpx"
>
<view class="section-title">水表{{ index + 1 }}</view>
<view class="meter-row">
<text class="meter-label">表号</text>
<text class="meter-label">表号</text>
<u-input
v-model="item.meterNumber"
v-model="form[index].meterNumber"
type="digit"
placeholder="请输入水表号"
border="none"
:disabled="!!item.meterNumber"
:disabled="!!form[index].meterNumber"
:custom-style="
item.meterNumber ? 'background:#fff;color:#bbb;' : ''
form[index].meterNumber ? 'background:#fff;color:#bbb;' : ''
"
/>
</view>
<!-- :disabled="!!item.lastMeterReading" -->
<view class="meter-row">
<text class="meter-label">上次表数</text>
<u-input
v-model="item.lastMeterReading"
v-model="form[index].lastMeterReading"
type="digit"
placeholder="请输入上次表数"
:placeholder="`上次表数${item.lastMeterReading}`"
border="none"
:disabled="!!item.lastMeterReading"
:custom-style="
item.meterNumber ? 'background:#fff;color:#bbb;' : ''
form[index].meterNumber ? 'background:#fff;color:#bbb;' : ''
"
/>
</view>
<view class="meter-row">
<text class="meter-label">本次表数</text>
<u-input
v-model="item.thisMeterReading"
v-model="form[index].thisMeterReading"
type="digit"
placeholder="请输入本次表数"
border="none"
@ -122,7 +122,7 @@
:preview-full-image="true"
:deletable="true"
:show-upload-list="true"
:fileList="item.fileList || []"
:fileList="form[index].fileList || []"
:auto-upload="false"
accept="all"
:maxSize="10 * 1024 * 1024"
@ -169,32 +169,35 @@ export default {
remark: "",
deptNames: [],
deptOptions: [],
blockForm: {},
buildingOptions: [],
unitOptions: [],
houseOptions: [],
currentHouse: {},
multiArray: [[], [], []],
multiIndex: [-1, -1, -1],
form: {
apartmentId: "",
apartmentName: "",
buildingId: "",
unitId: "",
houseId: "",
waterMeters: [],
multiIndex: [0, 0, 0],
form: [
{
meterNumber: "",
meterType: 1, // 1: 2:
houseId: "", //
roomId: "",
lastMeterReading: "",
thisMeterReading: "",
fileList: [],
remark: "",
},
//
],
};
},
watch: {
"form.apartmentId": {
"blockForm.apartmentId": {
handler(newVal, oldVal) {
if (newVal !== oldVal) {
this.form.buildingId = null;
this.form.unitId = null;
this.form.houseId = null;
this.blockForm.buildingId = null;
this.blockForm.unitId = null;
this.blockForm.houseId = null;
this.buildingOptions = [];
this.unitOptions = [];
this.houseOptions = [];
@ -252,8 +255,8 @@ export default {
console.log("社区信息", apartmentInfo);
console.log("社区信息11", this.deptOptions);
this.form.apartmentName = apartmentInfo.deptName;
this.form.apartmentId = apartmentInfo.deptId;
this.blockForm.apartmentName = apartmentInfo.deptName;
this.blockForm.apartmentId = apartmentInfo.deptId;
//
const buildingArray = await this.getListByParentId(
"2",
@ -264,7 +267,7 @@ export default {
const buildingNames = buildingArray.map((item) => 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({
let params = this.form.map((item) => ({
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,
});
});
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);

Loading…
Cancel
Save