index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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" v-if="!list.my">
  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. {{ amount }}
  56. </view>
  57. <view class="btn" @tap="handleOpen">
  58. 立刻升级
  59. </view>
  60. </view>
  61. </view>
  62. <uni-popup ref="popup" :is-mask-click="false" borderRadius="10px 10px 0 0" background-color="#eee">
  63. <view class="popup-content">
  64. <view class="popup-content-close">
  65. <view class="icon" @tap="handleClose">
  66. <uni-icons
  67. type="closeempty"
  68. color="#999"
  69. size="24"
  70. />
  71. </view>
  72. </view>
  73. <view class="popup-content-main">
  74. <view class="popup-content-main-count">
  75. <view class="title">{{ list.name }} 充值</view>
  76. <view class="pay">
  77. <uni-icons color="#000" type="icon-renminbi1688" size="16" custom-prefix="iconfont"></uni-icons>
  78. <view>{{ amount }}</view>
  79. </view>
  80. </view>
  81. <view class="popup-content-main-type">
  82. <view class="card">
  83. <radio-group @change="radioChange">
  84. <label class="card-label" v-for="(item, index) in payType" :key="item.value">
  85. <view class="name">
  86. <uni-icons :color="item.color" class="mr-1" :type="item.icon" size="24" custom-prefix="iconfont"></uni-icons>
  87. {{item.name}}
  88. </view>
  89. <view>
  90. <radio :value="item.value" :checked="index === payTypeCurrent" />
  91. </view>
  92. </label>
  93. </radio-group>
  94. </view>
  95. </view>
  96. </view>
  97. <view class="popup-content-btn">
  98. <button class="popup-content-btn-s" @tap="handlePay">
  99. 确认支付
  100. <uni-icons color="#FFF" type="icon-renminbi1688" size="16" custom-prefix="iconfont"></uni-icons>
  101. {{ amount }}
  102. </button>
  103. </view>
  104. </view>
  105. </uni-popup>
  106. </view>
  107. </template>
  108. <script setup>
  109. import { ref, computed, watch } from 'vue'
  110. import { getUserAvatar } from '@/utils/avatar'
  111. import { userStore } from '@/store/user'
  112. import { getMembershipPackageList } from '@/api/vip'
  113. const useUserStore = userStore()
  114. const baseInfo = computed(() => useUserStore?.baseInfo)
  115. const userInfo = computed(() => useUserStore?.userInfo)
  116. const memberList = ref([])
  117. const recommend = ref(null)
  118. const chooseId = ref(null)
  119. const popup = ref()
  120. const amount = computed(() => {
  121. return parseFloat(+list.value.price).toFixed(2)
  122. })
  123. const memberListLength = computed(() => {
  124. const result = [];
  125. for (let i = 0; i < memberList.value.length; i += 2) {
  126. const pair = memberList.value.slice(i, i + 2)
  127. result.push(pair)
  128. }
  129. return result
  130. })
  131. const pName = computed(() => {
  132. return memberList.value.find(item => +item.id === +userInfo.value?.vipFlag)?.name
  133. })
  134. const remaining = computed(() => {
  135. if (!userInfo.value?.vipExpireDate) return null
  136. const diffInMs = userInfo.value?.vipExpireDate - new Date().getTime()
  137. const day = diffInMs / (1000 * 60 * 60 * 24)
  138. return day < 1 ? '今天' : Math.floor(day) + '天'
  139. })
  140. const list = computed(() => {
  141. const item = memberList.value.find(item => item.id === chooseId.value)
  142. return item ?? {}
  143. })
  144. const current = ref(0)
  145. const payType = ref([
  146. {
  147. name: '微信支付',
  148. value: 'wxpay',
  149. icon: 'icon-weixinzhifu',
  150. color: '#1AAD19'
  151. }
  152. // {
  153. // name: '银行卡支付',
  154. // value: 'alipay',
  155. // icon: 'icon-alipay',
  156. // color: '#1296db'
  157. // }
  158. ])
  159. const payTypeCurrent = ref(0)
  160. const radioChange = (index) => {
  161. payTypeCurrent.value = index
  162. }
  163. const handleChoose = (id) => {
  164. chooseId.value = id
  165. }
  166. const handleOpen = () => {
  167. popup.value.open('bottom')
  168. }
  169. const handleClose = () => {
  170. popup.value.close()
  171. }
  172. // 支付
  173. const handlePay = async () => {
  174. uni.showToast({ title: '支付升级中', icon: 'none'})
  175. }
  176. const getMemberList = async () => {
  177. try {
  178. const { data } = await getMembershipPackageList()
  179. if (!data || data.length === 0) {
  180. return
  181. }
  182. // memberList.value = data
  183. let vipFlagIndex = null
  184. const list = data.map((item, index) => {
  185. if (+item.id === +userInfo.value?.vipFlag) {
  186. vipFlagIndex = index // 低于当前套餐的(套餐)不展示
  187. }
  188. if (item.recommend) {
  189. recommend.value = index // 推荐套餐
  190. }
  191. return {
  192. ...item,
  193. price: item.price/100,
  194. my: vipFlagIndex === index,
  195. list: JSON.parse(item.text),
  196. type: 3, // 订单类型 0平台订单|1求职端订单|2招聘端订单|3会员套餐
  197. loading: false
  198. }
  199. })
  200. // 低于当前套餐的(套餐)不展示
  201. memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
  202. handleChoose(memberList.value[0]?.id)
  203. if ((!userInfo.value?.vipFlag || userInfo.value?.vipExpireDate - new Date().getTime() > 0 ) && typeof recommend.value === 'number') {
  204. current.value = parseInt(recommend.value / 2)
  205. chooseId.value = memberList.value[recommend.value]?.id
  206. }
  207. } catch (error) {
  208. uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
  209. }
  210. }
  211. getMemberList()
  212. </script>
  213. <style lang="scss" scoped>
  214. .vipBox {
  215. // color: #a18a0f;
  216. padding: 80rpx 50rpx;
  217. display: flex;
  218. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  219. .avatar{
  220. position: relative;
  221. width: 100rpx;
  222. height: 100rpx;
  223. margin: 0;
  224. .img-box {
  225. width: 100%;
  226. height: 100%;
  227. border: 2rpx solid #ccc;
  228. border-radius: 50%;
  229. border: 1px solid gold;
  230. }
  231. .vipIcon {
  232. position: absolute;
  233. width: 50%;
  234. height: 50%;
  235. bottom: 0;
  236. right: 0;
  237. transform: translate(0, 30%);
  238. }
  239. }
  240. .nameBox {
  241. display: flex;
  242. flex-direction: column;
  243. justify-content: space-around;
  244. margin-left: 30rpx;
  245. .name {
  246. color: #724d2b;
  247. }
  248. .vipInfo {
  249. color: #572a00;
  250. }
  251. }
  252. }
  253. .swiper-box {
  254. height: 200rpx;
  255. .swiper-items {
  256. display: grid;
  257. grid-template-columns: 1fr 1fr;
  258. }
  259. .swiper-item {
  260. display: flex;
  261. flex-direction: column;
  262. justify-content: center;
  263. align-items: center;
  264. height: 200rpx;
  265. padding: 20rpx 10rpx;
  266. box-sizing: border-box;
  267. .card {
  268. color: #774e20;
  269. background-color: rgb(255, 251, 248);
  270. border: 1px solid #f1b17a;
  271. width: 100%;
  272. height: 100%;
  273. border-radius: 10rpx;
  274. padding: 0 20rpx;
  275. box-sizing: border-box;
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. position: relative;
  280. overflow: hidden;
  281. &.recommend {
  282. &::after {
  283. content: '推荐';
  284. position: absolute;
  285. right: 0;
  286. top: 0;
  287. padding: 6rpx 10rpx;
  288. font-size: 28rpx;
  289. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  290. }
  291. }
  292. &.vipFlag {
  293. &::before {
  294. content: '我的套餐';
  295. position: absolute;
  296. left: 0;
  297. top: 0;
  298. padding: 6rpx 10rpx;
  299. font-size: 28rpx;
  300. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  301. }
  302. }
  303. &.active {
  304. box-shadow: 0 0 18rpx 0 rgb(216 160 82);
  305. }
  306. }
  307. }
  308. }
  309. .itemBox {
  310. padding: 20rpx 40rpx;
  311. .item {
  312. // padding: 10rpx 0;
  313. margin-top: 20rpx;
  314. // color: rgba(119,78,32,.5);
  315. // &.active {
  316. color:#774e20;
  317. // }
  318. }
  319. }
  320. .pay {
  321. position: sticky;
  322. bottom: 0;
  323. padding: 0 40rpx 50rpx 40rpx;
  324. box-sizing: border-box;
  325. &-box {
  326. width: 100%;
  327. background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  328. border-radius: 180rpx 0 180rpx 0;
  329. box-shadow: 3rpx 6rpx 10rpx 0rpx rgb(216 160 82);
  330. display: flex;
  331. justify-content: space-between;
  332. align-items: center;
  333. height: 100rpx;
  334. .price {
  335. padding: 0 40rpx;
  336. font-size: 40rpx;
  337. font-weight: 600;
  338. color: #e68735;
  339. }
  340. .btn {
  341. height: 100%;
  342. display: flex;
  343. align-items: center;
  344. padding: 0 40rpx;
  345. border: 2rpx solid #00897B;
  346. background: #00897B;
  347. color: #FFF;
  348. border-radius: 180rpx 0 180rpx 0;
  349. position: relative;
  350. // &::after {
  351. // content: '';
  352. // position: absolute;
  353. // width: 50rpx;
  354. // height: 50rpx;
  355. // background: radial-gradient(top right, transparent 50%, #00897B 50%);
  356. // left: 0;
  357. // top: 0;
  358. // margin-left: -25rpx;
  359. // border-radius: 180rpx;
  360. // }
  361. }
  362. }
  363. }
  364. .popup-content {
  365. max-height: 500px;
  366. display: flex;
  367. flex-direction: column;
  368. &-close {
  369. display: flex;
  370. padding: 10px;
  371. justify-content: flex-end;
  372. .icon {
  373. width: 30px;
  374. height: 30px;
  375. background: #ccc;
  376. border-radius: 30px;
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. }
  381. }
  382. &-main {
  383. flex: 1;
  384. height: 0;
  385. overflow-y: auto;
  386. &-count {
  387. margin-bottom: 20px;
  388. text-align: center;
  389. .title {
  390. font-size: 28rpx;
  391. color: #666
  392. }
  393. .pay {
  394. font-size: 52rpx;
  395. color: #000;
  396. font-weight: 600;
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. padding: 10px 0;
  401. }
  402. }
  403. &-type {
  404. width: 100%;
  405. padding: 0 20px;
  406. box-sizing: border-box;
  407. .card {
  408. border-radius: 10px;
  409. margin: 0 auto;
  410. background: #FFF;
  411. padding: 10px;
  412. &-label {
  413. padding: 15px 0;
  414. box-sizing: border-box;
  415. display: flex;
  416. justify-content: space-between;
  417. border-bottom: 1px solid #eee;
  418. &:last-of-type {
  419. border-bottom: none;
  420. }
  421. .name {
  422. display: flex;
  423. align-items: center;
  424. color: #333;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. &-btn {
  431. height: 70px;
  432. width: 100%;
  433. margin-top: 10px;
  434. display: flex;
  435. align-items: center;
  436. justify-content: center;
  437. &-s {
  438. height: 40px;
  439. width: 75%;
  440. line-height: 40px;
  441. color: #FFF;
  442. // color: #724d2b;
  443. background: #00897B;
  444. // background: linear-gradient(121deg,#fde2c2 29.02%,#c19164 104.03%);
  445. border-radius: 90px;
  446. }
  447. }
  448. }
  449. .mr-1 {
  450. margin-right: 10px;
  451. }
  452. </style>