index.vue 5.0 KB

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