personal.js 3.4 KB

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