index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../../utils/auth')
  3. const wxpay = require('../../../utils/pay.js')
  4. Page({
  5. data: {
  6. wxlogin: true,
  7. applyStatus: -2, // -1 表示未申请,0 审核中 1 不通过 2 通过
  8. applyInfo: {},
  9. canvasHeight: 0
  10. },
  11. onLoad: function (options) {
  12. this.setting()
  13. },
  14. onShow() {
  15. AUTH.checkHasLogined().then(isLogined => {
  16. if (isLogined) {
  17. this.doneShow();
  18. }
  19. })
  20. },
  21. async doneShow() {
  22. const _this = this
  23. const userDetail = await WXAPI.userDetail(wx.getStorageSync('token'))
  24. WXAPI.fxApplyProgress(wx.getStorageSync('token')).then(res => {
  25. let applyStatus = userDetail.data.base.isSeller ? 2 : -1
  26. if (res.code == 2000) {
  27. this.setData({
  28. wxlogin: false
  29. })
  30. return
  31. }
  32. if (res.code === 700) {
  33. _this.setData({
  34. applyStatus: applyStatus
  35. })
  36. }
  37. if (res.code === 0) {
  38. if (userDetail.data.base.isSeller) {
  39. applyStatus = 2
  40. } else {
  41. applyStatus = res.data.status
  42. }
  43. _this.setData({
  44. applyStatus: applyStatus,
  45. applyInfo: res.data
  46. })
  47. }
  48. })
  49. },
  50. goForm: function (e) {
  51. wx.navigateTo({
  52. url: "/packageFx/pages/apply/form"
  53. })
  54. },
  55. goShop: function (e) {
  56. wx.switchTab({
  57. url: '/pages/index/index',
  58. })
  59. },
  60. goFx: function (e) {
  61. wx.redirectTo({
  62. url: '/packageFx/pages/index/index',
  63. })
  64. },
  65. async setting() {
  66. const res = await WXAPI.fxSetting()
  67. if (res.code == 0) {
  68. this.setData({
  69. setting: res.data
  70. })
  71. }
  72. },
  73. async buy() {
  74. const token = wx.getStorageSync('token')
  75. let res = await WXAPI.userAmount(token)
  76. if (res.code != 0) {
  77. wx.showToast({
  78. title: res.msg,
  79. icon: 'none'
  80. })
  81. return
  82. }
  83. if (res.data.balance >= this.data.setting.price) {
  84. // 余额足够
  85. res = await WXAPI.fxBuy(token)
  86. if (res.code != 0) {
  87. wx.showToast({
  88. title: res.msg,
  89. icon: 'none'
  90. })
  91. return
  92. }
  93. wx.showToast({
  94. title: '升级成功',
  95. })
  96. setTimeout(() => {
  97. wx.redirectTo({
  98. url: '/packageFx/pages/index/index',
  99. })
  100. }, 1000);
  101. } else {
  102. let price = this.data.setting.price - res.data.balance
  103. price = price.toFixed(2)
  104. wxpay.wxpay('fxsBuy', price, 0, "/packageFx/pages/index/index");
  105. }
  106. }
  107. })