index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. price: item.price/100,
  118. my: vipFlagIndex === index,
  119. list: JSON.parse(item.text),
  120. type: 3, // 订单类型 0平台订单|1求职端订单|2招聘端订单|3会员套餐
  121. loading: false
  122. }
  123. })
  124. // 低于当前套餐的(套餐)不展示
  125. memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
  126. if ((!userInfo.value?.vipFlag || userInfo.value?.vipExpireDate - new Date().getTime() > 0 ) && typeof recommend.value === 'number') {
  127. current.value = parseInt(recommend.value / 2)
  128. chooseId.value = memberList.value[recommend.value]?.id
  129. }
  130. } catch (error) {
  131. uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
  132. }
  133. }
  134. getMemberList()
  135. </script>
  136. <style lang="scss" scoped>
  137. .vipBox {
  138. // color: #a18a0f;
  139. padding: 80rpx 50rpx;
  140. display: flex;
  141. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  142. .avatar{
  143. position: relative;
  144. width: 100rpx;
  145. height: 100rpx;
  146. margin: 0;
  147. .img-box {
  148. width: 100%;
  149. height: 100%;
  150. border: 2rpx solid #ccc;
  151. border-radius: 50%;
  152. border: 1px solid gold;
  153. }
  154. .vipIcon {
  155. position: absolute;
  156. width: 50%;
  157. height: 50%;
  158. bottom: 0;
  159. right: 0;
  160. transform: translate(0, 30%);
  161. }
  162. }
  163. .nameBox {
  164. display: flex;
  165. flex-direction: column;
  166. justify-content: space-around;
  167. margin-left: 30rpx;
  168. .name {
  169. color: #724d2b;
  170. }
  171. .vipInfo {
  172. color: #572a00;
  173. }
  174. }
  175. }
  176. .swiper-box {
  177. height: 200rpx;
  178. .swiper-items {
  179. display: grid;
  180. grid-template-columns: 1fr 1fr;
  181. }
  182. .swiper-item {
  183. display: flex;
  184. flex-direction: column;
  185. justify-content: center;
  186. align-items: center;
  187. height: 200rpx;
  188. padding: 20rpx 10rpx;
  189. box-sizing: border-box;
  190. .card {
  191. color: #774e20;
  192. background-color: rgb(255, 251, 248);
  193. border: 1px solid #f1b17a;
  194. width: 100%;
  195. height: 100%;
  196. border-radius: 10rpx;
  197. padding: 0 20rpx;
  198. box-sizing: border-box;
  199. display: flex;
  200. justify-content: space-between;
  201. align-items: center;
  202. position: relative;
  203. overflow: hidden;
  204. &.recommend {
  205. &::after {
  206. content: '推荐';
  207. position: absolute;
  208. right: 0;
  209. top: 0;
  210. padding: 6rpx 10rpx;
  211. font-size: 28rpx;
  212. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  213. }
  214. }
  215. &.vipFlag {
  216. &::before {
  217. content: '我的套餐';
  218. position: absolute;
  219. left: 0;
  220. top: 0;
  221. padding: 6rpx 10rpx;
  222. font-size: 28rpx;
  223. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  224. }
  225. }
  226. &.active {
  227. box-shadow: 0 0 18rpx 0 rgb(216 160 82);
  228. }
  229. }
  230. }
  231. }
  232. .itemBox {
  233. padding: 20rpx 40rpx;
  234. .item {
  235. // padding: 10rpx 0;
  236. margin-top: 20rpx;
  237. // color: rgba(119,78,32,.5);
  238. // &.active {
  239. color:#774e20;
  240. // }
  241. }
  242. }
  243. .pay {
  244. position: sticky;
  245. bottom: 0;
  246. padding: 0 40rpx 50rpx 40rpx;
  247. box-sizing: border-box;
  248. &-box {
  249. width: 100%;
  250. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  251. border-radius: 180rpx 0 180rpx 0;
  252. box-shadow: 3rpx 6rpx 10rpx 0rpx rgb(216 160 82);
  253. display: flex;
  254. justify-content: space-between;
  255. align-items: center;
  256. height: 100rpx;
  257. .price {
  258. padding: 0 40rpx;
  259. font-size: 40rpx;
  260. font-weight: 600;
  261. color: #e68735;
  262. }
  263. .btn {
  264. height: 100%;
  265. display: flex;
  266. align-items: center;
  267. padding: 0 40rpx;
  268. border: 2rpx solid #00897B;
  269. background: #00897B;
  270. color: #FFF;
  271. border-radius: 180rpx 0 180rpx 0;
  272. position: relative;
  273. // &::after {
  274. // content: '';
  275. // position: absolute;
  276. // width: 50rpx;
  277. // height: 50rpx;
  278. // background: radial-gradient(top right, transparent 50%, #00897B 50%);
  279. // left: 0;
  280. // top: 0;
  281. // margin-left: -25rpx;
  282. // border-radius: 180rpx;
  283. // }
  284. }
  285. }
  286. }
  287. </style>