user.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. wx.removeStorage({
  62. key: 'user'
  63. })
  64. this.setData({
  65. userinfo: {},
  66. usercode: ''
  67. })
  68. // wx.navigateTo({
  69. // url: '../login/user',
  70. // })
  71. },
  72. onCustomerService(){
  73. wx.openCustomerServiceChat({
  74. extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcc1bd2a8bddad1dfb'},
  75. corpId: 'wwc4de479c81db4706',
  76. success(res) {}
  77. })
  78. },
  79. pushToday(e){
  80. $push.pushToday(e.currentTarget.dataset)
  81. },
  82. pushMessage(e){
  83. if($api.checkUser()){
  84. wx.navigateTo({
  85. url: '../message/message',
  86. })
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. this.getUserData()
  99. this.getTodayData()
  100. $api.initUser()
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. }
  127. })