Browse Source

水电联调

fenbao
wangyx 3 months ago
parent
commit
a67602b530
  1. 16
      pages/api.js
  2. 4
      pages/login/login.vue
  3. 4
      pages/tabBar/mine/index.vue
  4. 8
      pages/tabBar/work/index.vue
  5. 234
      pagesA/sdPage/dfReport.vue
  6. 451
      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, 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() { export function logout() {

4
pages/login/login.vue

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

4
pages/tabBar/mine/index.vue

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

8
pages/tabBar/work/index.vue

@ -103,8 +103,8 @@ export default {
{ image: "/static/img/记录.png", text: "巡检记录" }, { image: "/static/img/记录.png", text: "巡检记录" },
], ],
sdList: [ sdList: [
{ image: '/static/img/水费.png', text: '水量上报' }, { image: "/static/img/水费.png", text: "水量上报" },
{ image: '/static/img/电费.png', text: '电量上报' }, { image: "/static/img/电费.png", text: "电量上报" },
], ],
// bxList: [ // bxList: [
// { image: '/static/img/.png', text: '' }, // { image: '/static/img/.png', text: '' },
@ -118,7 +118,7 @@ export default {
}, },
onLoad() { onLoad() {
this.getRouter(); this.getRouter();
if (!uni.getStorageSync("token")) { if (!this.$store.state.user.token) {
uni.redirectTo({ uni.redirectTo({
url: "/pages/login/login", url: "/pages/login/login",
}); });
@ -132,7 +132,7 @@ export default {
function hasMenu(menu, name) { function hasMenu(menu, name) {
if (!menu) return false; if (!menu) return false;
if (Array.isArray(menu)) { 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.name === name) return true;
if (menu.children) return hasMenu(menu.children, name); if (menu.children) return hasMenu(menu.children, name);

234
pagesA/sdPage/dfReport.vue

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

451
pagesA/sdPage/sfReport.vue

@ -5,24 +5,43 @@
<view>填写信息</view> <view>填写信息</view>
<view>请您填写相关问题</view> <view>请您填写相关问题</view>
</view> </view>
<image class="bg-img" src="/static/img/bsorbxBac.png" mode="aspectFill"></image> <image
class="bg-img"
src="/static/img/bsorbxBac.png"
mode="aspectFill"
></image>
</view> </view>
<view class="info-card"> <view class="info-card">
<view class="meter-row"> <view class="meter-row">
<view class="meter-label"> <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> <text>乐业社区</text>
</view> </view>
<view class="picker-label"> <view class="picker-label">
<picker mode="selector" :range="deptNames" @change="onPickerChange($event,'乐业社区')"> <picker
<view :style="{'color':!form.apartmentName?'#cbcbcb':''}">{{form.apartmentName || pickerPlaceholder}}</view> mode="selector"
:range="deptNames"
@change="onPickerChange($event, '乐业社区')"
>
<view
:style="{ color: !blockForm.apartmentName ? '#cbcbcb' : '' }"
>{{ blockForm.apartmentName || pickerPlaceholder }}</view
>
</picker> </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> </view>
<view class="meter-row"> <view class="meter-row">
<view class="meter-label"> <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> <text>房屋</text>
</view> </view>
<view class="picker-label"> <view class="picker-label">
@ -42,53 +61,84 @@
}}</view> }}</view>
</picker> </picker>
</view> </view>
<view v-else @click="handleShowToast" style="color:#cbcbcb">请选择社区</view> <view v-else @click="handleShowToast" style="color: #cbcbcb"
<image class="arrow-r" src="/static/img/arrow-right.png" mode="aspectFill"></image> >请选择社区</view
>
<image
class="arrow-r"
src="/static/img/arrow-right.png"
mode="aspectFill"
></image>
</view> </view>
</view> </view>
</view> </view>
<scroll-view class="house-view" scroll-y="true"> <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"> <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 <u-input
v-model="item.meterNumber" v-model="item.waterMeterNumber"
type="digit" type="digit"
placeholder="请输入水表号" placeholder="请输入水表号"
border="none" border="none"
:disabled="!!item.meterNumber" :disabled="!!item.waterMeterNumber"
:custom-style="item.meterNumber ? 'background:#fff;color:#bbb;' : ''" :custom-style="
item.waterMeterNumber ? 'background:#fff;color:#bbb;' : ''
"
/> />
</view> </view>
<view class="meter-row"> <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 <u-input
v-model="item.lastMeterReading" v-model="form[index].lastMeterReading"
type="digit" type="digit"
placeholder="请输入上次表数" placeholder="请输入上次表数"
border="none" border="none"
:disabled="!!item.lastMeterReading" :custom-style="
:custom-style="item.lastMeterReading ? 'background:#fff;color:#bbb;' : ''" form[index].electricMeterNumber
? 'background:#fff;color:#bbb;'
: ''
"
/> />
</view> </view>
<view class="meter-row"> <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 <u-input
v-model="item.thisMeterReading" v-model="form[index].thisMeterReading"
type="digit" type="digit"
placeholder="请输入本次表数" placeholder="请输入本次表数"
border="none" border="none"
/> />
</view> </view>
<view class="imeter-row"> <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 <u-upload
:max-count="10" :max-count="10"
:multiple="true" :multiple="true"
: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"
@ -100,7 +150,11 @@
@click.stop="() => chooseMedia(index)" @click.stop="() => chooseMedia(index)"
> >
<view class="icon-box"> <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>
<view class="upload-tips">点击上传</view> <view class="upload-tips">点击上传</view>
</view> </view>
@ -114,52 +168,55 @@
</template> </template>
<script> <script>
import { queryDeptDropdownList } from "@/common/rec";
import { import { getdeptList } from "@/common/api";
queryDeptDropdownList,
} from "@/common/rec";
import { getdeptList } from '@/common/api';
import { import {
uploadImage, uploadImage,
queryLastMeterReading, queryLastMeterReading,
submitWaterAndElectricity submitWaterAndElectricity,
} from '@/pages/api'; getRoomByHouseId,
getHouseInfo,
} from "@/pages/api";
export default { export default {
data() { data() {
return { return {
pickerPlaceholder: '请选择', // pickerPlaceholder: "请选择", //
waterMeter: 3245.1, waterMeter: 3245.1,
electricMeter: 2672.6, electricMeter: 2672.6,
remark: '', remark: "",
fileList: [], fileList: [],
deptNames: [], deptNames: [],
deptOptions: [], deptOptions: [],
blockForm: {},
buildingOptions: [], buildingOptions: [],
unitOptions: [], unitOptions: [],
houseOptions: [], houseOptions: [],
multiArray: [[], [], []], multiArray: [[], [], []],
multiIndex: [-1, -1, -1], multiIndex: [-1, -1, -1],
form:{ form: [
apartmentId: '', {
apartmentName:'', meterNumber: "",
buildingId: '', meterType: 2, // 1: 2:
unitId: '', houseId: "", //
houseId: '', roomId: "",
roomId: '', lastMeterReading: "",
waterMeters: [], thisMeterReading: "",
remark: '' fileList: [],
remark: "",
waterMeterNumber: "",
}, },
} ], //
waterMeterConfig: "",
};
}, },
watch: { watch: {
"form.apartmentId": { "blockForm.apartmentId": {
handler(newVal, oldVal) { handler(newVal, oldVal) {
console.log("newVal", newVal); console.log("newVal", newVal);
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 = [];
@ -169,7 +226,7 @@ export default {
}, },
}, },
onLoad() { onLoad() {
this.getTree() this.getTree();
}, },
methods: { methods: {
getTree() { getTree() {
@ -209,8 +266,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",
@ -221,7 +278,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",
@ -231,13 +288,21 @@ 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;
this.form.roomId = houseArray[0].roomId; 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]; 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({
@ -252,51 +317,63 @@ export default {
} }
}, },
handleShowToast() { handleShowToast() {
uni.showToast({ title: '请选择乐业社区', icon: 'none' }); uni.showToast({ title: "请选择乐业社区", icon: "none" });
}, },
async bindMultiPickerColumnChange(e) { async bindMultiPickerColumnChange(e) {
if(!this.multiArray[0].length) return if (!this.multiArray[0].length) return;
console.log('修改的列为:' + e.detail.column + ',值为:' + e.detail.value) this.multiIndex[e.detail.column] = e.detail.value;
this.multiIndex[e.detail.column] = e.detail.value
switch (e.detail.column) { switch (e.detail.column) {
case 0: { case 0:
const unitArray = await this.getListByParentId("3", this.buildingOptions[e.detail.value].id); {
this.unitOptions = unitArray const unitArray = await this.getListByParentId(
const unitNames = unitArray.map(item=> item.name) "3",
this.form.unitId = unitArray[0].id this.buildingOptions[e.detail.value].id
);
const houseArray = await this.getListByParentId("4", unitArray[0].id); this.unitOptions = unitArray;
this.houseOptions = houseArray const unitNames = unitArray.map((item) => item.name);
const houseNames = houseArray.map(item=> item.name) this.blockForm.unitId = unitArray[0].id;
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
this.multiArray[2] = houseNames const houseArray = await this.getListByParentId(
} //2 "4",
this.multiIndex.splice(2, 1, 0) unitArray[0].id
break );
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: { 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]); 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) { oversize(e) {
@ -304,11 +381,11 @@ export default {
return false; return false;
}, },
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,
@ -327,7 +404,7 @@ 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,
@ -335,7 +412,9 @@ export default {
}); });
} }
// imageList // 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) { } catch (e) {
uni.showToast({ title: "上传失败", icon: "none" }); uni.showToast({ title: "上传失败", icon: "none" });
} finally { } 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() { async getLastMeter() {
const params = { const params = {
houseId: this.form.houseId, houseId: this.blockForm.houseId,
roomId: this.form.roomId, roomId: this.blockForm.roomId,
meterType: 1, // 12 meterType: 2, // 2
meterNumber: "", meterNumber: "",
}; };
const res = await queryLastMeterReading(params); const res = await queryLastMeterReading(params);
if (Array.isArray(res.data) && res.data.length > 0) { this.form = this.form.map((item) => {
this.form.waterMeters = res.data.map((item, idx) => ({ const meter = res.data.find(
lastMeterReading: item.thisMeterReading, (m) => String(m.roomId) === String(item.id)
meterNumber: item.meterNumber, );
thisMeterReading: "", if (meter) {
fileList: [], return {
})); ...item,
} else { lastMeterReading: meter.thisMeterReading,
// res.data waterMeterNumber: meter.meterNumber,
this.form.waterMeters = [ };
{ }
lastMeterReading: "", return item;
meterNumber: "", });
thisMeterReading: "",
fileList: [],
}, },
]; 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) { 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].imageList = this.form.waterMeters[
) { // index
this.form.waterMeters[index].fileList.splice(event.index, 1); // ].fileList.map((v) => v.url);
// imageList
this.form.waterMeters[index].imageList = this.form.waterMeters[index].fileList.map((v) => v.url);
} }
}, },
onSubmit() { onSubmit() {
let {buildingId, unitId, houseId} = this.form let { buildingId, unitId, houseId } = this.blockForm;
if(!this.form.apartmentName){ if (!this.blockForm.apartmentName) {
uni.showToast({ title: '请选择乐业社区', icon: 'none' }); uni.showToast({ title: "请选择乐业社区", icon: "none" });
return return;
} else if (!buildingId && !unitId && !houseId) { } else if (!buildingId && !unitId && !houseId) {
uni.showToast({ title: '请选择房屋', icon: 'none' }); uni.showToast({ title: "请选择房屋", icon: "none" });
return 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(); 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.waterMeterNumber,
params.push({ meterType: 2,
meterNumber: item.meterNumber, houseId: this.blockForm.houseId,
meterType: 1, // 12 roomId: item.id || "",
houseId: this.form.houseId, lastMeterReading: parseFloat(item.lastMeterReading).toFixed(4),
roomId: this.form.roomId, thisMeterReading: parseFloat(item.thisMeterReading).toFixed(4),
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() : ""),
}); })),
console.log(params, "params"); remark: item.remark || "",
}));
const res = await submitWaterAndElectricity(params); const res = await submitWaterAndElectricity(params);
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ uni.showToast({
@ -435,10 +589,9 @@ export default {
icon: "none", icon: "none",
}); });
} }
console.log(res, "reeees"); },
} },
} };
}
</script> </script>
<style scoped> <style scoped>

17
store/user.js

@ -1,18 +1,35 @@
// store/user.js // store/user.js
const state = { const state = {
userInfo: null, userInfo: null,
token:uni.getStorageSync('token') || null,
}; };
const mutations = { const mutations = {
SET_USER_INFO(state, info) { SET_USER_INFO(state, info) {
state.userInfo = info; state.userInfo = info;
}, },
SET_TOKEN(state, token) {
state.token = token;
},
LOGOUT(state) {
state.userInfo = null;
state.token = null;
},
}; };
const actions = { const actions = {
setUserInfo({ commit }, info) { setUserInfo({ commit }, info) {
commit("SET_USER_INFO", 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 { export default {

4
utils/request.js

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

Loading…
Cancel
Save