|
@@ -1,10 +1,20 @@
|
|
<!-- 支付方式 -->
|
|
<!-- 支付方式 -->
|
|
<template>
|
|
<template>
|
|
- <div>
|
|
|
|
|
|
+ <v-card elevation="0" :loading="loading" :disabled="loading">
|
|
|
|
+ <!-- 加载样式 -->
|
|
|
|
+ <template v-slot:loader="{ isActive }">
|
|
|
|
+ <v-progress-linear
|
|
|
|
+ :active="isActive"
|
|
|
|
+ color="var(--v-primary-base)"
|
|
|
|
+ height="1"
|
|
|
|
+ indeterminate
|
|
|
|
+ ></v-progress-linear>
|
|
|
|
+ </template>
|
|
|
|
+
|
|
<!-- 赏金所需 -->
|
|
<!-- 赏金所需 -->
|
|
<div class="pt-3 pb-5" style="color: var(--v-error-base); font-weight: bold; text-align: center;">
|
|
<div class="pt-3 pb-5" style="color: var(--v-error-base); font-weight: bold; text-align: center;">
|
|
<span class="font-size-13">¥</span>
|
|
<span class="font-size-13">¥</span>
|
|
- <span class="font-size-30">{{ needPrice }}</span>
|
|
|
|
|
|
+ <span class="font-size-30">{{ cost }}</span>
|
|
</div>
|
|
</div>
|
|
<radioGroupUI
|
|
<radioGroupUI
|
|
:modelValue="payType"
|
|
:modelValue="payType"
|
|
@@ -28,26 +38,29 @@
|
|
<div v-if="isQrCodePay && payQrCodeTet" style="color: var(--v-error-base);">扫码支付时请勿离开</div>
|
|
<div v-if="isQrCodePay && payQrCodeTet" style="color: var(--v-error-base);">扫码支付时请勿离开</div>
|
|
</div>
|
|
</div>
|
|
<div class="mt-10" style="text-align: center;">
|
|
<div class="mt-10" style="text-align: center;">
|
|
|
|
+ <!-- v-if="(isQrCodePay && payQrCodeTet) || isWalletPay" -->
|
|
<v-btn
|
|
<v-btn
|
|
- v-if="(isQrCodePay && payQrCodeTet) || isWalletPay"
|
|
|
|
|
|
+ v-if="isWalletPay"
|
|
class="buttons" color="primary"
|
|
class="buttons" color="primary"
|
|
:loading="payLoading"
|
|
:loading="payLoading"
|
|
@click="paySubmit"
|
|
@click="paySubmit"
|
|
>
|
|
>
|
|
- {{ isWalletPay ? '确认' : '支付完成' }}
|
|
|
|
|
|
+ <!-- {{ isWalletPay ? '确认' : '支付完成' }} -->
|
|
|
|
+ 确认
|
|
</v-btn>
|
|
</v-btn>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- </div>
|
|
|
|
|
|
+ </v-card>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
defineOptions({ name: 'pay-index'})
|
|
defineOptions({ name: 'pay-index'})
|
|
-import { computed, ref } from 'vue'
|
|
|
|
|
|
+import { computed, onUnmounted, ref } from 'vue'
|
|
import radioGroupUI from '@/components/FormUI/radioGroup'
|
|
import radioGroupUI from '@/components/FormUI/radioGroup'
|
|
import QrCode from '@/components/QrCode'
|
|
import QrCode from '@/components/QrCode'
|
|
import { definePayTypeList, qrCodePay, walletPay } from './until/payType'
|
|
import { definePayTypeList, qrCodePay, walletPay } from './until/payType'
|
|
-import { getEnableCodeList } from '@/api/common'
|
|
|
|
|
|
+import { getEnableCodeList, getUnpaidOrder, payOrderSubmit, getOrderPayStatus } from '@/api/common'
|
|
|
|
+import { createTradeOrder } from '@/api/position'
|
|
import { useSharedState } from '@/store/sharedState'
|
|
import { useSharedState } from '@/store/sharedState'
|
|
const emit = defineEmits(['payTypeChange', ])
|
|
const emit = defineEmits(['payTypeChange', ])
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
@@ -55,15 +68,24 @@ const props = defineProps({
|
|
type: Object,
|
|
type: Object,
|
|
default: () => {}
|
|
default: () => {}
|
|
},
|
|
},
|
|
- // codeList: {
|
|
|
|
- // type: Array,
|
|
|
|
- // default: () => []
|
|
|
|
- // },
|
|
|
|
- needPrice: {
|
|
|
|
|
|
+ cost: {
|
|
type: [String, Number],
|
|
type: [String, Number],
|
|
default: 0
|
|
default: 0
|
|
},
|
|
},
|
|
|
|
+ spuId: { // 原始数据id
|
|
|
|
+ type: String,
|
|
|
|
+ default: ''
|
|
|
|
+ },
|
|
|
|
+ spuName: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: ''
|
|
|
|
+ },
|
|
|
|
+ type: {
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 2 // 订单类型 0平台订单| 1发布职位订单| 2发布众聘职位订单,示例值(1)
|
|
|
|
+ },
|
|
})
|
|
})
|
|
|
|
+const loading = ref(true)
|
|
|
|
|
|
// 支付方式
|
|
// 支付方式
|
|
const payType = ref('')
|
|
const payType = ref('')
|
|
@@ -86,7 +108,10 @@ const getCodeList = async () => {
|
|
codeList.value.forEach(code => {
|
|
codeList.value.forEach(code => {
|
|
const item = definePayTypeList.find(p => p.code === code)
|
|
const item = definePayTypeList.find(p => p.code === code)
|
|
if (item) {
|
|
if (item) {
|
|
- if (!payType.value) payType.value = code // 默认值赋值
|
|
|
|
|
|
+ if (!payType.value) {
|
|
|
|
+ // payType.value = code
|
|
|
|
+ payTypeChange(code) // 默认值赋值
|
|
|
|
+ }
|
|
payTypeList.value.push(item)
|
|
payTypeList.value.push(item)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -95,18 +120,42 @@ const getCodeList = async () => {
|
|
}
|
|
}
|
|
getCodeList()
|
|
getCodeList()
|
|
|
|
|
|
|
|
+const payOrder = ref({})
|
|
|
|
+let maxCount = 0
|
|
|
|
+// 获取待支付的订单
|
|
|
|
+const getUnpaidOrderList = async () => {
|
|
|
|
+ try {
|
|
|
|
+ const data = await getUnpaidOrder({ spuId: props.spuId, type: props.type })
|
|
|
|
+ // order:业务订单; payOrder:支付订单
|
|
|
|
+ console.log('获取待支付的订单', data)
|
|
|
|
+ if (!data) {
|
|
|
|
+ // 订单超时,重新提交订单
|
|
|
|
+ await createTradeOrder({
|
|
|
|
+ spuId: props.spuId,
|
|
|
|
+ spuName: props.spuName,
|
|
|
|
+ price: props.cost,
|
|
|
|
+ type: props.type, // 发布众聘职位订单
|
|
|
|
+ })
|
|
|
|
+ if (maxCount > 3) return // 避免死循环
|
|
|
|
+ maxCount++
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ getUnpaidOrderList()
|
|
|
|
+ }, 1000)
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ if (data?.payOrder) {
|
|
|
|
+ payOrder.value = data.payOrder
|
|
|
|
+ loading.value = false
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+getUnpaidOrderList() // getUnpaidOrder
|
|
|
|
+
|
|
const payLoading = ref(false)
|
|
const payLoading = ref(false)
|
|
const payQrCodeTet = ref('')
|
|
const payQrCodeTet = ref('')
|
|
|
|
|
|
-const isQrCodePay = computed(() => {
|
|
|
|
- const bool = qrCodePay.includes(payType.value)
|
|
|
|
- if (bool) initPayQrCode() // 生成二维码内容
|
|
|
|
- return bool
|
|
|
|
-})
|
|
|
|
-const isWalletPay = computed(() => {
|
|
|
|
- return walletPay.includes(payType.value)
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
const payTypeItem = {
|
|
const payTypeItem = {
|
|
label: '',
|
|
label: '',
|
|
width: 1,
|
|
width: 1,
|
|
@@ -118,22 +167,67 @@ const payTypeItem = {
|
|
|
|
|
|
const balance = JSON.parse(localStorage.getItem('enterpriseUserAccount'))?.balance || 0
|
|
const balance = JSON.parse(localStorage.getItem('enterpriseUserAccount'))?.balance || 0
|
|
const balanceNotEnough = computed(() => {
|
|
const balanceNotEnough = computed(() => {
|
|
- return (Number(props.needPrice) > Number(balance))
|
|
|
|
|
|
+ return (Number(props.cost) > Number(balance))
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+const isWalletPay = ref(true)
|
|
|
|
+const isQrCodePay = ref(false)
|
|
const payTypeChange = (val) => {
|
|
const payTypeChange = (val) => {
|
|
payType.value = val
|
|
payType.value = val
|
|
|
|
+ isQrCodePay.value = qrCodePay.includes(payType.value)
|
|
|
|
+ isWalletPay.value = walletPay.includes(payType.value)
|
|
|
|
+ if (isQrCodePay.value) initPayQrCode() // 生成二维码内容
|
|
emit('payTypeChange', val, balanceNotEnough)
|
|
emit('payTypeChange', val, balanceNotEnough)
|
|
}
|
|
}
|
|
|
|
|
|
-const initPayQrCode = () => { // 生成二维码内容
|
|
|
|
- setTimeout(() => { payQrCodeTet.value = '测试测试测试测试测试测试测试测试' }, 2000)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
const paySubmit = () => {
|
|
const paySubmit = () => {
|
|
emit('paySubmit', payType.value)
|
|
emit('paySubmit', payType.value)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 生成二维码内容
|
|
|
|
+const timer = ref(null)
|
|
|
|
+onUnmounted(() => {
|
|
|
|
+ if (timer.value) clearInterval(timer.value); timer.value = null
|
|
|
|
+})
|
|
|
|
+const initPayQrCode = async () => {
|
|
|
|
+ if (timer.value) clearInterval(timer.value); timer.value = null
|
|
|
|
+ try {
|
|
|
|
+ if (payOrder.value) {
|
|
|
|
+ // 提交支付订单
|
|
|
|
+ const params = {
|
|
|
|
+ id: payOrder.value.id, // 支付单编号
|
|
|
|
+ channelCode: payType.value, // 支付渠道
|
|
|
|
+ displayMode: payOrder.value.notifyUrl, // 展示模式 notifyUrl
|
|
|
|
+ returnUrl: '',
|
|
|
|
+ }
|
|
|
|
+ const res = await payOrderSubmit(params)
|
|
|
|
+ payQrCodeTet.value = res?.displayContent || '' // 支付二维码
|
|
|
|
+ timer.value = setInterval(() => { payStatus() }, 1000) // 轮巡查询用户是否支付
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+import Snackbar from '@/plugins/snackbar'
|
|
|
|
+import { useRouter } from 'vue-router'; const router = useRouter()
|
|
|
|
+const payStatus = async () => {
|
|
|
|
+ try {
|
|
|
|
+ const data = await getOrderPayStatus({ id: payOrder.value.id })
|
|
|
|
+ if ((data?.status - 0) === 1) {
|
|
|
|
+ // 支付成功
|
|
|
|
+ if (timer.value) clearInterval(timer.value); timer.value = null
|
|
|
|
+ const query = { hire: true }
|
|
|
|
+ router.push({ path: '/recruit/enterprise/position', query }) // 返回到众聘页面
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ Snackbar.success('付款成功')
|
|
|
|
+ }, 1000);
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
</script>
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
.font-size-30 { font-size: 30px; }
|
|
.font-size-30 { font-size: 30px; }
|