packageList.vue 8.0 KB

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