Files
electricity_bill_calc_wx/pages/readingHistory/components/editModal/index.js

118 lines
2.8 KiB
JavaScript

// pages/workBench/components/tenement/components/bindMeter/index.js
// 0015980101
import { createReading, updateReading } from "../../../../service/workBench"
import { getWorkMeterDetail } from "../../../../service/meter"
import { alertInfo, alertSuccess } from "../../../../utils/index";
import request from "../../../../utils/request"
import dayjs from "../../../../utils/dayjs"
const { OK } = request
Component({
/**
* 组件的属性列表
*/
properties: {
visible: Boolean,
title: String,
timeProps: String,
numberProps: String,
idProps: String,
meter: String,
park: String
},
observers: {
"timeProps": function(newValue) {
// console.log("newValue", newValue)
this.setData({
time: newValue,
// startTime: newValue
})
},
"numberProps": function(newValue) {
this.setData({
number: newValue
})
},
"idProps": function(newValue) {
console.log("new id", newValue)
}
},
/**
* 组件的初始数据
*/
data: {
dateTimeShow: false,
},
/**
* 组件的方法列表
*/
methods: {
onCancel() {
this.setData({
show: false,
title: "",
type: "",
})
// this.triggerEvent("close")
},
onClose() {
this.setData({
show: false,
title: "",
type: "",
})
},
onChange(e) {
const { name } = e.currentTarget.dataset;
this.setData({
[name]: e.detail
})
},
async onSubmit() {
const { time, number, idProps, park, meter, timeProps } = this.data;
if (time == null || number == null) {
alertInfo("请正确填写后保存")
return;
}
if (!idProps) {
const { code, message } = await createReading(park, meter, {
overall: `${number}`,
flat: `${number}`,
readAt: time
})
if (code !== OK) {
alertError(message)
return
}
alertSuccess("录入成功")
this.setData({ number: null, time: null, startTime: null })
} else {
const { code, message } = await updateReading(park, meter, new Date(timeProps).getTime(), {
overall: `${number}`,
flat: `${number}`,
})
if (code !== OK) {
alertError(message)
return
}
alertSuccess("录入成功")
this.setData({ number: null, time: null, startTime: null })
}
const that = this;
setTimeout(() => {
that.triggerEvent("ok")
}, 300)
},
dateTimeConfirm(e) {
this.setData({ time: e.detail.time, dateTimeShow: false })
},
dateTimeCancal(e) {
this.setData({ dateTimeShow: false })
},
onTimeFocus() {
this.setData({ dateTimeShow: true })
}
}
})