index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. balance: 0.00
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function(options) {
  14. this.setData({
  15. balance_pay_pwd: wx.getStorageSync('balance_pay_pwd')
  16. })
  17. },
  18. onShow: function() {
  19. AUTH.checkHasLogined().then(isLogined => {
  20. if (!isLogined) {
  21. AUTH.login(this)
  22. } else {
  23. this.userAmount()
  24. }
  25. })
  26. },
  27. async userAmount() {
  28. const res = await WXAPI.userAmount(wx.getStorageSync('token'))
  29. if (res.code === 0) {
  30. this.setData({
  31. balance: res.data.balance
  32. })
  33. }
  34. },
  35. async bindSave() {
  36. let minWidthAmount = wx.getStorageSync('WITHDRAW_MIN');
  37. if (!minWidthAmount) {
  38. minWidthAmount = 0
  39. }
  40. const amount = this.data.amount;
  41. if (!amount) {
  42. wx.showToast({
  43. title: '请填写正确的提现金额',
  44. icon: 'none',
  45. })
  46. return
  47. }
  48. if (this.data.balance_pay_pwd && !this.data.pwd) {
  49. wx.showToast({
  50. title: '请输入交易密码',
  51. icon: 'none'
  52. })
  53. return
  54. }
  55. if (amount * 1 < minWidthAmount) {
  56. wx.showToast({
  57. title: '提现金额不能低于' + minWidthAmount,
  58. icon: 'none',
  59. })
  60. return
  61. }
  62. const res = await WXAPI.withDrawApplyV2({
  63. token: wx.getStorageSync('token'),
  64. money: amount,
  65. pwd: this.data.pwd
  66. })
  67. if (res.code == 0) {
  68. wx.showModal({
  69. title: '成功',
  70. content: '您的提现申请已提交,等待财务打款',
  71. showCancel: false,
  72. success: function(res) {
  73. if (res.confirm) {
  74. wx.navigateBack({
  75. delta: 0,
  76. })
  77. }
  78. }
  79. })
  80. } else {
  81. wx.showToast({
  82. title: res.msg,
  83. icon: 'none'
  84. })
  85. }
  86. }
  87. })