Jelajahi Sumber

发布职位时点数不足,点数充值

lifanagju_citu 9 bulan lalu
induk
melakukan
ad9d32e764

+ 34 - 20
src/components/pay/index.vue

@@ -30,13 +30,13 @@
         <div v-if="isWalletPay" class="py-10" style="text-align: center;">
           <div>
             <span>剩余点数:</span>
-            <span style="color: var(--v-primary-base);">{{ balance }}</span>
+            <span style="color: var(--v-primary-base);">{{ accountBalance }}</span>
           </div>
-          <div class="my-3" v-if="balanceNotEnough">
+          <div class="my-3" v-if="notEnoughMoney">
             <!-- <v-icon color="warning">mdi-information</v-icon> -->
             <!-- <span class="color-warning">{{ props.params?.txt || '当前余额不足,请选择其他支付方式' }}</span> -->
             <span class="color-error">
-              当前剩余点数不足,<span class="text-decoration-underline cursor-pointer" @click="showRecharge = true">去充值</span>
+              当前剩余点数不足,<span class="text-decoration-underline cursor-pointer" @click="handleRecharge">去充值</span>
             </span>
           </div>
         </div>
@@ -46,7 +46,7 @@
           <div class="mb-5" v-if="payQrCodeTxt" style="color: var(--v-error-base);">扫码支付时请勿离开</div>
         </div>
         <!-- 钱包支付确认按钮 -->
-        <div v-if="isWalletPay && !balanceNotEnough" class="mt-2" style="text-align: center;">
+        <div v-if="isWalletPay && !notEnoughMoney" class="mt-2" style="text-align: center;">
           <v-btn
             class="buttons" color="primary"
             :loading="payLoading"
@@ -59,8 +59,8 @@
     </template>
   </v-card>
 
-  <CtDialog :visible="showRecharge" :widthType="1" titleClass="text-h6" title="点数充值" :footer="false" submitText="确认" @close="handleClose">
-    <Recharge @finish="handleFinish"></Recharge>
+  <CtDialog :visible="showRecharge" :widthType="1" titleClass="text-h6" title="点数充值" :footer="false" submitText="确认" @close="handleRechargeClose">
+    <Recharge @paySuccess="RechargePaySuccess"></Recharge>
   </CtDialog>
 </template>
 
@@ -128,10 +128,10 @@ const tip = ref('')
 //      如果是点数支付也要走上面的步骤,只是不生成二维码
 
 
-const balance = ref(JSON.parse(localStorage.getItem('enterpriseUserAccount'))?.balance || 0)
-const balanceNotEnough = computed(() => {
-  console.log(props.cost, balance.value, 'balanceNotEnough')
-  return (Number(props.cost) > Number(balance))
+const accountBalance = ref(0)
+
+const notEnoughMoney = computed(() => {
+  return (Number(props.cost) > Number(accountBalance.value))
 })
 
 // 生成二维码内容
@@ -180,8 +180,7 @@ const getUnpaidOrderList = async () => {
       //* 充值
       if (props.rechargeInfo.payPrice === undefined && props.rechargeInfo.packageId === undefined) return
       const params = {
-        // payPrice: payCalculation(props.cost, 'emit'),
-        payPrice: props.rechargeInfo.payPrice - 0,
+        payPrice: (props.rechargeInfo.payPrice-0),
         packageId: props.rechargeInfo.id,
       }
       const data = await rechargeOrderCreate(params)
@@ -226,7 +225,6 @@ const payTypeChange = (value) => {
   isQrCodePay.value = qrCodePay.includes(payType.value)
   isWalletPay.value = walletPay.includes(payType.value)
   paySubmit() // 生成二维码内容
-  // emit('payTypeChange', value, balanceNotEnough)
 }
 // 1.支付方式
 const payType = ref('')
@@ -272,6 +270,7 @@ const walletPaySubmit = () => {
   paySubmit() // 使用点数
 }
 
+import { useUserStore } from '@/store/user'; const store = useUserStore()
 import Snackbar from '@/plugins/snackbar'
 import { useRoute } from 'vue-router'; const route = useRoute()
 import { useRouter } from 'vue-router'; const router = useRouter()
@@ -285,9 +284,13 @@ const payStatus = async () => {
       // 支付成功
       if (timer.value) clearInterval(timer.value); timer.value = null
       setTimeout(() => {
-        if (route.fullPath === props.returnUrl) router.go(0)
-        else if (props.returnUrl) router.push(props.returnUrl) // 返回指定页面
+        // 更新点数(充值、发布职位) 非点数支付时点充值
+        if (!showRecharge.value) updateAccountInfo()
+        // 支付成功
         emit('paySuccess', isWalletPay.value)
+        // 返回指定页面
+        if (route.fullPath === props.returnUrl) router.go(0)
+        else if (props.returnUrl) router.push(props.returnUrl)
         Snackbar.success('支付成功')
       }, 2000);
     }
@@ -296,16 +299,27 @@ const payStatus = async () => {
   }
 }
 
-const handleClose = () => {
+const handleRechargeClose = () => {
   showRecharge.value = false
+  loading.value = false
 }
 
-const handleFinish = () => {
+const RechargePaySuccess = () => {
   showRecharge.value = false
-  console.log(localStorage.getItem('enterpriseUserAccount'), '------')
-  balance.value = JSON.parse(localStorage.getItem('enterpriseUserAccount'))?.balance || 0
-  console.log(balance.value, 'balance.value')
+  updateAccountInfo()
+}
+
+const handleRecharge = () => {
+  showRecharge.value = true
+}
+
+const updateAccountInfo = async (init = false) => {
+  const account = await store.getEnterpriseUserAccountInfo()
+  accountBalance.value = account?.balance
+  if (init) return
+  loading.value = false
 }
+if ((props.appId - 0) !== 11) updateAccountInfo(true) // 充值前不查余额
 
 </script>
 <style lang="scss" scoped>

+ 1 - 0
src/store/user.js

@@ -155,6 +155,7 @@ export const useUserStore = defineStore('user',
         this.enterpriseUserAccount = data
         // this.getUserAccountBalance()
         localStorage.setItem('enterpriseUserAccount', JSON.stringify(data))
+        return data
       },
       // 获取用户账户信息
       async getUserAccountInfo () {

+ 1 - 1
src/views/login/components/passwordPage.vue

@@ -72,7 +72,7 @@ const loginData = reactive({
 // 设置默认账号密码便于开发快捷登录
 if (window.location.hostname === 'localhost' || window.location.hostname === '192.168.3.152') {
   loginData.phone = '13229740091'
-  loginData.password = '1111'
+  loginData.password = 'Citu123'
 }
 
 const passwordForm = ref()

+ 2 - 4
src/views/recruit/enterprise/memberCenter/myMembers/components/pointsAndBalance.vue

@@ -96,7 +96,7 @@ import Public from './public.vue'
 import { getEnterpriseRechargePackageList } from '@/api/recruit/enterprise/member/points'
 import { payCalculation } from '@/utils/position'
 
-const emits = defineEmits(['finish'])
+const emits = defineEmits(['paySuccess'])
 defineProps({
   showTitle: {
     type: Boolean,
@@ -146,11 +146,9 @@ const handleRecharge = (item) => {
 }
 
 // 支付成功
-import { useUserStore } from '@/store/user'; const store = useUserStore()
 const paySuccess = async () => {
   showConfirmPaymentDialog.value = false
-  await store.getEnterpriseUserAccountInfo()
-  emits('finish')
+  emits('paySuccess')
 }
 
 

+ 0 - 2
src/views/recruit/enterprise/positionManagement/components/item.vue

@@ -113,11 +113,9 @@ const toPay = (val) => {
   showConfirmPaymentDialog.value = true
 }
 // 支付成功
-import { useUserStore } from '@/store/user'; const store = useUserStore()
 const paySuccess = async () => {
   showConfirmPaymentDialog.value = false
   setTimeout(() => {
-    store.getEnterpriseUserAccountInfo()
     emit('refresh')
   }, 1000)
 }