123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- const app = getApp();
- Page({
- data: {
- images: {
- logo: '',
- background: '',
- card: '',
- tzd: "",
- phone: "",
- yl: "",
- jcsfcjtzd: ""
- },
- userInfo: {
- name: app.globalData.currentAccountInfo.username,
- id: app.globalData.currentAccountInfo.usernumber,
- address: app.globalData.currentAccountInfo.address
- },
- billInfo: {}, // 存储从首页传递过来的账单信息
- quickAmounts: [10, 30, 50, 100, 200, 500],
- waterUsage: {
- lastReading: 2000,
- currentReading: 2050,
- nextReading: 3020,
- usage: 87
- },
- showKeyboard: false,
- selectedAmount: null,
- customAmount: '',
- inputFocus: false,
- },
- onLoad(options) {
- // 接收从homepage传递的账单信息
- if (options.billInfo) {
- const billInfo = JSON.parse(decodeURIComponent(options.billInfo));
- debugger
- this.setData({
- amount: billInfo.amount, // 默认实缴金额为应缴金额
- actualAmount: billInfo.amountDue, // 设置应缴金额
- balance: billInfo.balance //余额
- });
- }
- this.setData({
- images: {
- logo:'/static_file/logo.png',
- background:'/static_file/background.png',
- card:'/static_file/card.png',
- tzd:'/static_file/backgrountzdd.png',
- phone:'/static_file/phone.png',
- yl:'/static_file/background.yl',
- jcsfcjtzd:'/static_file/jcsfcjtzd.png',
- kapiantubiao:'/static_file/kapiantubiao.png'
-
- }
- })
- // 获取状态栏高度
- const systemInfo = wx.getSystemInfoSync();
- debugger
- this.setData({
- statusBarHeight: systemInfo.statusBarHeight
- });
- this.fetchPaymentData();
- },
- // 选择快捷金额
- selectAmount: function(e) {
- const amount = e.currentTarget.dataset.amount;
- this.setData({
- amount: parseFloat(amount),
- selectedAmount: parseFloat(amount),
- customAmount: '' // 清空自定义金额
- });
- },
- // 立即缴费
- payNow: function() {
- wx.showLoading({
- title: '处理中',
- });
-
- // 模拟支付
- setTimeout(() => {
- wx.hideLoading();
- wx.showToast({
- title: '缴费成功',
- icon: 'success',
- duration: 2000,
- success: () => {
- // 支付成功后返回首页
- setTimeout(() => {
- wx.navigateBack();
- }, 2000);
- }
- });
- }, 1500);
- },
- // 返回上一页
- goBack: function() {
- wx.navigateBack();
- },
- // 切换到首页
- goToHome: function() {
- wx.switchTab({
- url: '/pages/homepage/homepage',
- });
- },
- // 切换到我的页面
- goToMine: function() {
- wx.switchTab({
- url: '/pages/mine/mine',
- });
- },
- // 添加切换水表的方法
- switchMeter: function() {
- wx.navigateTo({
- url: '/pages/switchMeter/switchMeter',
- })
- },
- navigateToHome() {
- wx.switchTab({
- url: '/pages/index/index'
- })
- },
- navigateToMine() {
- wx.switchTab({
- url: '/pages/mine/mine'
- })
- },
- // 显示键盘 - 使用微信内置键盘
- showCustomAmountInput: function() {
- // 使用微信内置的输入框
- wx.showModal({
- title: '请输入金额',
- placeholderText: '请输入缴费金额',
- editable: true,
- success: (res) => {
- if (res.confirm && res.content) {
- // 验证输入是否为有效数字
- const inputAmount = parseFloat(res.content);
- if (!isNaN(inputAmount) && inputAmount > 0) {
- this.setData({
- amount: inputAmount
- });
- } else {
- wx.showToast({
- title: '请输入有效金额',
- icon: 'none'
- });
- }
- }
- }
- });
- },
-
- // 输入数字
- inputNumber: function(e) {
- const number = e.currentTarget.dataset.number;
- let amount = this.data.amount;
-
- // 处理小数点
- if (number === '.' && amount.includes('.')) {
- return;
- }
-
- // 限制小数点后两位
- if (amount.includes('.') && amount.split('.')[1].length >= 2 && number !== '.') {
- return;
- }
-
- // 更新金额
- this.setData({
- amount: amount === '0' ? number : amount + number
- });
- },
-
- // 删除数字
- deleteNumber: function() {
- let amount = this.data.amount;
- if (amount.length <= 1) {
- this.setData({
- amount: '0'
- });
- } else {
- this.setData({
- amount: amount.substring(0, amount.length - 1)
- });
- }
- },
-
- // 确认输入
- confirmInput: function() {
- this.setData({
- showKeyboard: false
- });
- },
- // 添加自定义金额输入处理函数
- onCustomAmountInput: function(e) {
- let value = e.detail.value;
-
- // 限制只能输入小数点后两位
- if (value.indexOf('.') !== -1) {
- const parts = value.split('.');
- if (parts[1].length > 2) {
- value = parts[0] + '.' + parts[1].substring(0, 2);
- }
- }
-
- // 验证输入是否为有效数字
- if (value) {
- const inputAmount = parseFloat(value);
- if (!isNaN(inputAmount) && inputAmount >= 0) {
- // 更新实缴金额和自定义金额
- this.setData({
- amount: inputAmount,
- customAmount: value,
- selectedAmount: null // 取消快捷金额的选中状态
- });
- } else {
- this.setData({
- customAmount: value
- });
- }
- } else {
- // 输入框为空时
- this.setData({
- customAmount: '',
- amount: 0
- });
- }
- },
- // 输入框获得焦点
- onInputFocus: function() {
- this.setData({
- inputFocus: true,
- selectedAmount: null // 取消快捷金额的选中状态
- });
- },
-
- // 输入框失去焦点
- onInputBlur: function() {
- this.setData({
- inputFocus: false
- });
- },
- // 从接口获取支付数据
- fetchPaymentData: function() {
- // 这里是模拟数据,实际应用中应该调用真实接口
- // wx.request({
- // url: 'your-api-endpoint',
- // success: (res) => {
- // this.setData({
- // amountDue: res.data.amountDue,
- // balance: res.data.balance
- // });
- // }
- // });
-
- // this.setData({
- // amountDue: 150.00,
- // balance: 200.50
- // });
- },
- })
|