growth.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const app = getApp()
  2. const WXAPI = require('apifm-wxapi')
  3. const AUTH = require('../../utils/auth')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. wxlogin: true,
  10. score: 0,
  11. uid: undefined
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. },
  18. /**
  19. * 生命周期函数--监听页面初次渲染完成
  20. */
  21. onReady: function () {
  22. },
  23. /**
  24. * 生命周期函数--监听页面显示
  25. */
  26. onShow: function () {
  27. AUTH.checkHasLogined().then(isLogined => {
  28. this.setData({
  29. wxlogin: isLogined
  30. })
  31. if (isLogined) {
  32. this.initData()
  33. }
  34. })
  35. },
  36. async initData(){
  37. const token = wx.getStorageSync('token')
  38. const res1 = await WXAPI.userAmount(token)
  39. if (res1.code == 0) {
  40. this.data.score = res1.data.score
  41. }
  42. const res2 = await WXAPI.scoreDeductionRules(1);
  43. if (res2.code == 0) {
  44. this.data.deductionRules = res2.data
  45. }
  46. this.setData({
  47. score: this.data.score,
  48. deductionRules: this.data.deductionRules,
  49. })
  50. },
  51. async bindSave(e) {
  52. const score = e.detail.value.score;
  53. if (!score) {
  54. wx.showToast({
  55. title: '请输入积分数量',
  56. icon: 'none'
  57. })
  58. return
  59. }
  60. const res = await WXAPI.exchangeScoreToGrowth(wx.getStorageSync('token'), score)
  61. if (res.code == 0) {
  62. wx.showModal({
  63. title: '成功',
  64. content: '恭喜您,成功兑换'+ res.data +'成长值',
  65. showCancel: false
  66. })
  67. } else {
  68. wx.showToast({
  69. title: res.msg,
  70. icon: 'none'
  71. })
  72. }
  73. },
  74. cancelLogin() {
  75. this.setData({
  76. wxlogin: true
  77. })
  78. },
  79. })