index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view>
  3. <view class="vipBox">
  4. <view class="avatar">
  5. <img :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" alt="" class="img-box">
  6. <image src="/static/svg/vip.svg" class="vipIcon"></image>
  7. </view>
  8. <view class="nameBox">
  9. <view class="name font-weight-bold font-size-16">{{ baseInfo?.name || userInfo?.phone }}</view>
  10. <view class="vipInfo font-size-14" v-if="remaining">
  11. {{ pName }}
  12. <view>将于{{ remaining }}后过期</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view>
  17. <swiper class="swiper-box" :current="current">
  18. <swiper-item v-for="(item, index) in memberListLength" :key="index" class="swiper-items">
  19. <view class="swiper-item" v-for="val in item" :key="val.id">
  20. <view
  21. class="card"
  22. :class="{ recommend: val.recommend, vipFlag: val.my, active: val.id === chooseId}"
  23. @tap="handleChoose(val.id)"
  24. >
  25. <text>{{ val.name }}</text>
  26. <view>
  27. <uni-icons color="#f30" type="icon-renminbi1688" size="16" custom-prefix="iconfont"></uni-icons>
  28. <text>{{ val.price }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </swiper-item>
  33. </swiper>
  34. <view v-if="typeof chooseId === 'number'" class="itemBox">
  35. 套餐权益 ( {{ list.name }} )
  36. <uni-section
  37. v-for="item in list.list"
  38. :key="item.id"
  39. class="item"
  40. :class="{ active: item.active }"
  41. titleColor="#774e20"
  42. subTitleColor="#774e20"
  43. :title="item.text"
  44. >
  45. <template v-slot:right>
  46. <uni-icons color="#774e20" :type="item.active ? 'checkmarkempty' : 'closeempty'" size="20"/>
  47. </template>
  48. </uni-section>
  49. </view>
  50. </view>
  51. <view class="pay">
  52. <view class="pay-box">
  53. <view class="price">
  54. <uni-icons color="#e68735" type="icon-renminbi1688" size="16" custom-prefix="iconfont"></uni-icons>
  55. {{ list.price }}
  56. </view>
  57. <view class="btn">
  58. 立刻升级
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script setup>
  65. import { ref, computed, watch } from 'vue'
  66. import { getUserAvatar } from '@/utils/avatar'
  67. import { userStore } from '@/store/user'
  68. import { getMembershipPackageList } from '@/api/vip'
  69. const useUserStore = userStore()
  70. const baseInfo = computed(() => useUserStore?.baseInfo)
  71. const userInfo = computed(() => useUserStore?.userInfo)
  72. const memberList = ref([])
  73. const recommend = ref(null)
  74. const chooseId = ref(null)
  75. const memberListLength = computed(() => {
  76. const result = [];
  77. for (let i = 0; i < memberList.value.length; i += 2) {
  78. const pair = memberList.value.slice(i, i + 2)
  79. result.push(pair)
  80. }
  81. return result
  82. })
  83. const pName = computed(() => {
  84. return memberList.value.find(item => +item.id === +userInfo.value?.vipFlag)?.name
  85. })
  86. const remaining = computed(() => {
  87. if (!userInfo.value?.vipExpireDate) return null
  88. const diffInMs = userInfo.value?.vipExpireDate - new Date().getTime()
  89. const day = diffInMs / (1000 * 60 * 60 * 24)
  90. return day < 1 ? '今天' : Math.floor(day) + '天'
  91. })
  92. const list = computed(() => {
  93. const item = memberList.value.find(item => item.id === chooseId.value)
  94. return item ?? {}
  95. })
  96. const current = ref(0)
  97. const handleChoose = (id) => {
  98. chooseId.value = id
  99. }
  100. const getMemberList = async () => {
  101. try {
  102. const { data } = await getMembershipPackageList()
  103. if (!data || data.length === 0) {
  104. return
  105. }
  106. // memberList.value = data
  107. let vipFlagIndex = null
  108. const list = data.map((item, index) => {
  109. if (+item.id === +userInfo.value?.vipFlag) {
  110. vipFlagIndex = index // 低于当前套餐的(套餐)不展示
  111. }
  112. if (item.recommend) {
  113. recommend.value = index // 推荐套餐
  114. }
  115. return {
  116. ...item,
  117. my: vipFlagIndex === index,
  118. list: JSON.parse(item.text),
  119. type: 3, // 订单类型 0平台订单|1求职端订单|2招聘端订单|3会员套餐
  120. loading: false
  121. }
  122. })
  123. // 低于当前套餐的(套餐)不展示
  124. memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
  125. if ((!userInfo.value?.vipFlag || userInfo.value?.vipExpireDate - new Date().getTime() > 0 ) && typeof recommend.value === 'number') {
  126. current.value = parseInt(recommend.value / 2)
  127. chooseId.value = memberList.value[recommend.value]?.id
  128. }
  129. } catch (error) {
  130. uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
  131. }
  132. }
  133. getMemberList()
  134. </script>
  135. <style lang="scss" scoped>
  136. .vipBox {
  137. // color: #a18a0f;
  138. padding: 80rpx 50rpx;
  139. display: flex;
  140. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  141. .avatar{
  142. position: relative;
  143. width: 100rpx;
  144. height: 100rpx;
  145. margin: 0;
  146. .img-box {
  147. width: 100%;
  148. height: 100%;
  149. border: 2rpx solid #ccc;
  150. border-radius: 50%;
  151. border: 1px solid gold;
  152. }
  153. .vipIcon {
  154. position: absolute;
  155. width: 50%;
  156. height: 50%;
  157. bottom: 0;
  158. right: 0;
  159. transform: translate(0, 30%);
  160. }
  161. }
  162. .nameBox {
  163. display: flex;
  164. flex-direction: column;
  165. justify-content: space-around;
  166. margin-left: 30rpx;
  167. .name {
  168. color: #724d2b;
  169. }
  170. .vipInfo {
  171. color: #572a00;
  172. }
  173. }
  174. }
  175. .swiper-box {
  176. height: 200rpx;
  177. .swiper-items {
  178. display: grid;
  179. grid-template-columns: 1fr 1fr;
  180. }
  181. .swiper-item {
  182. display: flex;
  183. flex-direction: column;
  184. justify-content: center;
  185. align-items: center;
  186. height: 200rpx;
  187. padding: 20rpx 10rpx;
  188. box-sizing: border-box;
  189. .card {
  190. color: #774e20;
  191. background-color: rgb(255, 251, 248);
  192. border: 1px solid #f1b17a;
  193. width: 100%;
  194. height: 100%;
  195. border-radius: 10rpx;
  196. padding: 0 20rpx;
  197. box-sizing: border-box;
  198. display: flex;
  199. justify-content: space-between;
  200. align-items: center;
  201. position: relative;
  202. overflow: hidden;
  203. &.recommend {
  204. &::after {
  205. content: '推荐';
  206. position: absolute;
  207. right: 0;
  208. top: 0;
  209. padding: 6rpx 10rpx;
  210. font-size: 28rpx;
  211. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  212. }
  213. }
  214. &.vipFlag {
  215. &::before {
  216. content: '我的套餐';
  217. position: absolute;
  218. left: 0;
  219. top: 0;
  220. padding: 6rpx 10rpx;
  221. font-size: 28rpx;
  222. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  223. }
  224. }
  225. &.active {
  226. box-shadow: 0 0 18rpx 0 rgb(216 160 82);
  227. }
  228. }
  229. }
  230. }
  231. .itemBox {
  232. padding: 20rpx 40rpx;
  233. .item {
  234. // padding: 10rpx 0;
  235. margin-top: 20rpx;
  236. // color: rgba(119,78,32,.5);
  237. // &.active {
  238. color:#774e20;
  239. // }
  240. }
  241. }
  242. .pay {
  243. position: sticky;
  244. bottom: 0;
  245. padding: 0 40rpx 50rpx 40rpx;
  246. box-sizing: border-box;
  247. &-box {
  248. width: 100%;
  249. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  250. border-radius: 180rpx 0 180rpx 0;
  251. box-shadow: 3rpx 6rpx 10rpx 0rpx rgb(216 160 82);
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: center;
  255. height: 100rpx;
  256. .price {
  257. padding: 0 40rpx;
  258. font-size: 40rpx;
  259. font-weight: 600;
  260. color: #e68735;
  261. }
  262. .btn {
  263. height: 100%;
  264. display: flex;
  265. align-items: center;
  266. padding: 0 40rpx;
  267. border: 2rpx solid #00897B;
  268. background: #00897B;
  269. color: #FFF;
  270. border-radius: 180rpx 0 180rpx 0;
  271. position: relative;
  272. // &::after {
  273. // content: '';
  274. // position: absolute;
  275. // width: 50rpx;
  276. // height: 50rpx;
  277. // background: radial-gradient(top right, transparent 50%, #00897B 50%);
  278. // left: 0;
  279. // top: 0;
  280. // margin-left: -25rpx;
  281. // border-radius: 180rpx;
  282. // }
  283. }
  284. }
  285. }
  286. </style>