packageList.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <!-- -->
  2. <template>
  3. <div class="d-flex mt-5 list">
  4. <div v-for="(val, i) in packDataList" :key="i" class="list-item cursor-pointer" :class="{'active': active === i }" @click="handleClickItem(val, i)">
  5. <div v-if="val.id === userStore.userInfo?.vipFlag" class="recommend long">我的套餐</div>
  6. <div v-if="val.recommend" class="recommend">推荐</div>
  7. <div class="text-center font-weight-bold">{{ val.name }}</div>
  8. <div class="text-center my-5">
  9. <div v-if="val.price && !val.cycle">
  10. <span class="font-weight-bold font-size-20">{{ val.price }}</span>
  11. <!-- /年 -->
  12. </div>
  13. <div v-if="val.cycle">¥<span class="font-weight-bold font-size-18 font-size-20">{{ val.price }}</span><span class="font-size-14 mr-3">起</span> {{ val.cycle }}</div>
  14. <!-- <div v-if="val.customized" class="font-size-20 font-weight-bold">按需定制</div> -->
  15. </div>
  16. <v-divider></v-divider>
  17. <!-- <div v-if="val.equity">
  18. <div class="font-weight-bold my-3">权益</div>
  19. <ul>
  20. <li v-for="(k, num) in val.equity" :key="k" :class="{'greyText': num+1 > val.showLength}">{{ k }}</li>
  21. </ul>
  22. </div> -->
  23. <div v-if="val.text">
  24. <div class="font-weight-bold my-3">权益</div>
  25. <div v-html="val.text"></div>
  26. </div>
  27. <!-- <div v-else>
  28. <h3 class="my-3">授权范围:</h3>
  29. <div class="font-size-15">扫描下方二维码联系高级客户经理为您定制</div>
  30. </div> -->
  31. <div
  32. v-if="userStore.userInfo?.vipFlag === val.id && canUse"
  33. style="font-size: 14px; position: absolute; bottom: 30px;" class="mt-5"
  34. >
  35. 有效期:{{ timesTampChange(userStore.userInfo?.vipExpireDate, 'Y-M-D') }}
  36. </div>
  37. <div class="text-center item-btn" v-else>
  38. <v-btn
  39. color="error"
  40. variant="outlined"
  41. rounded
  42. :loading="val.loading"
  43. @click="createOrder(val)"
  44. >开通会员</v-btn>
  45. </div>
  46. </div>
  47. </div>
  48. <CtDialog :visible="open" :widthType="3" :footer="false" titleClass="text-h6" title="开通会员" @close="open = false">
  49. <m-pay
  50. :payPrice="payPrice"
  51. :qrCode="qrCode"
  52. :disabled="disabled"
  53. :expirationTime="expirationTime"
  54. :payChannelCode="payChannelCode"
  55. :orderId="orderId"
  56. @overdue="handleOverdue"
  57. @refreshQrCode="refreshQrCode"
  58. @paySuccess="paySuccess"
  59. ></m-pay>
  60. </CtDialog>
  61. </template>
  62. <script setup>
  63. defineOptions({name: 'purchasePackage-packageList'})
  64. import { ref, computed } from 'vue'
  65. // import Snackbar from '@/plugins/snackbar'
  66. import MPay from '@/components/personalRecharge/pay.vue'
  67. import { orderCreated, getOrder, payOrderSubmit } from '@/api/common'
  68. import { getMembershipPackageList } from '@/api/recruit/personal/membershipPackage.js'
  69. import Snackbar from '@/plugins/snackbar'
  70. import { useUserStore } from '@/store/user'
  71. import { timesTampChange } from '@/utils/date'
  72. const userStore = useUserStore()
  73. const active = ref(null)
  74. const handleClickItem = (val, i) => {
  75. active.value = i
  76. }
  77. const open = ref(false)
  78. const disabled = ref(false)
  79. const qrCode = ref('')
  80. const payChannelCode = ref('wx_native')
  81. const payPrice = ref(0)
  82. const expirationTime = ref(-1)
  83. const orderId = ref('')
  84. const canUse = computed(() => {
  85. return new Date().getTime() < userStore.userInfo?.vipExpireDate
  86. })
  87. const packDataList = ref([])
  88. const getData = async () => {
  89. const data = await getMembershipPackageList()
  90. if (!data?.length) return
  91. // packDataList.value =
  92. let vipFlagIndex = null
  93. const list = data.map((item, index) => {
  94. item.id = item.id?.toString()
  95. if (item.id === userStore.userInfo?.vipFlag) vipFlagIndex = index // 低于当前套餐的(套餐)不展示
  96. if (item.recommend) active.value = index // 推荐套餐
  97. return {
  98. ...item,
  99. type: 3, // 订单类型 0平台订单|1求职端订单|2招聘端订单|3会员套餐
  100. loading: false
  101. }
  102. })
  103. // 低于当前套餐的(套餐)不展示
  104. packDataList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
  105. }
  106. getData()
  107. // 重新获取订单
  108. const refreshQrCode = (payType) => {
  109. payChannelCode.value = payType
  110. }
  111. // 创建订单
  112. async function createOrder (val) {
  113. val.loading = true
  114. payPrice.value = val.price
  115. try {
  116. const data = await getOrder({
  117. spuId: val.id, // 商品编号
  118. type: val.type
  119. })
  120. if (data) {
  121. // 获取支付码
  122. paymentCode(data)
  123. return
  124. }
  125. await orderCreated({
  126. spuId: val.id, // 商品编号
  127. spuName: val.name, // 商品名称
  128. price: val.price * 100, // 价格
  129. type: val.type // 订单类型 0平台订单|1求职端订单|2招聘端订单|3会员套餐
  130. })
  131. const _data = await getOrder({
  132. spuId: val.id, // 商品编号
  133. type: val.type
  134. })
  135. // 获取支付码
  136. paymentCode(_data)
  137. // qrCode.value = data
  138. } catch (error) {
  139. console.log(error)
  140. } finally {
  141. val.loading = false
  142. }
  143. }
  144. async function paymentCode (param) {
  145. try {
  146. const res = await payOrderSubmit({
  147. id: param.payOrder.id,
  148. channelCode: payChannelCode.value
  149. })
  150. if (!res?.displayContent) {
  151. Snackbar.error('获取支付码失败')
  152. return
  153. }
  154. orderId.value = param.payOrder.id
  155. expirationTime.value = param.payOrder.expireTime - new Date().getTime()
  156. // expirationTime.value = param.payOrder.expireTime - _now
  157. qrCode.value = res.displayContent
  158. open.value = true
  159. } catch (error) {
  160. console.log(error)
  161. }
  162. }
  163. // 支付成功
  164. function paySuccess () {
  165. Snackbar.success('支付成功')
  166. // 更新个人资料
  167. userStore.getUserInfos()
  168. open.value = false
  169. }
  170. // 过期
  171. function handleOverdue () {
  172. disabled.value = true
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .greyText {
  177. color: #774e2085 !important;
  178. }
  179. .list {
  180. width: 100%;
  181. }
  182. .list-item {
  183. position: relative;
  184. // height: 400px;
  185. min-height: 480px;;
  186. width: calc((100% - 120px) / 5);
  187. min-width: calc((100% - 120px) / 5);
  188. max-width: calc((100% - 120px) / 5);
  189. padding: 30px 20px;
  190. border-radius: 14px;
  191. margin-right: 30px;
  192. color: #774e20;
  193. background-color: #fafafa;
  194. &:nth-child(5n) {
  195. margin-right: 0;
  196. }
  197. .item-btn {
  198. position: absolute;
  199. bottom: 30px;
  200. left: 50%;
  201. transform: translateX(-50%);
  202. }
  203. }
  204. ul li {
  205. list-style: none;
  206. font-size: 15px;
  207. margin: 10px 0;
  208. font-weight: 500;
  209. }
  210. .active {
  211. background-color: rgba(255, 251, 248, 1);
  212. border: 1px solid #f1b17a;
  213. box-shadow: 0px 6px 12px 0px rgba(216, 160, 82, 0.36);
  214. }
  215. :deep(.v-btn) {
  216. border: 1px solid #bc8b55;
  217. color: #c30f0f !important;
  218. font-weight: 700;
  219. }
  220. .tips {
  221. background-color: #fffbf8;
  222. border: 1px solid #f1b17a;
  223. border-radius: 4px;
  224. text-align: center;
  225. font-size: 15px;
  226. }
  227. .recommend {
  228. position: absolute;
  229. top: 0;
  230. left: 0;
  231. width: 55px;
  232. height: 26px;
  233. line-height: 26px;
  234. background-color: #ff8a04;
  235. border-radius: 12px 0 18px 0;
  236. font-weight: 600;
  237. font-size: 14px;
  238. color: #fff;
  239. text-align: center;
  240. }
  241. .long {
  242. width: 100px;
  243. }
  244. .scanCode {
  245. border: 1px dashed #ccc;
  246. border-radius: 10px;
  247. padding: 30px;
  248. .code-left {
  249. border: 1px solid #f1b17a;
  250. border-radius: 6px;
  251. padding: 5px;
  252. }
  253. .price {
  254. font-size: 30px;
  255. font-weight: 700;
  256. color: #ff9012;
  257. }
  258. }
  259. :deep(.v-slide-group__content) {
  260. background: none !important;
  261. }
  262. .package-title {
  263. height: 60px;
  264. line-height: 60px;
  265. color: #fff;
  266. background: linear-gradient(45deg, #ff8a04, transparent);
  267. font-weight: 700;
  268. font-size: 20px;
  269. text-align: center;
  270. border-radius: 4px;
  271. }
  272. </style>