index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!-- vip权益 -->
  2. <template>
  3. <view class="box">
  4. <!-- vip信息 -->
  5. <view class="vipBox">
  6. <view class="avatar">
  7. <img :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" alt="" class="img-box">
  8. <image src="/static/svg/vip.svg" class="vipIcon"></image>
  9. </view>
  10. <view class="nameBox">
  11. <view class="name font-weight-bold font-size-16">{{ baseInfo?.name || userInfo?.phone }}</view>
  12. <view class="vipInfo font-size-14">
  13. {{ pName }}将于{{ remaining }}后过期
  14. </view>
  15. </view>
  16. </view>
  17. <view style="height: 20rpx; background-color: #f8f8fa;"></view>
  18. <view class="card">
  19. <uni-list>
  20. <uni-list-item
  21. v-for="item in menuList"
  22. :clickable="true"
  23. :key="item.title"
  24. :title="item.title"
  25. showArrow
  26. :rightText="item.rightTex || ''"
  27. @click="handleToLink(item)"
  28. >
  29. </uni-list-item>
  30. </uni-list>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup>
  35. import { userStore } from '@/store/user'
  36. import { ref, computed, watch } from 'vue'
  37. import { getUserAvatar } from '@/utils/avatar'
  38. import { getMembershipPackageList } from '@/api/vip'
  39. const useUserStore = userStore()
  40. const baseInfo = computed(() => useUserStore?.baseInfo)
  41. const userInfo = computed(() => useUserStore?.userInfo)
  42. let list = [
  43. { title: '简历刷新次数', key: 'resumeRefreshCount', show: true, path: '/pagesA/vip/template/index' },
  44. { title: '简历模板', key: 'resumeTemplate', show: false, path: '/pagesA/vip/template/index' },
  45. { title: '屏蔽企业', key: 'viewersList', show: true, path: '/pagesA/vip/blockEnt/index' },
  46. ]
  47. const listKeys = list.map(e => e.key)
  48. // 权益列表
  49. const menuList = ref([])
  50. watch(() => userInfo.value?.entitlement,
  51. (newVal) => {
  52. // if (newVal) getPName()
  53. if (newVal && listKeys?.length) {
  54. listKeys.forEach(key => {
  55. const item = list.find(e => e.key === key)
  56. if (!item || item.show) return
  57. //
  58. if (key === 'resumeRefreshCount') { // 简历刷新次数
  59. item.rightTex = '剩余 ' + (newVal[key] ? newVal[key] : 0) + ' 次'
  60. }
  61. else if (newVal[key]) item.show = true
  62. })
  63. menuList.value = list.filter(e => e.show)
  64. }
  65. },
  66. {
  67. // deep: true,
  68. immediate: true
  69. }
  70. )
  71. const remaining = computed(() => {
  72. if (!userInfo.value?.vipExpireDate) return '0'
  73. const diffInMs = (userInfo.value?.vipExpireDate-0) - new Date().getTime()
  74. const day = diffInMs / (1000 * 60 * 60 * 24)
  75. return day < 1 ? '今天' : Math.floor(day) + '天'
  76. })
  77. // 列表跳转
  78. const handleToLink = (item) => {
  79. uni.navigateTo({
  80. url: item.path
  81. })
  82. }
  83. const pName = ref('')
  84. let getPNameNum = 0
  85. const getPName = () => {
  86. if (!useUserStore.userInfo?.vipFlag) {
  87. getPNameNum++
  88. if (getPNameNum > 6)
  89. setTimeout(() => { getPName() }, 1000);
  90. return
  91. }
  92. memberList.value.forEach(e => {
  93. if (e.id && e.id.toString() === useUserStore.userInfo?.vipFlag?.toString()) pName.value = e.name
  94. })
  95. }
  96. const memberList = ref([])
  97. const getMemberList = async () => {
  98. try {
  99. const res = await getMembershipPackageList()
  100. if (!res?.data?.length) return uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
  101. memberList.value = res.data
  102. getPName()
  103. } catch (error) {
  104. uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
  105. }
  106. }
  107. getMemberList()
  108. </script>
  109. <style lang="scss" scoped>
  110. .vipBox {
  111. // color: #a18a0f;
  112. padding: 80rpx 50rpx;
  113. display: flex;
  114. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  115. .avatar{
  116. position: relative;
  117. width: 100rpx;
  118. height: 100rpx;
  119. margin: 0;
  120. .img-box {
  121. width: 100%;
  122. height: 100%;
  123. border: 2rpx solid #ccc;
  124. border-radius: 50%;
  125. border: 1px solid gold;
  126. }
  127. .vipIcon {
  128. position: absolute;
  129. width: 50%;
  130. height: 50%;
  131. bottom: 0;
  132. right: 0;
  133. transform: translate(0, 30%);
  134. }
  135. }
  136. .nameBox {
  137. display: flex;
  138. flex-direction: column;
  139. justify-content: space-around;
  140. margin-left: 30rpx;
  141. .name {
  142. color: #724d2b;
  143. }
  144. .vipInfo {
  145. color: #572a00;
  146. }
  147. }
  148. }
  149. :deep(.uni-list-item) {
  150. height: 120rpx !important;
  151. line-height: 120rpx !important;
  152. }
  153. :deep(.uni-list-item__content-title) {
  154. font-size: 32rpx !important;
  155. font-weight: 500;
  156. }
  157. </style>