packageList.vue 8.2 KB

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