微信小店联盟带货小程序

withdraw.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. Page({
  2. data: {
  3. balance: '5280.00', // 可提现余额
  4. withdrawAmount: '', // 用户输入的提现金额
  5. withdrawMethods: [
  6. { id: 'alipay', name: '支付宝', icon: '/static/images/alipay.png' },
  7. { id: 'wechat', name: '微信', icon: '/static/images/wechat.png' },
  8. { id: 'bank', name: '银行卡', icon: '/static/images/bank.png' }
  9. ],
  10. selectedMethod: null,
  11. accountInfo: null
  12. },
  13. onLoad() {
  14. this.getUserBalance()
  15. this.getUserAccountInfo()
  16. },
  17. // 获取用户可提现余额
  18. getUserBalance() {
  19. // TODO: 调用后端API获取实际余额
  20. this.setData({
  21. balance: '5280.00'
  22. })
  23. },
  24. // 获取用户账户信息
  25. getUserAccountInfo() {
  26. // TODO: 调用后端API获取账户信息
  27. this.setData({
  28. accountInfo: {
  29. alipay: '138****1234',
  30. wechat: '微信用户',
  31. bank: {
  32. bankName: '中国银行',
  33. cardNumber: '**** **** **** 5678'
  34. }
  35. }
  36. })
  37. },
  38. // 选择提现方式
  39. selectWithdrawMethod(e) {
  40. const { id } = e.currentTarget.dataset
  41. this.setData({
  42. selectedMethod: id
  43. })
  44. },
  45. // 输入提现金额
  46. onAmountInput(e) {
  47. this.setData({
  48. withdrawAmount: e.detail.value
  49. })
  50. },
  51. // 全部提现
  52. withdrawAll() {
  53. this.setData({
  54. withdrawAmount: this.data.balance
  55. })
  56. },
  57. // 提现申请
  58. submitWithdraw() {
  59. const { withdrawAmount, selectedMethod, balance } = this.data
  60. // 验证提现金额
  61. if (!withdrawAmount) {
  62. wx.showToast({
  63. title: '请输入提现金额',
  64. icon: 'none'
  65. })
  66. return
  67. }
  68. const amount = parseFloat(withdrawAmount)
  69. const maxBalance = parseFloat(balance)
  70. if (isNaN(amount) || amount <= 0) {
  71. wx.showToast({
  72. title: '请输入有效的金额',
  73. icon: 'none'
  74. })
  75. return
  76. }
  77. if (amount > maxBalance) {
  78. wx.showToast({
  79. title: '提现金额不能超过可用余额',
  80. icon: 'none'
  81. })
  82. return
  83. }
  84. // 验证提现方式
  85. if (!selectedMethod) {
  86. wx.showToast({
  87. title: '请选择提现方式',
  88. icon: 'none'
  89. })
  90. return
  91. }
  92. // 确认提现
  93. wx.showModal({
  94. title: '确认提现',
  95. content: `确定要提现${withdrawAmount}元到${this.getMethodName(selectedMethod)}?`,
  96. success: (res) => {
  97. if (res.confirm) {
  98. this.processWithdraw()
  99. }
  100. }
  101. })
  102. },
  103. // 获取提现方式名称
  104. getMethodName(method) {
  105. const methodMap = {
  106. 'alipay': '支付宝',
  107. 'wechat': '微信',
  108. 'bank': '银行卡'
  109. }
  110. return methodMap[method] || '未知方式'
  111. },
  112. // 处理提现流程
  113. processWithdraw() {
  114. wx.showLoading({
  115. title: '提现处理中...'
  116. })
  117. // TODO: 调用后端API处理提现
  118. setTimeout(() => {
  119. wx.hideLoading()
  120. wx.showToast({
  121. title: '提现申请成功',
  122. icon: 'success'
  123. })
  124. // 更新余额
  125. const newBalance = (parseFloat(this.data.balance) - parseFloat(this.data.withdrawAmount)).toFixed(2)
  126. this.setData({
  127. balance: newBalance,
  128. withdrawAmount: ''
  129. })
  130. }, 1500)
  131. },
  132. // 管理收款账户
  133. manageAccounts() {
  134. wx.navigateTo({
  135. url: '/pages/bank/list'
  136. })
  137. }
  138. })