electricity_bill_calc_wx/pages/workBench/components/recharge/index.js
2024-11-12 11:10:46 +08:00

131 lines
2.7 KiB
JavaScript

import { handleRecharge } from "../../../../service/recharge";
import { alertInfo, alertSuccess } from "../../../../utils/index";
import request from '../../../../utils/request'
const { OK } = request;
// pages/workBench/components/recharge/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
show: false,
},
/**
* 组件的方法列表
*/
methods: {
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: 'meter'
})
},
onConfirm(e) {
// console.log('e', e)
const { data, type, way } = e.detail;
console.log('e.detail', e.detail)
switch(type) {
case "park":
this.setData({
parkName: data.name,
park: data.id,
})
break;
case "meter":
this.setData({
meterName: `${data.meterNo}-${data.address}${data.tenement?.name ? '-' + data.tenement?.name : ''}`,
meter: data.id,
})
break;
case "pay":
this.setData({
payName: data,
way: way,
});
break;
}
this.onConcal();
},
onConcal() {
this.setData({
show: false,
title: "",
type: "",
})
},
onPayFocus() {
this.setData({
show: true,
title: "付款方式",
type: 'pay'
})
},
onChangeMoney(e) {
console.log('e', e)
this.setData({ money: e.detail })
},
onChangeVoucherNo(e) {
console.log('e', e)
this.setData({ voucherNo: e.detail })
},
async handleSubmit() {
const { park, meter, money, way, voucherNo } = this.data;
if (!park) {
alertInfo("请选择园区");
return;
}
if (!meter) {
alertInfo("请选择电表")
return;
}
if (!money) {
alertInfo("请输入金额")
return
}
if (!way && way !== 0) {
alertInfo("请选择付款方式")
return
}
if (!voucherNo) {
alertInfo("请输入凭证号")
return
}
const { code, message } = await handleRecharge(park, {
amount: `${money || ''}`,
meter,
paymentType: way,
voucherNo,
type: "0"
})
if (code !== OK) {
alertInfo(message)
return
}
alertSuccess("充值成功")
}
}
})