user.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/user/user.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. const $api = require('../../utils/api.js').API;
  5. const $push = require('../../utils/api.js').PUSH;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. userinfo:{},
  12. todayinfo:{},
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.getUserData()
  19. },
  20. zx(){
  21. wx.navigateTo({
  22. url: '../message/message',
  23. })
  24. },
  25. getUserData() {
  26. $api.getAuthinfo().then(res=>{
  27. if(res.data.code == 0){
  28. this.setData({
  29. userinfo: res.data.data,
  30. })
  31. wx.setStorage({
  32. key: 'user',
  33. data: res.data.data,
  34. })
  35. }
  36. })
  37. .catch(err=>{
  38. this.setData({
  39. userinfo: {}
  40. })
  41. })
  42. },
  43. getTodayData() {
  44. $api.getMineLatest().then(res=>{
  45. this.setData({
  46. todayinfo: res.data.data,
  47. todayMoney:((res.data.data.today_fund - res.data.data.yesterday_fund)*10000).toFixed(2)
  48. })
  49. })
  50. .catch(err=>{
  51. this.setData({
  52. todayinfo: {},
  53. status:0
  54. })
  55. })
  56. },
  57. logout() {
  58. wx.removeStorage({
  59. key: 'userInfo'
  60. })
  61. this.setData({
  62. userinfo: {},
  63. usercode: ''
  64. })
  65. wx.navigateTo({
  66. url: '../login/user',
  67. })
  68. },
  69. onCustomerService(){
  70. wx.openCustomerServiceChat({
  71. extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},
  72. corpId: 'wwc4de479c81db4706',
  73. success(res) {}
  74. })
  75. },
  76. pushToday(e){
  77. $push.pushToday(e.currentTarget.dataset)
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function () {
  88. this.getUserData()
  89. this.getTodayData()
  90. $api.initUser()
  91. },
  92. /**
  93. * 生命周期函数--监听页面隐藏
  94. */
  95. onHide: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面卸载
  99. */
  100. onUnload: function () {
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh: function () {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. }
  117. })