index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const app = getApp()
  2. const WXAPI = require('apifm-wxapi')
  3. const AUTH = require('../../utils/auth')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. balance: 0.00,
  10. freeze: 0,
  11. score: 0,
  12. score_sign_continuous: 0,
  13. cashlogs: undefined
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function () {
  29. AUTH.checkHasLogined().then(isLogined => {
  30. if (isLogined) {
  31. this.doneShow();
  32. } else {
  33. wx.showModal({
  34. title: '提示',
  35. content: '本次操作需要您的登录授权',
  36. cancelText: '暂不登录',
  37. confirmText: '前往登录',
  38. success(res) {
  39. if (res.confirm) {
  40. wx.switchTab({
  41. url: "/pages/my/index"
  42. })
  43. } else {
  44. wx.navigateBack()
  45. }
  46. }
  47. })
  48. }
  49. })
  50. },
  51. doneShow: function () {
  52. const _this = this
  53. const token = wx.getStorageSync('token')
  54. WXAPI.userAmount(token).then(function (res) {
  55. if (res.code == 0) {
  56. _this.setData({
  57. balance: res.data.balance.toFixed(2),
  58. freeze: res.data.freeze.toFixed(2),
  59. totleConsumed: res.data.totleConsumed.toFixed(2),
  60. score: res.data.score
  61. });
  62. } else {
  63. wx.showToast({
  64. title: res.msg,
  65. icon: 'none'
  66. })
  67. }
  68. })
  69. // 读取积分明细
  70. WXAPI.scoreLogs({
  71. token: token,
  72. page:1,
  73. pageSize:50
  74. }).then(res => {
  75. if (res.code == 0) {
  76. _this.setData({
  77. cashlogs: res.data.result
  78. })
  79. }
  80. })
  81. },
  82. recharge: function (e) {
  83. wx.navigateTo({
  84. url: "/pages/recharge/index"
  85. })
  86. },
  87. withdraw: function (e) {
  88. wx.navigateTo({
  89. url: "/pages/withdraw/index"
  90. })
  91. }
  92. })