tips.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // pages/tips/tips.js
  2. const api = require('../../utils/api.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp()
  5. Page({
  6. data: {
  7. TabIndex: 0,
  8. dayIncomeList: [],
  9. dayIncomeCount: 99,
  10. sum: 0,
  11. userInfo: {},
  12. tipsText: [],
  13. sharePath: 'pages/share/share',
  14. shareInfo: {},
  15. mpType: app.globalData.mpType
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. let timer = setInterval(() => {
  22. if (app.globalData.PageCallback) {
  23. this.getIncomeList()
  24. this.gethelptipsTextFun()
  25. this.getShareInfo()
  26. clearInterval(timer)
  27. }
  28. }, 200)
  29. },
  30. getShareInfo: function () {
  31. api.getShareInfo({
  32. data: {
  33. path: this.data.sharePath
  34. }
  35. }).then(res => {
  36. this.setData({
  37. shareInfo: res.data
  38. })
  39. }).catch(err => {
  40. console.log('getShare', err)
  41. })
  42. },
  43. // 获取今日收益列表
  44. getIncomeList: function () {
  45. const d = new Date()
  46. let today = d.getFullYear() + "-"
  47. today += ((d.getMonth() + 1) < 10 ? '0' : '') + (d.getMonth() + 1) + '-'
  48. today += ((d.getDate() + 1) < 10 ? '0' : '') + d.getDate()
  49. api.getIncomeList({ page: 1, offset: 1000 }).then(res => {
  50. res.data.list.forEach((item, ids) => {
  51. if (this.data.mpType === 'rp') {
  52. item.amount = item.amount
  53. }
  54. item.create_time = util.formatTime(item.create_time, 'yyyy/MM/dd')
  55. })
  56. this.setData({
  57. dayIncomeList: res.data.list,
  58. dayIncomeCount: res.data.count,
  59. userInfo: app.globalData.userInfo,
  60. sum: this.data.mpType === 'gd' ? (res.data.sum ? res.data.sum.my_integral : 0) : (res.data.sum ? res.data.sum.sum_agent_gain : 0).toFixed(2)
  61. })
  62. })
  63. },
  64. // 赚钱小技巧文字
  65. gethelptipsTextFun: function () {
  66. api.gethelpTipsText().then(res => {
  67. if (res.code === 200) {
  68. this.setData({
  69. tipsText: res.data.text.split('\n')
  70. })
  71. }
  72. })
  73. },
  74. routeTo: function (e) {
  75. util.routeTo(e.currentTarget.dataset.to)
  76. },
  77. toRank: function (e) {
  78. util.routeTo('/pages/user/rank')
  79. },
  80. routeUser: function (e) {
  81. if (this.data.mpType === 'rp') {
  82. app.globalData.openGZH = true
  83. wx.switchTab({
  84. url: '/pages/user/index?open=1',
  85. })
  86. } else if (this.data.mpType === 'gd') {
  87. // app.globalData.openGZH = true
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. }
  92. },
  93. routeBox: function (e) {
  94. wx.switchTab({
  95. url: '/pages/box/box',
  96. })
  97. },
  98. routeTask: function (e) {
  99. util.routeTo('/pages/user/task')
  100. },
  101. ChangeTab: function (e) {
  102. this.setData({
  103. TabIndex: e.target.dataset.index
  104. })
  105. },
  106. onShow: function () {
  107. wx.showShareMenu({ // 允许转发时携带 shareTicket。
  108. withShareTicket: true
  109. })
  110. }
  111. })