apply-status.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. const ImageUtil = require('../../utils/image')
  4. const wxpay = require('../../utils/pay.js')
  5. Page({
  6. data: {
  7. wxlogin: true,
  8. applyStatus: -2, // -1 表示未申请,0 审核中 1 不通过 2 通过
  9. applyInfo: {},
  10. canvasHeight: 0,
  11. currentPages: undefined,
  12. },
  13. onLoad: function (options) {
  14. this.setting()
  15. },
  16. onShow() {
  17. const _this = this
  18. AUTH.checkHasLogined().then(isLogined => {
  19. this.setData({
  20. wxlogin: isLogined
  21. })
  22. if (isLogined) {
  23. this.doneShow();
  24. }
  25. })
  26. },
  27. async doneShow() {
  28. const _this = this
  29. const userDetail = await WXAPI.userDetail(wx.getStorageSync('token'))
  30. WXAPI.fxApplyProgress(wx.getStorageSync('token')).then(res => {
  31. let applyStatus = userDetail.data.base.isSeller ? 2 : -1
  32. if (res.code == 2000) {
  33. this.setData({
  34. wxlogin: false
  35. })
  36. return
  37. }
  38. if (res.code === 700) {
  39. _this.setData({
  40. applyStatus: applyStatus
  41. })
  42. }
  43. if (res.code === 0) {
  44. if (userDetail.data.base.isSeller) {
  45. applyStatus = 2
  46. } else {
  47. applyStatus = res.data.status
  48. }
  49. _this.setData({
  50. applyStatus: applyStatus,
  51. applyInfo: res.data
  52. })
  53. }
  54. if (applyStatus == 2) {
  55. _this.fetchQrcode()
  56. }
  57. })
  58. this.setData({
  59. currentPages: getCurrentPages()
  60. })
  61. },
  62. fetchQrcode(){
  63. const _this = this
  64. wx.showLoading({
  65. title: '加载中',
  66. mask: true
  67. })
  68. WXAPI.wxaQrcode({
  69. scene: 'inviter_id=' + wx.getStorageSync('uid'),
  70. page: 'pages/index/index',
  71. is_hyaline: true,
  72. autoColor: true,
  73. expireHours: 1
  74. }).then(res => {
  75. wx.hideLoading()
  76. if (res.code == 0) {
  77. _this.showCanvas(res.data)
  78. }
  79. })
  80. },
  81. showCanvas(qrcode){
  82. const _this = this
  83. let ctx
  84. wx.getImageInfo({
  85. src: qrcode,
  86. success: (res) => {
  87. const imageSize = ImageUtil.imageUtil(res.width, res.height)
  88. const qrcodeWidth = imageSize.windowWidth / 2
  89. _this.setData({
  90. canvasHeight: qrcodeWidth
  91. })
  92. ctx = wx.createCanvasContext('firstCanvas')
  93. ctx.setFillStyle('#fff')
  94. ctx.fillRect(0, 0, imageSize.windowWidth, imageSize.imageHeight + qrcodeWidth)
  95. ctx.drawImage(res.path, (imageSize.windowWidth - qrcodeWidth) / 2, 0, qrcodeWidth, qrcodeWidth)
  96. setTimeout(function () {
  97. wx.hideLoading()
  98. ctx.draw()
  99. }, 1000)
  100. }
  101. })
  102. },
  103. onShareAppMessage() {
  104. return {
  105. title: '"' + wx.getStorageSync('mallName') + '" ' + wx.getStorageSync('share_profile'),
  106. path: '/pages/index/index?inviter_id=' + wx.getStorageSync('uid'),
  107. success: function (res) {
  108. // 转发成功
  109. },
  110. fail: function (res) {
  111. // 转发失败
  112. }
  113. }
  114. },
  115. bindSave: function (e) {
  116. wx.navigateTo({
  117. url: "/pages/fx/apply"
  118. })
  119. },
  120. goShop: function (e) {
  121. wx.switchTab({
  122. url: '/pages/index/index',
  123. })
  124. },
  125. saveToMobile() { //下载二维码到手机
  126. wx.canvasToTempFilePath({
  127. canvasId: 'firstCanvas',
  128. success: function (res) {
  129. let tempFilePath = res.tempFilePath
  130. wx.saveImageToPhotosAlbum({
  131. filePath: tempFilePath,
  132. success: (res) => {
  133. wx.showModal({
  134. content: '二维码已保存到手机相册',
  135. showCancel: false,
  136. confirmText: '知道了',
  137. confirmColor: '#333'
  138. })
  139. },
  140. fail: (res) => {
  141. wx.showToast({
  142. title: res.errMsg,
  143. icon: 'none',
  144. duration: 2000
  145. })
  146. }
  147. })
  148. }
  149. })
  150. },
  151. goIndex() {
  152. wx.switchTab({
  153. url: '/pages/index/index',
  154. });
  155. },
  156. cancelLogin() {
  157. wx.switchTab({
  158. url: '/pages/my/index'
  159. })
  160. },
  161. processLogin(e) {
  162. if (!e.detail.userInfo) {
  163. wx.showToast({
  164. title: '已取消',
  165. icon: 'none',
  166. })
  167. return;
  168. }
  169. AUTH.register(this);
  170. },
  171. async setting() {
  172. const res = await WXAPI.fxSetting()
  173. if (res.code == 0) {
  174. this.setData({
  175. setting: res.data
  176. })
  177. }
  178. },
  179. async buy() {
  180. const token = wx.getStorageSync('token')
  181. let res = await WXAPI.userAmount(token)
  182. if (res.code != 0) {
  183. wx.showToast({
  184. title: res.msg,
  185. icon: 'none'
  186. })
  187. return
  188. }
  189. if (res.data.balance >= this.data.setting.price) {
  190. // 余额足够
  191. res = await WXAPI.fxBuy(token)
  192. if (res.code != 0) {
  193. wx.showToast({
  194. title: res.msg,
  195. icon: 'none'
  196. })
  197. return
  198. }
  199. wx.showToast({
  200. title: '升级成功',
  201. })
  202. setTimeout(() => {
  203. this.doneShow();
  204. }, 1000);
  205. } else {
  206. let price = this.data.setting.price - res.data.balance
  207. price = price.toFixed(2)
  208. wxpay.wxpay('fxsBuy', price, 0, "/pages/fx/apply-status");
  209. }
  210. }
  211. })