123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- Page({
- data: {
- balance: '5280.00', // 可提现余额
- withdrawAmount: '', // 用户输入的提现金额
- withdrawMethods: [
- { id: 'alipay', name: '支付宝', icon: '/static/images/alipay.png' },
- { id: 'wechat', name: '微信', icon: '/static/images/wechat.png' },
- { id: 'bank', name: '银行卡', icon: '/static/images/bank.png' }
- ],
- selectedMethod: null,
- accountInfo: null
- },
- onLoad() {
- this.getUserBalance()
- this.getUserAccountInfo()
- },
- // 获取用户可提现余额
- getUserBalance() {
- // TODO: 调用后端API获取实际余额
- this.setData({
- balance: '5280.00'
- })
- },
- // 获取用户账户信息
- getUserAccountInfo() {
- // TODO: 调用后端API获取账户信息
- this.setData({
- accountInfo: {
- alipay: '138****1234',
- wechat: '微信用户',
- bank: {
- bankName: '中国银行',
- cardNumber: '**** **** **** 5678'
- }
- }
- })
- },
- // 选择提现方式
- selectWithdrawMethod(e) {
- const { id } = e.currentTarget.dataset
- this.setData({
- selectedMethod: id
- })
- },
- // 输入提现金额
- onAmountInput(e) {
- this.setData({
- withdrawAmount: e.detail.value
- })
- },
- // 全部提现
- withdrawAll() {
- this.setData({
- withdrawAmount: this.data.balance
- })
- },
- // 提现申请
- submitWithdraw() {
- const { withdrawAmount, selectedMethod, balance } = this.data
- // 验证提现金额
- if (!withdrawAmount) {
- wx.showToast({
- title: '请输入提现金额',
- icon: 'none'
- })
- return
- }
- const amount = parseFloat(withdrawAmount)
- const maxBalance = parseFloat(balance)
- if (isNaN(amount) || amount <= 0) {
- wx.showToast({
- title: '请输入有效的金额',
- icon: 'none'
- })
- return
- }
- if (amount > maxBalance) {
- wx.showToast({
- title: '提现金额不能超过可用余额',
- icon: 'none'
- })
- return
- }
- // 验证提现方式
- if (!selectedMethod) {
- wx.showToast({
- title: '请选择提现方式',
- icon: 'none'
- })
- return
- }
- // 确认提现
- wx.showModal({
- title: '确认提现',
- content: `确定要提现${withdrawAmount}元到${this.getMethodName(selectedMethod)}?`,
- success: (res) => {
- if (res.confirm) {
- this.processWithdraw()
- }
- }
- })
- },
- // 获取提现方式名称
- getMethodName(method) {
- const methodMap = {
- 'alipay': '支付宝',
- 'wechat': '微信',
- 'bank': '银行卡'
- }
- return methodMap[method] || '未知方式'
- },
- // 处理提现流程
- processWithdraw() {
- wx.showLoading({
- title: '提现处理中...'
- })
- // TODO: 调用后端API处理提现
- setTimeout(() => {
- wx.hideLoading()
- wx.showToast({
- title: '提现申请成功',
- icon: 'success'
- })
- // 更新余额
- const newBalance = (parseFloat(this.data.balance) - parseFloat(this.data.withdrawAmount)).toFixed(2)
- this.setData({
- balance: newBalance,
- withdrawAmount: ''
- })
- }, 1500)
- },
- // 管理收款账户
- manageAccounts() {
- wx.navigateTo({
- url: '/pages/bank/list'
- })
- }
- })
|