index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.openLoginDialog()
  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. processLogin(e) {
  36. if (!e.detail.userInfo) {
  37. wx.showToast({
  38. title: '已取消',
  39. icon: 'none',
  40. })
  41. return;
  42. }
  43. AUTH.register(this);
  44. },
  45. async bindSave() {
  46. let minWidthAmount = wx.getStorageSync('WITHDRAW_MIN');
  47. if (!minWidthAmount) {
  48. minWidthAmount = 0
  49. }
  50. const amount = this.data.amount;
  51. if (!amount) {
  52. wx.showToast({
  53. title: '请填写正确的提现金额',
  54. icon: 'none',
  55. })
  56. return
  57. }
  58. if (this.data.balance_pay_pwd && !this.data.pwd) {
  59. wx.showToast({
  60. title: '请输入交易密码',
  61. icon: 'none'
  62. })
  63. return
  64. }
  65. if (amount * 1 < minWidthAmount) {
  66. wx.showToast({
  67. title: '提现金额不能低于' + minWidthAmount,
  68. icon: 'none',
  69. })
  70. return
  71. }
  72. const res = await WXAPI.withDrawApplyV2({
  73. token: wx.getStorageSync('token'),
  74. money: amount,
  75. pwd: this.data.pwd
  76. })
  77. if (res.code == 0) {
  78. wx.showModal({
  79. title: '成功',
  80. content: '您的提现申请已提交,等待财务打款',
  81. showCancel: false,
  82. success: function(res) {
  83. if (res.confirm) {
  84. wx.navigateBack({
  85. delta: 0,
  86. })
  87. }
  88. }
  89. })
  90. } else {
  91. wx.showToast({
  92. title: res.msg,
  93. icon: 'none'
  94. })
  95. }
  96. }
  97. })