index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. const memberList = ref([])
  49. // 权益列表
  50. const menuList = ref([])
  51. watch(() => userInfo.value?.entitlement,
  52. (newVal) => {
  53. // if (newVal) getPName()
  54. if (newVal && listKeys?.length) {
  55. listKeys.forEach(key => {
  56. const item = list.find(e => e.key === key)
  57. if (!item || item.show) return
  58. //
  59. if (key === 'resumeRefreshCount') { // 简历刷新次数
  60. item.rightTex = '剩余 ' + (newVal[key] ? newVal[key] : 0) + ' 次'
  61. }
  62. else if (newVal[key]) item.show = true
  63. })
  64. menuList.value = list.filter(e => e.show)
  65. }
  66. },
  67. {
  68. // deep: true,
  69. immediate: true
  70. }
  71. )
  72. const remaining = computed(() => {
  73. if (!userInfo.value?.vipExpireDate) return ' 0 天'
  74. const diffInMs = (userInfo.value?.vipExpireDate-0) - new Date().getTime()
  75. const day = diffInMs / (1000 * 60 * 60 * 24)
  76. return day < 1 ? '今天' : Math.floor(day) + '天'
  77. })
  78. // 列表跳转
  79. const handleToLink = (item) => {
  80. uni.navigateTo({
  81. url: item.path
  82. })
  83. }
  84. const pName = ref('')
  85. let getPNameNum = 0
  86. const getPName = () => {
  87. if (!userInfo.value?.vipFlag) {
  88. getPNameNum++
  89. if (getPNameNum > 6)
  90. setTimeout(() => { getPName() }, 1000);
  91. return
  92. }
  93. memberList.value.forEach(e => {
  94. if (e.id && e.id.toString() === userInfo.value?.vipFlag?.toString()) pName.value = e.name
  95. })
  96. }
  97. const getMemberList = async () => {
  98. try {
  99. const { data } = await getMembershipPackageList()
  100. if (!data || data.length === 0) {
  101. return
  102. }
  103. memberList.value = data
  104. // let vipFlagIndex = null
  105. // const list = data.map((item, index) => {
  106. // item.id = item.id?.toString()
  107. // if (item.id === userInfo.value?.vipFlag) vipFlagIndex = index // 低于当前套餐的(套餐)不展示
  108. // if (item.recommend) recommend.value = index // 推荐套餐
  109. // return {
  110. // ...item,
  111. // my: vipFlagIndex === index,
  112. // list: JSON.parse(item.text),
  113. // type: 3, // 订单类型 0平台订单|1求职端订单|2招聘端订单|3会员套餐
  114. // loading: false
  115. // }
  116. // })
  117. // // 低于当前套餐的(套餐)不展示
  118. // memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
  119. getPName()
  120. } catch (error) {
  121. uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
  122. }
  123. }
  124. getMemberList()
  125. </script>
  126. <style lang="scss" scoped>
  127. .vipBox {
  128. // color: #a18a0f;
  129. padding: 80rpx 50rpx;
  130. display: flex;
  131. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  132. .avatar{
  133. position: relative;
  134. width: 100rpx;
  135. height: 100rpx;
  136. margin: 0;
  137. .img-box {
  138. width: 100%;
  139. height: 100%;
  140. border: 2rpx solid #ccc;
  141. border-radius: 50%;
  142. border: 1px solid gold;
  143. }
  144. .vipIcon {
  145. position: absolute;
  146. width: 50%;
  147. height: 50%;
  148. bottom: 0;
  149. right: 0;
  150. transform: translate(0, 30%);
  151. }
  152. }
  153. .nameBox {
  154. display: flex;
  155. flex-direction: column;
  156. justify-content: space-around;
  157. margin-left: 30rpx;
  158. .name {
  159. color: #724d2b;
  160. }
  161. .vipInfo {
  162. color: #572a00;
  163. }
  164. }
  165. }
  166. :deep(.uni-list-item) {
  167. height: 120rpx !important;
  168. line-height: 120rpx !important;
  169. }
  170. :deep(.uni-list-item__content-title) {
  171. font-size: 32rpx !important;
  172. font-weight: 500;
  173. }
  174. </style>