personal.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. const app = require('../../utils/util.js');
  2. const tool = require('../../utils/tool.js');
  3. Page({
  4. data: {
  5. avatarUrl: '../../images/morenImg.png',
  6. tabArr: [{
  7. name: '我的信息',
  8. img: '../../images/icon1.jpg',
  9. url: '/pages/InfoType/InfoType'
  10. }, {
  11. name: '我的活动',
  12. img: '../../images/icon6.jpg',
  13. url: '/pages/myActive/myActive'
  14. }, {
  15. name: '心动0次',
  16. img: '../../images/icon3.jpg'
  17. }, {
  18. name: '被心动0次',
  19. img: '../../images/icon7.jpg',
  20. url: ''
  21. },
  22. {
  23. name: '推荐好友',
  24. img: '../../images/icon5.jpg',
  25. url: '/pages/share/share'
  26. }
  27. ]
  28. },
  29. goTab(e) {
  30. console.log(e.currentTarget.dataset.index)
  31. if (e.currentTarget.dataset.index == 0 || e.currentTarget.dataset.index == 1) {
  32. if (this.data.loginStatus) {
  33. wx.navigateTo({
  34. url: e.currentTarget.dataset.src
  35. })
  36. } else {
  37. wx.showModal({
  38. title: '您还未登录',
  39. showCancel: false
  40. });
  41. }
  42. }if (e.currentTarget.dataset.index == 4){
  43. wx.navigateTo({
  44. url: '/pages/share/share'
  45. })
  46. }
  47. },
  48. goIndex() {
  49. wx.redirectTo({
  50. url: '/pages/index/index',
  51. })
  52. },
  53. bindGetUserInfo: function (e) {
  54. console.log(e.detail.userInfo)
  55. this.setData({
  56. nick: e.detail.userInfo.nickName,
  57. avatarUrl: e.detail.userInfo.avatarUrl,
  58. loginStatus: true
  59. })
  60. this.upload(e.detail.userInfo.nickName, e.detail.userInfo.avatarUrl);
  61. },
  62. upload(nickName, avatar) {
  63. const form = {
  64. nickName: nickName,
  65. avatar: avatar
  66. }
  67. wx.request({
  68. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  69. method: "POST",
  70. header: {
  71. 'content-type': 'application/x-www-form-urlencoded',
  72. },
  73. data: form,
  74. success: (res) => {
  75. console.log(res)
  76. if (res.data.code == 0) {
  77. console.log('上传头像昵称成功')
  78. }
  79. }
  80. })
  81. },
  82. getTimes() {
  83. let myHeartTimes = 'tabArr[2].name'
  84. wx.request({
  85. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearts',
  86. method: "get",
  87. success: (res) => {
  88. if (res.data.code == 0) {
  89. this.setData({
  90. [myHeartTimes]: '心动' + res.data.heartCount + '次'
  91. })
  92. }
  93. console.log(this.data.tabArr[2].name)
  94. }
  95. })
  96. let myHeartedTimes = 'tabArr[3].name'
  97. wx.request({
  98. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearted',
  99. method: "get",
  100. success: (res) => {
  101. if (res.data.code == 0) {
  102. this.setData({
  103. [myHeartedTimes]: '被心动' + res.data.heartedCount + '次'
  104. })
  105. console.log(this.data.tabArr[3].name)
  106. }
  107. }
  108. })
  109. },
  110. getInfos() {
  111. tool.isLogin().then(res => {
  112. this.setData({
  113. avatarUrl: res.userInfo.avatarUrl,
  114. nick: res.userInfo.nickName,
  115. loginStatus: true
  116. })
  117. }).catch(err => {
  118. this.setData({
  119. loginStatus: false
  120. })
  121. })
  122. },
  123. async onShow() {
  124. tool.openidStatus().then(result => {
  125. this.setData({
  126. openid: result[0],
  127. sessionkey: result[1]
  128. })
  129. this.getInfos();
  130. this.getTimes();
  131. })
  132. }
  133. })