Files
electricity_bill_calc_wx/pages/workBenchNew/components/installMeter/index.js
2025-11-03 16:26:30 +08:00

379 lines
7.4 KiB
JavaScript

// pages/workBenchNew/components/createMeter/index.js
import dayjs from "../../../../utils/dayjs"
import { alertInfo, alertSuccess, loadingFunc } from "../../../../utils/index"
import { uploadInstallMeter } from "../../../../service/public"
import request from "../../../../utils/request"
import { installMeter } from "../../../../service/meter"
const { OK } = request
Page({
/**
* 页面的初始数据
*/
data: {
time: "",
area: "",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({
time: dayjs().format("YYYY-MM-DD HH:mm:ss")
})
},
onParkFocus(e) {
this.setData({
show: true,
title: "园区",
type: 'park'
})
},
onMeterFocus(e) {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "电表",
type: 'inventoryMeter'
})
},
onBuildingFocus() {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "建筑",
type: 'building'
})
},
clearImage() {
this.setData({
url: ""
})
},
onMeterBoxFocus() {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "电表箱",
type: 'meterBox'
})
},
onMeterTypeFocus() {
this.setData({
show: true,
title: "电表类型",
type: 'meterType'
})
},
onBindCard() {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "卡",
type: 'card'
})
},
onBindCollectionA() {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "采集器A",
type: 'collection',
collection: "A"
})
},
onBindCollectionB() {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "采集器B",
type: 'collection',
collection: "B"
})
},
onBindCollectionC() {
const { park } = this.data;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "采集器C",
type: 'collection',
collection: "C"
})
},
uploadImage() {
const that = this;
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
success: async function(res) {
console.log("res", res)
const path = res.tempFiles?.[0]?.tempFilePath.toLowerCase()
if (!/(\.jpg|\.png|\.jpeg)$/.test(path)) {
wx.showToast({
title: '请上传jpg、png或jpeg格式的图片',
icon: 'none',
});
return;
}
var tempFilePaths = path;
loadingFunc(async () => {
const { code, message, url } = await uploadInstallMeter(tempFilePaths)
if (code !== OK) {
alertError(message)
return
}
that.setData({
url: url
})
})
}
})
},
onConfirm(e) {
const { type, data = {} } = e.detail;
const {collection} = this.data;
switch(type) {
case "park":
this.setData({
park: data.id,
parkName: data.name,
})
break;
case "tenement":
this.setData({
tenement: data.id,
tenementName: data.name,
})
break;
case "inventoryMeter":
this.setData({
meter: data.id,
meterName: data?.sn,
})
break;
case "building":
this.setData({
building: data.id,
buildingName: data.name,
});
break;
case "meterBox":
this.setData({
meterBox: data.id,
meterBoxName: data.address,
});
break;
case "tenement":
this.setData({
tenement: data.id,
tenementName: data.name,
})
break;
case "meterType":
this.setData({
meterType: data.way,
meterTypeName: data,
});
break;
case "meter":
this.setData({
meter: data.id,
meterName: data.address,
});
break;
case "card":
this.setData({
card: data.id,
cardName: data.sim_number,
});
break;
case "collection":
let newData = {}
if (collection === "A") {
newData = {
collectionA: data.id,
collectionAName: data.name,
}
}
if (collection === "B") {
newData = {
collectionB: data.id,
collectionBName: data.name,
}
}
if (collection === "C") {
newData = {
collectionC: data.id,
collectionCName: data.name,
}
}
this.setData(newData);
break;
}
this.onCancel();
},
changeAddress(e) {
this.setData({
address: e.detail
})
},
changeArea(e) {
this.setData({
area: e.detail
})
},
changeOverall(e) {
this.setData({
overall: e.detail
})
},
changeSharp(e) {
this.setData({
sharp: e.detail
})
},
changePeak(e) {
this.setData({
sharp: e.detail
})
},
changeFlat(e) {
this.setData({
flat: e.detail
})
},
changeValley(e) {
this.setData({
valley: e.detail
})
},
changeRatio(e) {
this.setData({
ratio: e.detail,
})
},
onCancel() {
this.setData({
show: false,
title: "",
type: "",
})
},
onTenementFocus(e) {
const { park } = this.data;
const that = this;
if (!park) {
alertInfo("请先选择园区")
return;
}
this.setData({
show: true,
title: "商户",
type: 'tenement'
})
},
async handleSubmit() {
const {
park, meter, address, building, meterBox, meterType,
ratio, area, card, collectionA, collectionB, collectionC,
tenement, sharp, peak, flat, valley, overall, url
} = this.data;
if (!park || !meter || !address) {
alertInfo("请填写必填项后保存")
return;
}
console.log("data", this.data)
const { code, data, message } = await installMeter({
park, meter, address, building, meterBox, meterType,
ratio, area, card, collectionA, collectionB, collectionC,
tenement, sharp, peak, flat, valley, overall, url
})
if (code !== OK) {
alertInfo(message)
return;
}
alertSuccess("新增成功")
},
goback() {
wx.navigateBack()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})