微信小店联盟带货小程序

withdraw.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // pages/distribution/withdraw.js
  2. Page({
  3. data: {
  4. balance: '1234.56',
  5. pendingAmount: '456.78',
  6. settledAmount: '777.78',
  7. amount: '',
  8. minWithdraw: 10,
  9. maxWithdraw: 50000,
  10. selectedMethod: 'wxpay',
  11. canWithdraw: false
  12. },
  13. onLoad: function (options) {
  14. this.loadBalance()
  15. },
  16. // 加载余额信息
  17. loadBalance: function () {
  18. // 模拟API请求
  19. setTimeout(() => {
  20. this.setData({
  21. balance: '1234.56',
  22. pendingAmount: '456.78',
  23. settledAmount: '777.78'
  24. })
  25. }, 500)
  26. },
  27. // 输入金额
  28. onAmountInput: function (e) {
  29. const amount = e.detail.value.trim()
  30. let canWithdraw = false
  31. if (amount) {
  32. const numAmount = parseFloat(amount)
  33. canWithdraw = numAmount >= this.data.minWithdraw &&
  34. numAmount <= this.data.maxWithdraw &&
  35. numAmount <= parseFloat(this.data.balance)
  36. }
  37. this.setData({
  38. amount,
  39. canWithdraw
  40. })
  41. },
  42. // 全部提现
  43. setMaxAmount: function () {
  44. const amount = this.data.balance
  45. const canWithdraw = parseFloat(amount) >= this.data.minWithdraw
  46. this.setData({
  47. amount,
  48. canWithdraw
  49. })
  50. },
  51. // 选择提现方式
  52. selectMethod: function (e) {
  53. const method = e.currentTarget.dataset.method
  54. this.setData({ selectedMethod: method })
  55. },
  56. // 提交提现
  57. submitWithdraw: function () {
  58. if (!this.data.canWithdraw) return
  59. const amount = parseFloat(this.data.amount)
  60. if (isNaN(amount)) {
  61. wx.showToast({
  62. title: '请输入正确的提现金额',
  63. icon: 'none'
  64. })
  65. return
  66. }
  67. // 根据提现方式判断
  68. if (this.data.selectedMethod === 'bank') {
  69. wx.navigateTo({
  70. url: '/pages/bank/list'
  71. })
  72. return
  73. }
  74. // 模拟提现请求
  75. wx.showLoading({
  76. title: '提现申请中...',
  77. mask: true
  78. })
  79. setTimeout(() => {
  80. wx.hideLoading()
  81. wx.showToast({
  82. title: '提现申请成功',
  83. icon: 'success',
  84. duration: 2000,
  85. success: () => {
  86. setTimeout(() => {
  87. wx.navigateBack()
  88. }, 2000)
  89. }
  90. })
  91. }, 1500)
  92. }
  93. })