Browse Source

水电联调

fenbao
wangyx 3 months ago
parent
commit
a67602b530
  1. 16
      pages/api.js
  2. 4
      pages/login/login.vue
  3. 6
      pages/tabBar/mine/index.vue
  4. 14
      pages/tabBar/work/index.vue
  5. 242
      pagesA/sdPage/dfReport.vue
  6. 501
      pagesA/sdPage/sfReport.vue
  7. 17
      store/user.js
  8. 4
      utils/request.js

16
pages/api.js

@ -133,6 +133,22 @@ export function submitWaterAndElectricity(data) {
data: data,
});
}
// 根据房屋获取房间
export function getRoomByHouseId(query) {
return request({
url: `/mz/room/getRoomInfoByHouseId`,
method: "get",
params: query,
});
}
// 查房屋信息
export function getHouseInfo(id ){
return request ({
url: `/mz/house/${id}`,
method:"get"
})
}
// 退出登录
export function logout() {

4
pages/login/login.vue

@ -177,11 +177,9 @@ export default {
if (res.code === 200) {
this.loginFailCounts[username] = 0;
uni.setStorageSync("token", res.token);
store.dispatch('user/setToken', res.token);
// 1.
const userRes = await getUserInfo();
console.log(userRes,'获取用户信息成功');
if (userRes.code === 200) {
uni.setStorageSync("userInfo", userRes.data);
// 2. vuex

6
pages/tabBar/mine/index.vue

@ -68,8 +68,6 @@ export default {
this.$store.dispatch("user/setUserInfo", userInfo);
}
this.userInfo = userInfo;
console.log("userInfo", userInfo);
},
methods: {
isNetAvatar(url) {
@ -79,8 +77,8 @@ export default {
async handleLogout() {
try {
await logout();
} catch (e) {}
uni.removeStorageSync("token");
} catch (e) { }
await this.$store.dispatch("user/logout");
uni.reLaunch({
url: "/pages/login/login",
});

14
pages/tabBar/work/index.vue

@ -38,7 +38,7 @@
</view>
</view>
<view class="conItem" >
<view class="conItem">
<view class="conItem-title">水电</view>
<view class="conItem-cont">
<view
@ -89,8 +89,8 @@ import { getRouters } from "../../../pages/api";
export default {
data() {
return {
showCheckOut: false, //
showInspection: false, //
showCheckOut: false, //
showInspection: false, //
fyList: [
// { image: '/static/img/.png', text: '' },
{ image: "/static/img/退房检查.png", text: "退房检查" },
@ -103,8 +103,8 @@ export default {
{ image: "/static/img/记录.png", text: "巡检记录" },
],
sdList: [
{ image: '/static/img/水费.png', text: '水量上报' },
{ image: '/static/img/电费.png', text: '电量上报' },
{ image: "/static/img/水费.png", text: "水量上报" },
{ image: "/static/img/电费.png", text: "电量上报" },
],
// bxList: [
// { image: '/static/img/.png', text: '' },
@ -118,7 +118,7 @@ export default {
},
onLoad() {
this.getRouter();
if (!uni.getStorageSync("token")) {
if (!this.$store.state.user.token) {
uni.redirectTo({
url: "/pages/login/login",
});
@ -132,7 +132,7 @@ export default {
function hasMenu(menu, name) {
if (!menu) return false;
if (Array.isArray(menu)) {
return menu.some(item => hasMenu(item, name));
return menu.some((item) => hasMenu(item, name));
}
if (menu.name === name) return true;
if (menu.children) return hasMenu(menu.children, name);

242
pagesA/sdPage/dfReport.vue

@ -74,39 +74,56 @@
<view
class="section-card"
v-for="(item, index) in form"
:key="item.id || index"
:key="item.id"
style="margin-bottom: 24rpx"
>
<view class="section-title">水表{{ index + 1 }}</view>
<view class="section-title">{{ item.roomTypeName }}</view>
<view class="meter-row">
<text class="meter-label">电表号</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>电表号</text>
</view>
<u-input
v-model="form[index].meterNumber"
v-model="item.electricMeterNumber"
type="digit"
placeholder="请输入水表号"
placeholder="请输入表号"
border="none"
:disabled="!!form[index].meterNumber"
:disabled="!!item.electricMeterNumber"
:custom-style="
form[index].meterNumber ? 'background:#fff;color:#bbb;' : ''
item.electricMeterNumber ? 'background:#fff;color:#bbb;' : ''
"
/>
</view>
<!-- :disabled="!!item.lastMeterReading" -->
<view class="meter-row">
<text class="meter-label">上次表数</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>上次表数</text>
</view>
<u-input
v-model="form[index].lastMeterReading"
type="digit"
:placeholder="`上次表数${item.lastMeterReading}`"
border="none"
:custom-style="
form[index].meterNumber ? 'background:#fff;color:#bbb;' : ''
form[index].electricMeterNumber
? 'background:#fff;color:#bbb;'
: ''
"
/>
</view>
<view class="meter-row">
<text class="meter-label">本次表数</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>本次表数</text>
</view>
<u-input
v-model="form[index].thisMeterReading"
type="digit"
@ -115,7 +132,12 @@
/>
</view>
<view class="imeter-row">
<text class="meter-label">上传图片</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>上传图片</text>
</view>
<u-upload
:max-count="10"
:multiple="true"
@ -158,6 +180,8 @@ import {
uploadImage,
queryLastMeterReading,
submitWaterAndElectricity,
getRoomByHouseId,
getHouseInfo,
} from "@/pages/api";
export default {
@ -186,9 +210,12 @@ export default {
thisMeterReading: "",
fileList: [],
remark: "",
electricMeterNumber: "",
},
//
],
energyMeterConfig: "",
waterMeterConfig: "",
};
},
watch: {
@ -283,6 +310,15 @@ export default {
this.houseOptions = houseArray;
const houseNames = houseArray.map((item) => item.name);
this.blockForm.houseId = houseArray[0].id;
this.energyMeterConfig = houseArray[0].energyMeterConfig;
this.waterMeterConfig = houseArray[0].waterMeterConfig;
if (this.energyMeterConfig == 1) {
this.getHouseInfoBy(this.blockForm.houseId);
} else if (this.energyMeterConfig == 2) {
this.getRoomByHouseId(this.blockForm.houseId);
}
this.getLastMeter();
let house = houseArray[0];
// for (let index = 0; index < house.type; index++) {
// this.form.waterMeters.push({
@ -346,10 +382,24 @@ export default {
case 2: {
this.blockForm.houseId = this.houseOptions[e.detail.value].id;
this.blockForm.roomId = this.houseOptions[e.detail.value].roomId;
this.waterMeterConfig =
this.houseOptions[e.detail.value].waterMeterConfig;
this.energyMeterConfig =
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);
}
this.getLastMeter();
console.log(
this.waterMeterConfig,
this.energyMeterConfig,
"this.waterMeterConfig, this.energyMeterConfig"
);
console.log(this.houseOptions[e.detail.value]);
}
}
this.getLastMeter();
this.$forceUpdate();
},
onDelete(event, index) {
@ -403,6 +453,16 @@ export default {
},
});
},
//
async getHouseInfoBy(id) {
const res = await getHouseInfo(id);
if (res.code == 200) {
this.form = this.form.map((item) => ({
...item,
electricMeterNumber: res.data.electricMeterNumber,
}));
}
},
//
async getLastMeter(item) {
const params = {
@ -412,23 +472,65 @@ export default {
meterNumber: "",
};
const res = await queryLastMeterReading(params);
if (Array.isArray(res.data) && res.data.length > 0) {
this.form = res.data.map((item, idx) => ({
lastMeterReading: item.thisMeterReading,
meterNumber: item.meterNumber,
// thisMeterReading: item.thisMeterReading || "",
// fileList: [],
// id: item.id || idx,
}));
} else {
// res.data
this.form = [
{
lastMeterReading: "",
meterNumber: "",
thisMeterReading: "",
},
];
console.log(
"form:",
this.form.map((i) => i.id)
);
console.log(
"res.data:",
res.data.map((i) => i.roomId)
);
// if (Array.isArray(res.data) && res.data.length > 0) {
this.form = this.form.map((item) => {
// getLastMeter
const meter = res.data.find(
(m) => String(m.roomId) === String(item.id)
);
console.log(meter, "meter");
if (meter) {
return {
...item,
lastMeterReading: meter.thisMeterReading,
electricMeterNumber: meter.meterNumber,
};
}
return item;
});
// } else {
// // res.data
// this.form = [
// {
// lastMeterReading: "",
// // meterNumber: "",
// thisMeterReading: "",
// },
// ];
// }
},
async getRoomByHouseId(id) {
const res = await getRoomByHouseId({ houseId: id });
if (res.code == 200) {
console.log(res.data, "res.data");
const data = res.data;
if (this.energyMeterConfig == 1) {
this.form = [{}];
} else if (this.energyMeterConfig == 2) {
this.form = res.data;
}
this.getLastMeter();
console.log(this.form, "this.form");
// if (this.waterMeterConfig == 1 && this.energyMeterConfig == 1) {
// this.sbList = [];
// this.dbList = [];
// } else if (this.waterMeterConfig == 1 && this.energyMeterConfig == 2) {
// this.sbList = [];
// this.dbList = data;
// } else if (this.waterMeterConfig == 2 && this.energyMeterConfig == 1) {
// this.sbList = data;
// this.dbList = [];
// }
}
},
onSubmit() {
@ -443,26 +545,80 @@ export default {
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;
// }
// /
for (let i = 0; i < this.form.length; i++) {
const item = this.form[i];
if (this.energyMeterConfig == 2) {
// if (!item.electricMeterNumber) {
// 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}个房间请填写本次表数`,
icon: "none",
});
return;
}
if (!item.fileList || item.fileList.length === 0) {
uni.showToast({
title: `${i + 1}个房间请上传图片/视频`,
icon: "none",
});
return;
}
} else {
// if (!item.electricMeterNumber) {
// uni.showToast({
// title: ``,
// icon: "none",
// });
// return;
// }
if (!item.lastMeterReading && item.lastMeterReading !== 0) {
uni.showToast({
title: `请填写上次表数`,
icon: "none",
});
return;
}
if (!item.thisMeterReading && item.thisMeterReading !== 0) {
uni.showToast({
title: `请填写本次表数`,
icon: "none",
});
return;
}
if (!item.fileList || item.fileList.length === 0) {
uni.showToast({
title: `请上传图片/视频`,
icon: "none",
});
return;
}
}
}
this.submitAdd();
console.log("onSubmit", this.form);
},
async submitAdd() {
let params = this.form.map((item) => ({
meterNumber: item.meterNumber,
meterType: 1,
meterNumber: item.electricMeterNumber,
meterType: 1,
houseId: this.blockForm.houseId,
roomId: this.blockForm.roomId,
lastMeterReading: parseFloat(item.lastMeterReading).toFixed(2),
thisMeterReading: parseFloat(item.thisMeterReading).toFixed(2),
roomId: item.id || "",
lastMeterReading: parseFloat(item.lastMeterReading).toFixed(4),
thisMeterReading: parseFloat(item.thisMeterReading).toFixed(4),
images: (item.fileList || []).map((f) => ({
url: f.url,
name: f.name,

501
pagesA/sdPage/sfReport.vue

@ -1,28 +1,47 @@
<template>
<view class="page-content sfReport">
<view class="bg-box">
<view class="bg-text">
<view class="bg-text">
<view>填写信息</view>
<view>请您填写相关问题</view>
</view>
<image class="bg-img" src="/static/img/bsorbxBac.png" mode="aspectFill"></image>
</view>
<image
class="bg-img"
src="/static/img/bsorbxBac.png"
mode="aspectFill"
></image>
</view>
<view class="info-card">
<view class="meter-row">
<view class="meter-label">
<view style="color: #f93838;margin-right: 4rpx;font-size: 24rpx;">*</view>
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>乐业社区</text>
</view>
<view class="picker-label">
<picker mode="selector" :range="deptNames" @change="onPickerChange($event,'乐业社区')">
<view :style="{'color':!form.apartmentName?'#cbcbcb':''}">{{form.apartmentName || pickerPlaceholder}}</view>
<picker
mode="selector"
:range="deptNames"
@change="onPickerChange($event, '乐业社区')"
>
<view
:style="{ color: !blockForm.apartmentName ? '#cbcbcb' : '' }"
>{{ blockForm.apartmentName || pickerPlaceholder }}</view
>
</picker>
<image class="arrow-r" src="/static/img/arrow-right.png" mode="aspectFill"></image>
<image
class="arrow-r"
src="/static/img/arrow-right.png"
mode="aspectFill"
></image>
</view>
</view>
<view class="meter-row">
<view class="meter-label">
<view style="color: #f93838;margin-right: 4rpx;font-size: 24rpx;">*</view>
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>房屋</text>
</view>
<view class="picker-label">
@ -42,53 +61,84 @@
}}</view>
</picker>
</view>
<view v-else @click="handleShowToast" style="color:#cbcbcb">请选择社区</view>
<image class="arrow-r" src="/static/img/arrow-right.png" mode="aspectFill"></image>
<view v-else @click="handleShowToast" style="color: #cbcbcb"
>请选择社区</view
>
<image
class="arrow-r"
src="/static/img/arrow-right.png"
mode="aspectFill"
></image>
</view>
</view>
</view>
<scroll-view class="house-view" scroll-y="true">
<view class="section-card" v-for="(item,index) in form.waterMeters" :key="item.id">
<view class="section-card" v-for="(item, index) in form" :key="index">
<view class="meter-row">
<text class="meter-label">水表号</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>水表号</text>
</view>
<u-input
v-model="item.meterNumber"
v-model="item.waterMeterNumber"
type="digit"
placeholder="请输入水表号"
border="none"
:disabled="!!item.meterNumber"
:custom-style="item.meterNumber ? 'background:#fff;color:#bbb;' : ''"
:disabled="!!item.waterMeterNumber"
:custom-style="
item.waterMeterNumber ? 'background:#fff;color:#bbb;' : ''
"
/>
</view>
<view class="meter-row">
<text class="meter-label">上次表数</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>上次表数</text>
</view>
<u-input
v-model="item.lastMeterReading"
v-model="form[index].lastMeterReading"
type="digit"
placeholder="请输入上次表数"
border="none"
:disabled="!!item.lastMeterReading"
:custom-style="item.lastMeterReading ? 'background:#fff;color:#bbb;' : ''"
:custom-style="
form[index].electricMeterNumber
? 'background:#fff;color:#bbb;'
: ''
"
/>
</view>
<view class="meter-row">
<text class="meter-label">本次表数</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>本次表数</text>
</view>
<u-input
v-model="item.thisMeterReading"
v-model="form[index].thisMeterReading"
type="digit"
placeholder="请输入本次表数"
border="none"
/>
</view>
<view class="imeter-row">
<text class="meter-label">上传图片/视频</text>
<view class="meter-label">
<view style="color: #f93838; margin-right: 4rpx; font-size: 24rpx"
>*</view
>
<text>图片/视频</text>
</view>
<u-upload
:max-count="10"
:multiple="true"
: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"
@ -100,7 +150,11 @@
@click.stop="() => chooseMedia(index)"
>
<view class="icon-box">
<image class="camera-icon" src="/static/img/camera-icon.png" mode="aspectFill"></image>
<image
class="camera-icon"
src="/static/img/camera-icon.png"
mode="aspectFill"
></image>
</view>
<view class="upload-tips">点击上传</view>
</view>
@ -109,57 +163,60 @@
</view>
</scroll-view>
<!-- 提交按钮 -->
<view class="btn" @click="onSubmit">提交</view>
<view class="btn" @click="onSubmit">提交</view>
</view>
</template>
<script>
import {
queryDeptDropdownList,
} from "@/common/rec";
import { getdeptList } from '@/common/api';
import { queryDeptDropdownList } from "@/common/rec";
import { getdeptList } from "@/common/api";
import {
uploadImage,
queryLastMeterReading,
submitWaterAndElectricity
} from '@/pages/api';
submitWaterAndElectricity,
getRoomByHouseId,
getHouseInfo,
} from "@/pages/api";
export default {
data() {
return {
pickerPlaceholder: '请选择', //
pickerPlaceholder: "请选择", //
waterMeter: 3245.1,
electricMeter: 2672.6,
remark: '',
remark: "",
fileList: [],
deptNames: [],
deptOptions: [],
blockForm: {},
buildingOptions: [],
unitOptions: [],
houseOptions: [],
multiArray: [[], [], []],
multiIndex: [-1, -1, -1],
form:{
apartmentId: '',
apartmentName:'',
buildingId: '',
unitId: '',
houseId: '',
roomId: '',
waterMeters: [],
remark: ''
},
}
form: [
{
meterNumber: "",
meterType: 2, // 1: 2:
houseId: "", //
roomId: "",
lastMeterReading: "",
thisMeterReading: "",
fileList: [],
remark: "",
waterMeterNumber: "",
},
], //
waterMeterConfig: "",
};
},
watch: {
"form.apartmentId": {
"blockForm.apartmentId": {
handler(newVal, oldVal) {
console.log("newVal", newVal);
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 = [];
@ -168,11 +225,11 @@ export default {
immediate: true,
},
},
onLoad () {
this.getTree()
onLoad() {
this.getTree();
},
methods: {
getTree(){
getTree() {
getdeptList().then(async (res) => {
this.deptOptions = this.handleTree(
res.data,
@ -209,8 +266,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",
@ -221,7 +278,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",
@ -231,13 +288,21 @@ 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.form.roomId = houseArray[0].roomId;
this.blockForm.houseId = houseArray[0].id;
this.energyMeterConfig = houseArray[0].energyMeterConfig;
this.waterMeterConfig = houseArray[0].waterMeterConfig;
if (this.energyMeterConfig == 1) {
this.getHouseInfoBy(this.blockForm.houseId);
} else if (this.energyMeterConfig == 2) {
this.getRoomByHouseId(this.blockForm.houseId);
}
this.getLastMeter();
this.blockForm.roomId = houseArray[0].roomId;
let house = houseArray[0];
// for (let index = 0; index < house.type; index++) {
// this.form.waterMeters.push({
@ -251,52 +316,64 @@ export default {
this.multiArray = [buildingNames, unitNames, houseNames];
}
},
handleShowToast(){
uni.showToast({ title: '请选择乐业社区', icon: 'none' });
handleShowToast() {
uni.showToast({ title: "请选择乐业社区", icon: "none" });
},
async bindMultiPickerColumnChange (e) {
if(!this.multiArray[0].length) return
console.log('修改的列为:' + e.detail.column + ',值为:' + e.detail.value)
this.multiIndex[e.detail.column] = e.detail.value
async bindMultiPickerColumnChange(e) {
if (!this.multiArray[0].length) return;
this.multiIndex[e.detail.column] = e.detail.value;
switch (e.detail.column) {
case 0: {
const unitArray = await this.getListByParentId("3", this.buildingOptions[e.detail.value].id);
this.unitOptions = 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
this.form.roomId = houseArray[0].roomId
this.multiArray[1] = unitNames
this.multiArray[2] = houseNames
}//1
this.multiIndex.splice(1, 1, 0)
this.multiIndex.splice(2, 1, 0)
break
case 1:{
const houseArray = await this.getListByParentId("4", this.unitOptions[e.detail.value].id);
this.houseOptions = houseArray
const houseNames = houseArray.map(item=> item.name)
this.form.houseId = houseArray[0].id
this.form.roomId = houseArray[0].roomId
case 0:
{
const unitArray = await this.getListByParentId(
"3",
this.buildingOptions[e.detail.value].id
);
this.unitOptions = unitArray;
const unitNames = unitArray.map((item) => item.name);
this.blockForm.unitId = unitArray[0].id;
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
console.log(this.houseOptions[e.detail.value]);
const houseArray = await this.getListByParentId(
"4",
unitArray[0].id
);
this.houseOptions = houseArray;
const houseNames = houseArray.map((item) => item.name);
this.blockForm.houseId = houseArray[0].id;
this.blockForm.roomId = houseArray[0].roomId;
this.multiArray[1] = unitNames;
this.multiArray[2] = houseNames;
}
this.multiIndex.splice(1, 1, 0);
this.multiIndex.splice(2, 1, 0);
break;
case 1:
{
const houseArray = await this.getListByParentId(
"4",
this.unitOptions[e.detail.value].id
);
this.houseOptions = houseArray;
const houseNames = houseArray.map((item) => item.name);
this.blockForm.houseId = houseArray[0].id;
this.blockForm.roomId = houseArray[0].roomId;
this.multiArray[2] = houseNames;
}
this.multiIndex.splice(2, 1, 0);
break;
case 2: {
this.blockForm.houseId = this.houseOptions[e.detail.value].id;
this.blockForm.roomId = this.houseOptions[e.detail.value].roomId;
this.waterMeterConfig =
this.houseOptions[e.detail.value].waterMeterConfig;
if (this.waterMeterConfig == 1) {
this.getHouseInfoBy(this.blockForm.houseId);
} else if (this.waterMeterConfig == 2) {
this.getRoomByHouseId(this.blockForm.houseId);
}
}
}
this.getLastMeter()
this.$forceUpdate()
this.$forceUpdate();
},
//
oversize(e) {
@ -304,11 +381,11 @@ export default {
return false;
},
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,
@ -327,7 +404,7 @@ 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,
@ -335,7 +412,9 @@ export default {
});
}
// imageList
this.form.waterMeters[index].imageList = this.form.waterMeters[index].fileList.map((v) => v.url);
this.form[index].imageList = this.form[index].fileList.map(
(v) => v.url
);
} catch (e) {
uni.showToast({ title: "上传失败", icon: "none" });
} finally {
@ -347,72 +426,147 @@ export default {
},
});
},
//
async getHouseInfoBy(id) {
const res = await getHouseInfo(id);
if (res.code == 200) {
this.form = this.form.map((item) => ({
...item,
waterMeterNumber: res.data.waterMeterNumber,
}));
}
},
async getLastMeter() {
const params = {
houseId: this.form.houseId,
roomId: this.form.roomId,
meterType: 1, // 12
houseId: this.blockForm.houseId,
roomId: this.blockForm.roomId,
meterType: 2, // 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: [],
},
];
this.form = this.form.map((item) => {
const meter = res.data.find(
(m) => String(m.roomId) === String(item.id)
);
if (meter) {
return {
...item,
lastMeterReading: meter.thisMeterReading,
waterMeterNumber: meter.meterNumber,
};
}
return item;
});
},
async getRoomByHouseId(id) {
const res = await getRoomByHouseId({ houseId: id });
if (res.code == 200) {
if (this.waterMeterConfig == 1) {
this.form = [{}];
} else if (this.waterMeterConfig == 2) {
this.form = res.data;
}
this.getLastMeter();
}
},
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);
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);
}
},
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' });
return
let { buildingId, unitId, houseId } = this.blockForm;
if (!this.blockForm.apartmentName) {
uni.showToast({ title: "请选择乐业社区", icon: "none" });
return;
} else if (!buildingId && !unitId && !houseId) {
uni.showToast({ title: "请选择房屋", icon: "none" });
return;
}
// /
for (let i = 0; i < this.form.length; i++) {
const item = this.form[i];
if (this.waterMeterConfig == 2) {
if (!item.electricMeterNumber) {
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}个房间请填写本次表数`,
icon: "none",
});
return;
}
if (!item.fileList || item.fileList.length === 0) {
uni.showToast({
title: `${i + 1}个房间请上传图片/视频`,
icon: "none",
});
return;
}
} else {
// if (!item.electricMeterNumber) {
// uni.showToast({
// title: ``,
// icon: "none",
// });
// return;
// }
if (!item.lastMeterReading && item.lastMeterReading !== 0) {
uni.showToast({
title: `请填写上次表数`,
icon: "none",
});
return;
}
if (!item.thisMeterReading && item.thisMeterReading !== 0) {
uni.showToast({
title: `请填写本次表数`,
icon: "none",
});
return;
}
if (!item.fileList || item.fileList.length === 0) {
uni.showToast({
title: `请上传图片/视频`,
icon: "none",
});
return;
}
}
}
this.submitAdd();
console.log('onSubmit',this.form);
console.log("onSubmit", this.form);
},
async submitAdd() {
let params = [];
this.form.waterMeters.forEach((item) => {
params.push({
meterNumber: item.meterNumber,
meterType: 1, // 12
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");
let params = this.form.map((item) => ({
meterNumber: item.waterMeterNumber,
meterType: 2,
houseId: this.blockForm.houseId,
roomId: item.id || "",
lastMeterReading: parseFloat(item.lastMeterReading).toFixed(4),
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 || "",
}));
const res = await submitWaterAndElectricity(params);
if (res.code == 200) {
uni.showToast({
@ -435,14 +589,13 @@ export default {
icon: "none",
});
}
console.log(res, "reeees");
}
}
}
},
},
};
</script>
<style scoped>
.page-content{
.page-content {
background: #f7f7f7;
min-height: 100vh;
padding-bottom: 40rpx;
@ -455,23 +608,23 @@ export default {
position: relative;
display: flex;
}
.bg-img{
.bg-img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.bg-text{
.bg-text {
margin: 50rpx 0 0 28rpx;
z-index: 1;
font-size: 44rpx;
color:#101010;
color: #101010;
font-weight: bold;
}
.bg-text view:nth-child(2){
.bg-text view:nth-child(2) {
font-size: 28rpx;
color:#666666;
color: #666666;
margin-top: 10rpx;
font-weight: 400;
}
@ -481,11 +634,11 @@ export default {
border-radius: 20rpx;
margin: -100rpx 24rpx 16rpx 24rpx;
padding: 24rpx 24rpx 12rpx 24rpx;
box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
position: relative;
z-index: 2;
}
.house-view{
.house-view {
height: calc(100vh - 600rpx);
}
.room-title {
@ -515,7 +668,7 @@ export default {
margin-bottom: 18rpx;
}
.device-row {
display: flex;
display: flex;
align-items: center;
padding: 0 24rpx;
min-height: 64rpx;
@ -544,12 +697,12 @@ display: flex;
color: #68758b;
font-size: 28rpx;
}
.picker-label{
.picker-label {
display: flex;
align-items: center;
font-size: 28rpx;
}
.arrow-r{
.arrow-r {
width: 30rpx;
height: 30rpx;
margin-left: 8rpx;
@ -576,7 +729,7 @@ display: flex;
justify-content: center;
margin: 20rpx 16rpx 0 0;
}
.icon-box{
.icon-box {
width: 60rpx;
height: 60rpx;
background: #ceeced;
@ -585,7 +738,7 @@ display: flex;
align-items: center;
justify-content: center;
}
.camera-icon{
.camera-icon {
width: 36rpx;
height: 36rpx;
}
@ -634,7 +787,7 @@ display: flex;
</style>
<style>
.sfReport .u-input__content__field-wrapper__field{
.sfReport .u-input__content__field-wrapper__field {
text-align: right !important;
}
</style>

17
store/user.js

@ -1,18 +1,35 @@
// store/user.js
const state = {
userInfo: null,
token:uni.getStorageSync('token') || null,
};
const mutations = {
SET_USER_INFO(state, info) {
state.userInfo = info;
},
SET_TOKEN(state, token) {
state.token = token;
},
LOGOUT(state) {
state.userInfo = null;
state.token = null;
},
};
const actions = {
setUserInfo({ commit }, info) {
commit("SET_USER_INFO", info);
},
setToken({ commit }, token) {
commit("SET_TOKEN", token);
uni.setStorageSync('token', token);
},
logout({ commit }) {
commit("LOGOUT");
uni.removeStorageSync('token');
uni.removeStorageSync('userInfo');
},
};
export default {

4
utils/request.js

@ -1,9 +1,9 @@
// utils/request.js
import { baseUrl } from "./config";
import store from "@/store";
export default function request(options = {}) {
// 获取token(假设存储在本地storage)
const token = uni.getStorageSync('token') || '';
const token = uni.getStorageSync('token') || store.state.user.token;
return new Promise((resolve, reject) => {
uni.request({

Loading…
Cancel
Save