growth.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. processLogin(e) {
  80. if (!e.detail.userInfo) {
  81. wx.showToast({
  82. title: '已取消',
  83. icon: 'none',
  84. })
  85. return;
  86. }
  87. AUTH.register(this);
  88. },
  89. })