purse.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // pages/user/purse.js
  2. const api = require('../../utils/api.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. userInfo: {},
  11. sharePath: 'pages/share/share',
  12. shareInfo: {}
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. let timer = setInterval(() => {
  19. if (app.globalData.PageCallback) {
  20. api.getUserInfo().then(res => {
  21. this.setData({
  22. userInfo: res.data
  23. })
  24. }, err => {
  25. console.log(err)
  26. })
  27. this.getIncomeList()
  28. this.getShareInfo()
  29. clearInterval(timer)
  30. }
  31. }, 200)
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload: function () {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh: function () {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. },
  63. routeUser: function (e) {
  64. app.globalData.openGZH = true
  65. wx.switchTab({
  66. url: '/pages/user/index?open=1',
  67. })
  68. },
  69. routeTo: function (e) {
  70. util.routeTo(e.currentTarget.dataset.to)
  71. },
  72. getShareInfo: function () {
  73. api.getShareInfo({
  74. data: {
  75. path: this.data.sharePath
  76. }
  77. }).then(res => {
  78. this.setData({
  79. shareInfo: res.data
  80. })
  81. }).catch(err => {
  82. console.log('getShare', err)
  83. })
  84. },
  85. // 获取今日收益列表
  86. getIncomeList: function () {
  87. const d = new Date()
  88. let today = d.getFullYear() + "-"
  89. today += ((d.getMonth() + 1) < 10 ? '0' : '') + (d.getMonth() + 1) + '-'
  90. today += ((d.getDate() + 1) < 10 ? '0' : '') + d.getDate()
  91. api.getIncomeList({
  92. start_time: today,
  93. end_time: today,
  94. page: 1,
  95. offset: 1000
  96. }).then(res => {
  97. let sum = 0
  98. res.data.list.forEach((item, ids) => {
  99. item.amount = (item.amount).toFixed(2)
  100. item.create_time = util.formatTime(item.create_time, 'yyyy/MM/dd')
  101. sum += +item.amount
  102. })
  103. this.setData({
  104. // sum: (res.data.sum ? res.data.sum.sum_agent_gain : 0).toFixed(2)
  105. sum: sum.toFixed(2)
  106. })
  107. })
  108. }
  109. })