personal.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. userInfo: '',
  33. ysf: {
  34. title: '注册页',
  35. config: ''
  36. }
  37. },
  38. goTab(e) {
  39. console.log(e.currentTarget.dataset.index)
  40. if (e.currentTarget.dataset.index == 0 || e.currentTarget.dataset.index == 1) {
  41. if (this.data.loginStatus) {
  42. wx.navigateTo({
  43. url: e.currentTarget.dataset.src
  44. })
  45. } else {
  46. wx.showModal({
  47. title: '您还未登录',
  48. showCancel: false
  49. });
  50. }
  51. }if (e.currentTarget.dataset.index == 4){
  52. wx.navigateTo({
  53. url: '/pages/share/share'
  54. })
  55. }
  56. },
  57. goInfo(){
  58. wx.redirectTo({
  59. url: '/pages/personInfo/personInfo',
  60. })
  61. },
  62. goIndex() {
  63. wx.redirectTo({
  64. url: '/pages/index/index',
  65. })
  66. },
  67. bindGetUserInfo: function (e) {
  68. console.log(e)
  69. this.setData({
  70. nick: e.detail.userInfo.nickName,
  71. avatarUrl: e.detail.userInfo.avatarUrl,
  72. loginStatus: true
  73. })
  74. this.upload(e.detail.userInfo.nickName, e.detail.userInfo.avatarUrl);
  75. },
  76. upload(nickName, avatar) {
  77. const form = {
  78. nickName: nickName,
  79. avatar: avatar
  80. }
  81. wx.request({
  82. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  83. method: "POST",
  84. header: {
  85. 'content-type': 'application/x-www-form-urlencoded',
  86. },
  87. data: form,
  88. success: (res) => {
  89. console.log(res)
  90. if (res.data.code == 0) {
  91. console.log('上传头像昵称成功')
  92. }
  93. }
  94. })
  95. },
  96. getTimes() {
  97. let myHeartTimes = 'tabArr[2].name'
  98. wx.request({
  99. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearts',
  100. method: "get",
  101. success: (res) => {
  102. if (res.data.code == 0) {
  103. this.setData({
  104. [myHeartTimes]: '心动' + res.data.heartCount + '次'
  105. })
  106. }
  107. console.log(this.data.tabArr[2].name)
  108. }
  109. })
  110. let myHeartedTimes = 'tabArr[3].name'
  111. wx.request({
  112. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearted',
  113. method: "get",
  114. success: (res) => {
  115. if (res.data.code == 0) {
  116. this.setData({
  117. [myHeartedTimes]: '被心动' + res.data.heartedCount + '次'
  118. })
  119. console.log(this.data.tabArr[3].name)
  120. }
  121. }
  122. })
  123. },
  124. // getInfos() {
  125. // tool.isLogin().then(res => {
  126. // console.log(res)
  127. // this.setData({
  128. // userInfo: JSON.parse(res.rawData),
  129. // avatarUrl: res.userInfo.avatarUrl,
  130. // nick: res.userInfo.nickName,
  131. // loginStatus: true
  132. // })
  133. // }).catch(err => {
  134. // this.setData({
  135. // loginStatus: false
  136. // })
  137. // })
  138. // },
  139. getInfos2() {
  140. wx.request({
  141. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  142. method: "get",
  143. success: (res) => {
  144. console.log(res,'00000000000000')
  145. if (res.data.code == 0) {
  146. let config='ysf.config';
  147. let sex1 = '';
  148. if(res.data.info.sex==0){
  149. sex1='女'
  150. }else{
  151. sex1='男'
  152. }
  153. this.setData({
  154. myInfo: res.data.info,
  155. [config]:JSON.stringify({
  156. "uid": res.data.id, // 用户唯一标识
  157. "level": 1, // vip等级
  158. "data": JSON.stringify([{
  159. "index": 0,
  160. "key": "name",
  161. "label": "姓名",
  162. "value": res.data.info.name
  163. },
  164. {
  165. "index": 1,
  166. "key": "createTime",
  167. "label": "创建时间",
  168. "value": res.data.info.createTime
  169. },
  170. {
  171. "index": 2,
  172. "key": "sex",
  173. "label": "性别",
  174. "value": sex1
  175. },
  176. {
  177. "index": 3,
  178. "key": "tel",
  179. "label": "电话",
  180. "value": res.data.info.tel
  181. }
  182. ])
  183. })
  184. })
  185. if(res.data.info.avatar&&res.data.info.nickName){
  186. this.setData({
  187. avatarUrl: res.data.info.avatar,
  188. nick: res.data.info.nickName,
  189. loginStatus: true,
  190. })
  191. }else{
  192. this.setData({
  193. loginStatus: false,
  194. })
  195. }}
  196. }
  197. })
  198. },
  199. async onShow() {
  200. tool.openidStatus().then(result => {
  201. this.setData({
  202. openid: result[0],
  203. sessionkey: result[1]
  204. })
  205. // this.getInfos();
  206. this.getInfos2();
  207. this.getTimes();
  208. })
  209. }
  210. })