electricity_bill_calc_wx/pages/recharge/index.js
2024-03-21 09:38:10 +08:00

113 lines
2.0 KiB
JavaScript

import { getMeterDetail } from "../../service/meter";
import { getGlobalData, showModal } from "../../utils/index";
// pages/recharge/index.js
Page({
/**
* 页面的初始数据
*/
data: {
money: 0,
moneyIndex: -1,
primaryColor: getGlobalData().primaryColor,
defaultMoneyArray: [100, 200, 500, 1000, 2000],
customFlag: false,
detail: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { tenement, code } = options
this.init({ tenement, code })
},
async init(options) {
const { code, message, data = {}} = await getMeterDetail(options)
this.setData({
detail: data
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
chooseMoney(e) {
const { money, index } = e.currentTarget.dataset;
this.setData({
money,
moneyIndex: Number(index),
customFlag: false,
});
},
onChangeCode(e) {
const { codes } = this.data;
const index = Number(e.detail.value);
this.setData({
code: codes[index]
})
},
custom() {
this.setData({
moneyIndex: -1,
customFlag: true,
})
},
onChangeCustomMoney(e) {
const money = e.detail.value;
this.setData({
money: money,
})
},
async recharge() {
const { detail = {}, money } = this.data;
const confirmResult = await showModal({ title: "充值确认", content: `确认充值表号为${detail?.meter?.code}的表计${money}元吗?` });
if (!confirmResult) {
return;
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})