me.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <!-- pages/me.wxml -->
  3. <view class="uni-container">
  4. <view class="uni-header-logo">
  5. <img class="uni-header-image" :src="initInfo.headImg == null || initInfo.headImg == '' ? 'http://116.142.80.12:9000/10_03.png' : initInfo.headImg" />
  6. <span>{{initInfo.name == null || initInfo.name == '' ? initInfo.wechatName : initInfo.name}}</span>
  7. <text>{{initInfo.scoreNum}}</text>
  8. </view>
  9. <view class="uni-panel" v-for="(item, index) in list" :key="item.id">
  10. <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="goDetailPage(index, item.id)">
  11. <text class="uni-panel-text">{{item.name}}</text>
  12. <text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import {getScore, getUserInfo} from '@/api/me/me.js'
  19. // pages/me.js
  20. export default {
  21. data() {
  22. return {
  23. initInfo:{
  24. userId: null,
  25. scoreNum: 0,
  26. wechatName: "微信用户",
  27. name: null,
  28. headImg: null,
  29. },
  30. list: [
  31. {
  32. id: 'me/meOperate',//id是文件路径
  33. name: '我的积分流水',
  34. open: false,
  35. pages: ['meOperate']
  36. },
  37. {
  38. id: 'wenba/wenba',
  39. name: '我的问答',
  40. open: false,
  41. pages: ['meOperate']
  42. }
  43. ]
  44. };
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */ onLoad(options) {},
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady() {
  53. this.userId = getApp().globalData.userId
  54. this.getUserInfoByUserId(this.userId)
  55. this.getScoreForMe(this.userId)
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow() {},
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide() {},
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload() {},
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh() {},
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom() {},
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage() {},
  81. methods: {
  82. goDetailPage(panel, e) {
  83. if (typeof e === 'string') {
  84. const url = '/pages/' + e
  85. if (this.hasLeftWin) {
  86. uni.reLaunch({
  87. url: url
  88. })
  89. } else {
  90. uni.navigateTo({
  91. url: url
  92. })
  93. }
  94. } else {
  95. if (this.hasLeftWin) {
  96. uni.reLaunch({
  97. url: e.url
  98. })
  99. } else {
  100. uni.navigateTo({
  101. url: e.url
  102. })
  103. }
  104. }
  105. },
  106. //获取用户信息:用户名称:头像
  107. getUserInfoByUserId(userId){
  108. getUserInfo(userId).then(res =>{
  109. this.initInfo.wechatName = res.data.wechatName;
  110. this.initInfo.name = res.data.name;
  111. this.initInfo.wechatName = res.data.wechatName;
  112. })
  113. },
  114. //获取当前积分
  115. getScoreForMe(userId){
  116. getScore(this.userId).then(res =>{
  117. this.initInfo.socreNum = res.data.scoreNum
  118. })
  119. }
  120. }
  121. };
  122. </script>
  123. <style>
  124. @import './me.css';
  125. </style>