personal.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.png',
  9. url: '/pages/InfoType/InfoType'
  10. }, {
  11. name: '我的活动',
  12. img: '../../images/icon2.png',
  13. url: '/pages/myActive/myActive'
  14. }, {
  15. name: '心动0次',
  16. img: '../../images/icon3.png',
  17. url: ''
  18. }, {
  19. name: '被心动0次',
  20. img: '../../images/icon4.png',
  21. url: ''
  22. },
  23. // {
  24. // name: '增加权益',
  25. // img: '../../images/icon7.png',
  26. // url: '/pages/addRights/addRights'
  27. // },
  28. {
  29. name: '推荐好友',
  30. img: '../../images/icon6.png',
  31. url: '/pages/share/share'
  32. },
  33. // {
  34. // name: '我的订单',
  35. // img: '../../images/icon8.png',
  36. // url: '/pages/paylists/paylists'
  37. // }
  38. ]
  39. },
  40. goTab(e) {
  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. success(res) {
  50. if (res.confirm) {
  51. wx.redirectTo({
  52. url: '/pages/personal/personal',
  53. })
  54. }
  55. }
  56. });
  57. }
  58. },
  59. goIndex() {
  60. wx.redirectTo({
  61. url: '/pages/index/index',
  62. })
  63. },
  64. // onShareAppMessage: function (options) {
  65. // console.log(options)
  66. // var that = this;
  67. // // 设置菜单中的转发按钮触发转发事件时的转发内容
  68. // var shareObj = {
  69. // title: "月合文化", // 默认是小程序的名称(可以写slogan等)
  70. // path: '/pages/personal/personal', // 默认是当前页面,必须是以‘/’开头的完整路径
  71. // imageUrl: '../../images/photo.jpg', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  72. // success: function (res) {
  73. // console.log(res)
  74. // // 转发成功之后的回调
  75. // if (res.errMsg == 'shareAppMessage:ok') {}
  76. // },
  77. // fail: function () {
  78. // // 转发失败之后的回调
  79. // if (res.errMsg == 'shareAppMessage:fail cancel') {
  80. // // 用户取消转发
  81. // } else if (res.errMsg == 'shareAppMessage:fail') {
  82. // // 转发失败,其中 detail message 为详细失败信息
  83. // }
  84. // }
  85. // }
  86. // // 来自页面内的按钮的转发
  87. // if (options.from == 'button') {
  88. // var eData = options.target.dataset;
  89. // console.log(eData.name); // shareBtn
  90. // // 此处可以修改 shareObj 中的内容
  91. // shareObj.path = '/pages/btnname/btnname?btn_name=' + eData.name;
  92. // }
  93. // // 返回shareObj
  94. // return shareObj;
  95. // },
  96. bindGetUserInfo: function (e) {
  97. console.log(e.detail.userInfo)
  98. this.setData({
  99. nick: e.detail.userInfo.nickName,
  100. avatarUrl: e.detail.userInfo.avatarUrl,
  101. loginStatus:true
  102. })
  103. this.upload(e.detail.userInfo.nickName, e.detail.userInfo.avatarUrl);
  104. },
  105. upload(nickName, avatar) {
  106. const form = {
  107. nickName: nickName,
  108. avatar: avatar
  109. }
  110. wx.request({
  111. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  112. method: "POST",
  113. header: {
  114. 'content-type': 'application/x-www-form-urlencoded',
  115. },
  116. data: form,
  117. success: (res) => {
  118. console.log(res)
  119. if (res.data.code == 0) {
  120. console.log('上传头像昵称成功')
  121. }
  122. }
  123. })
  124. },
  125. getTimes() {
  126. let myHeartTimes = 'tabArr[2].name'
  127. wx.request({
  128. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearts',
  129. method: "get",
  130. success: (res) => {
  131. if (res.data.code == 0) {
  132. this.setData({
  133. [myHeartTimes]: '心动' + res.data.heartCount + '次'
  134. })
  135. }
  136. console.log(this.data.tabArr[2].name)
  137. }
  138. })
  139. let myHeartedTimes = 'tabArr[3].name'
  140. wx.request({
  141. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/0/myHearted',
  142. method: "get",
  143. success: (res) => {
  144. if (res.data.code == 0) {
  145. this.setData({
  146. [myHeartedTimes]: '被心动' + res.data.heartedCount + '次'
  147. })
  148. console.log(this.data.tabArr[3].name)
  149. }
  150. }
  151. })
  152. },
  153. getPhoneNumber(e) {
  154. console.log(e)
  155. console.log(e.detail.errMsg == "getPhoneNumber:ok");
  156. if (e.detail.errMsg == "getPhoneNumber:ok") {
  157. wx.request({
  158. url: app.globalData.publicUrl + '/wx/user/wxbfa171fdd4000e03/phone',
  159. // data: {
  160. // encryptedData: e.detail.encryptedData,
  161. // iv: e.detail.iv,
  162. // sessionKey: that.data.session_key,
  163. // uid: "",
  164. // },
  165. data: {
  166. appid: 'wxbfa171fdd4000e03',
  167. sessionKey: this.data.sessionKey,
  168. signature,
  169. rawData,
  170. encryptedData: e.detail.encryptedData,
  171. iv: e.detail.iv
  172. },
  173. method: "get",
  174. success: function (res) {
  175. console.log(res);
  176. }
  177. })
  178. }
  179. // console.log(e.detail.iv)
  180. // console.log(e.detail.encryptedData)
  181. },
  182. getInfos() {
  183. tool.isLogin().then(res => {
  184. this.setData({
  185. avatarUrl: res.userInfo.avatarUrl,
  186. nick: res.userInfo.nickName,
  187. loginStatus: true
  188. })
  189. wx.hideLoading();
  190. }).catch(err => {
  191. this.setData({
  192. loginStatus: false
  193. })
  194. wx.hideLoading();
  195. })
  196. },
  197. async onShow() {
  198. wx.showLoading();
  199. tool.openidStatus().then(result => {
  200. this.setData({
  201. openid: result[0],
  202. sessionkey: result[1]
  203. })
  204. this.getInfos();
  205. this.getTimes();
  206. })
  207. },
  208. /**
  209. * 生命周期函数--监听页面初次渲染完成
  210. */
  211. onReady: function () {
  212. },
  213. onHide: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面卸载
  217. */
  218. onUnload: function () {
  219. },
  220. /**
  221. * 页面相关事件处理函数--监听用户下拉动作
  222. */
  223. onPullDownRefresh: function () {
  224. },
  225. /**
  226. * 页面上拉触底事件的处理函数
  227. */
  228. onReachBottom: function () {
  229. },
  230. onShareTimeline: function () {
  231. return {
  232. title: '测试',
  233. query: {
  234. id: 0
  235. },
  236. imageUrl: '../../images/icon1.png'
  237. }
  238. },
  239. })