cash.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/cash/cash.js
  2. const app = getApp()
  3. var lock = require('../../utils/lock.js')
  4. var verify = require('../../utils/verify.js')
  5. var net = require('../../utils/net.js')
  6. var url = require('../../utils/url.js')
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. wallet: {},
  13. balance: 0,
  14. isNeedFinish: true,
  15. error: false,
  16. sum: 0,
  17. input: '',
  18. valueName: '',
  19. valueCard: '',
  20. hiddenDialog: true,
  21. },
  22. onLoad: function (options) {
  23. this.getWallet()
  24. },
  25. getWallet: function () {
  26. wx.showLoading({
  27. title: '',
  28. })
  29. net.connect({
  30. url: url.host + url.wallet,
  31. data: {},
  32. success: res => {
  33. wx.hideLoading()
  34. var _result = res.data.data
  35. this.data.wallet = _result
  36. this.data.balance = _result.totalFee - _result.applyFee - _result.finishFee
  37. this.data.isNeedFinish = _result.idcard == null
  38. this.setData({
  39. balance: this.data.balance
  40. })
  41. },
  42. })
  43. },
  44. cash: function (e) {
  45. var sum = e.detail.value.amount
  46. //验证是否为正整数或保留两位小数
  47. if (!verify.isTwoDecimals(sum)) {
  48. wx.showModal({
  49. title: '提示',
  50. content: '请填写正确的提现金额,最多保留两位小数',
  51. showCancel: false
  52. })
  53. return
  54. }
  55. sum = new Number(sum)
  56. //限制最低提现金额10元
  57. if (sum < 10) {
  58. wx.showModal({
  59. title: '提示',
  60. content: '提现金额不能低于10元',
  61. showCancel: false
  62. })
  63. return
  64. }
  65. //限制提现金额不超过当前可提现金额
  66. var balance = this.data.balance
  67. if (sum > balance / 100) {
  68. this.setData({
  69. error: true
  70. })
  71. return
  72. }
  73. this.data.sum = sum
  74. //是否需要完善信息
  75. if (this.data.isNeedFinish) {
  76. this.showDialog()
  77. return
  78. }
  79. //提现
  80. this.submitCash(sum)
  81. },
  82. submitCash: function (sum) {
  83. wx.showLoading({
  84. title: '',
  85. })
  86. net.connect({
  87. url: url.host + url.withdraw,
  88. data: {
  89. fee: parseInt(sum * 100),
  90. realName: this.data.wallet.realName,
  91. idcard: this.data.wallet.idcard
  92. },
  93. method: 'POST',
  94. success: res => {
  95. wx.hideLoading()
  96. wx.showToast({
  97. title: '已提交申请',
  98. mask: true
  99. })
  100. var balance = this.data.balance
  101. balance = Number((balance - sum * 100).toFixed(2))
  102. app.globalData.user.withdrawalbleFee = balance
  103. this.data.wallet.applyFee += sum * 100
  104. this.setData({
  105. balance: balance,
  106. error: false,
  107. input: ''
  108. })
  109. },
  110. })
  111. },
  112. finish: function (e) {
  113. var name = e.detail.value.name
  114. if (!verify.isRealName(name)) {
  115. wx.showToast({
  116. title: '请输入真实的姓名',
  117. icon: 'none'
  118. })
  119. return
  120. }
  121. var card = e.detail.value.card
  122. if (!verify.isIdentityCard(card)) {
  123. wx.showToast({
  124. title: '请输入正确的身份证号码',
  125. icon: 'none'
  126. })
  127. return
  128. }
  129. this.data.wallet.realName = name
  130. this.data.wallet.idcard = card
  131. this.data.isNeedFinish = this.data.wallet.idcard == null
  132. this.hiddenDialog()
  133. this.submitCash(this.data.sum)
  134. },
  135. toRecord: function () {
  136. if (lock.lockTapDelay()) {
  137. return
  138. }
  139. wx.navigateTo({
  140. url: '../cashRecord/cashRecord?applyFee=' + this.data.wallet.applyFee + '&finishFee=' + this.data.wallet.finishFee,
  141. })
  142. },
  143. showDialog: function () {
  144. this.setData({
  145. hiddenDialog: false,
  146. valueName: '',
  147. valueCard: '',
  148. })
  149. },
  150. hiddenDialog: function () {
  151. this.setData({
  152. hiddenDialog: true
  153. })
  154. }
  155. })