From 8434c4b22d915ed796f7662cb10817b8e33c47c6 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 17 三月 2025 16:26:37 +0800
Subject: [PATCH] fix: 修改支付方式选择
---
packages/components/src/views/electricBillRecharge/ElectricBillRechargeStep2.vue | 50 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/packages/components/src/views/electricBillRecharge/ElectricBillRechargeStep2.vue b/packages/components/src/views/electricBillRecharge/ElectricBillRechargeStep2.vue
index 1bc4f9c..5984a9f 100644
--- a/packages/components/src/views/electricBillRecharge/ElectricBillRechargeStep2.vue
+++ b/packages/components/src/views/electricBillRecharge/ElectricBillRechargeStep2.vue
@@ -62,6 +62,11 @@
</NutRadio>
</NutRadioGroup>
</NutFormItem>
+ <SelectPayTypeFormItem
+ v-model="form.lifePayType"
+ :showWeixinPay="showWeixinPay"
+ :showAliPay="showAliPay"
+ ></SelectPayTypeFormItem>
<div class="common-content">
<nut-button class="recharge-button" type="primary" @click="handleSubmit">
<div class="recharge-button-inner">
@@ -89,6 +94,7 @@
鍚屼竴鐢佃垂璐︽埛鍦ㄥ厖鍊兼湡闂达紝鏈埌璐﹀墠鍒囧嬁鍦ㄥ叾浠栦换浣曞钩鍙板啀娆″厖鍊笺�傚洜姝ら�犳垚鐨勮祫閲戞崯澶遍』鐢ㄦ埛鑷鎵挎媴锛侊紒锛�
</template>
</ConfirmDialog>
+ <NutToast :msg="state.msg" v-model:visible="state.show" type="warn" cover />
</NutForm>
</template>
@@ -99,9 +105,10 @@
RadioGroup as NutRadioGroup,
Radio as NutRadio,
Button as NutButton,
+ Toast as NutToast,
} from '@nutui/nutui-taro';
import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types';
-import { reactive, ref, computed } from 'vue';
+import { reactive, ref, computed, toRef } from 'vue';
import {
useLifeRechargeContext,
LifeElectricDataCreateLifePayOrderInput,
@@ -112,26 +119,26 @@
import ConfirmDialog from '../../components/Dialog/ConfirmDialog.vue';
import ConfirmDialogInfoItem from '../../components/Dialog/ConfirmDialogInfoItem.vue';
import { useGetRate, useGetElectricParValue, useSetUserAccountBySelect } from '../../hooks';
-import { FormValidator } from '../../utils';
+import { FormValidator, initLifePayType } from '../../utils';
import { CustomerServiceTips } from '../../constants';
import AccountAddCard from '../../components/Card/AccountAddCard.vue';
import AccountCard from '../../components/Card/AccountCard.vue';
import { useElectricBillRechargeContext, ElectricUserAccountExtraProperties } from './context';
+import SelectPayTypeFormItem from '../../components/SelectPayTypeFormItem/SelectPayTypeFormItem.vue';
+import { useSelectPayType, useGetPayStatusByOrderNo } from '../../hooks/selectPayType';
+import { RechargeProps } from '../PhoneBillRecharge/types';
defineOptions({
name: 'ElectricBillRechargeStep2',
});
-type Props = {
- isDev?: boolean;
-};
-
-const props = withDefaults(defineProps<Props>(), {
+const props = withDefaults(defineProps<RechargeProps>(), {
isDev: false,
});
const emit = defineEmits<{
(e: 'goPay', orderNo: string): void;
+ (e: 'paySuccess', orderNo: string): void;
}>();
const { goTo } = useElectricBillRechargeContext();
@@ -146,6 +153,7 @@
sixID: '',
currentUserAccountId: '',
remark: '',
+ lifePayType: initLifePayType(props.isInWeChat, props.isInAlipay),
});
const { userAccountAllList, handleUserAccountChange } = useSetUserAccountBySelect({
@@ -200,6 +208,7 @@
{ required: true, message: '璇烽�夋嫨鍏呭�奸噾棰�', validator: FormValidator.validatorNumberNotNull },
],
currentUserAccountId: [{ required: true, message: '璇烽�夋嫨鍏呭�兼埛鍙�' }],
+ lifePayType: [{ required: true, message: '璇烽�夋嫨鏀粯鏂瑰紡' }],
});
const formRef = ref<any>(null);
@@ -228,10 +237,20 @@
confirmDialogVisible.value = true;
}
+const { state, invokeAliPay, invokeWeixinPay } = useSelectPayType({
+ openId: toRef(props, 'openId'),
+ isInWeChat: toRef(props, 'isInWeChat'),
+ isH5: toRef(props, 'isH5'),
+ appId: toRef(props, 'appId'),
+});
+
+const currentOrderNo = ref('');
+
async function goPay() {
try {
let params: LifeElectricDataCreateLifePayOrderInput = {
userId: blLifeRecharge.accountModel.userId,
+ channelId: blLifeRecharge.accountModel.channlesNum,
productData: {
parValue: props.isDev ? 0.1 : form.parValue,
electricType: form.electricType,
@@ -243,7 +262,22 @@
},
};
let res = await blLifeRecharge.services.createLifePayElectricOrder(params);
- emit('goPay', res.orderNo);
+ // emit('goPay', res.orderNo);
+ if (form.lifePayType === LifeRechargeConstants.LifePayTypeEnum.WxPay) {
+ await invokeWeixinPay(res.orderNo);
+ } else {
+ await invokeAliPay(res.orderNo);
+ }
+ currentOrderNo.value = res.orderNo;
} catch (error) {}
}
+
+useGetPayStatusByOrderNo({
+ orderNo: currentOrderNo,
+ enabled: computed(() => props.isFocus && !!currentOrderNo.value),
+ onPaySuccess: (orderNo) => {
+ emit('paySuccess', orderNo);
+ currentOrderNo.value = '';
+ },
+});
</script>
--
Gitblit v1.9.1