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/GasBillRecharge/GasBillRechargeStep3.vue | 115 ++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 73 insertions(+), 42 deletions(-)
diff --git a/packages/components/src/views/GasBillRecharge/GasBillRechargeStep3.vue b/packages/components/src/views/GasBillRecharge/GasBillRechargeStep3.vue
index cc6068c..8fc4f5d 100644
--- a/packages/components/src/views/GasBillRecharge/GasBillRechargeStep3.vue
+++ b/packages/components/src/views/GasBillRecharge/GasBillRechargeStep3.vue
@@ -21,7 +21,7 @@
<AccountCard
v-if="userAccountAllList.length > 0"
title="鍏呭�兼埛鍙�"
- :content="`${form.city} ${form.gasAccount}`"
+ :content="`${form.areaList?.[1] ?? ''} ${form.gasAccount}`"
:remark="form.remark"
>
<template #action>
@@ -31,19 +31,13 @@
<AccountAddCard text="鏂板鎴峰彿" v-else @click="handleAddUserAccount" />
</NutFormItem>
- <NutFormItem
- v-if="!!form.province"
- label="閫夋嫨鍏呭�奸噾棰�"
- class="bole-form-item"
- prop="parValue"
- required
- >
+ <NutFormItem label="閫夋嫨鍏呭�奸噾棰�" class="bole-form-item" prop="parValue" required>
<NutRadioGroup v-model="form.parValue" direction="horizontal" class="parValue-radio-group">
- <!-- <NutRadio
+ <NutRadio
:label="Number(item)"
:key="item"
shape="button"
- v-for="item in parValueList"
+ v-for="item in gasValueList"
class="parValue-item"
>
<div class="parValue-item-inner">
@@ -59,13 +53,18 @@
</div>
<div class="discountTag">{{ lifePayGasRate }}鎶�</div>
</div>
- </NutRadio> -->
+ </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">
- <!-- <div>锟{ realParValue }}</div> -->
+ <div>锟{ realParValue }}</div>
<div class="recharge-button-text">绔嬪嵆鍏呭��</div>
</div>
</nut-button>
@@ -82,7 +81,7 @@
<template #info>
<ConfirmDialogInfoItem
label="鐕冩皵绫诲瀷"
- :content="blLifeRecharge.constants.GasOrgCodeEnumText[form.gasOrgType]"
+ :content="currentGasParValueItem?.gasOrgName ?? ''"
/>
<ConfirmDialogInfoItem :label-width="96" label="鎴峰彿" :content="form.gasAccount" />
<ConfirmDialogInfoItem label="鍏呭�奸噾棰�" :content="`锟�${form.parValue.toFixed(2)}`" danger />
@@ -93,6 +92,7 @@
鍚屼竴鐕冩皵璐硅处鎴峰湪鍏呭�兼湡闂达紝鏈埌璐﹀墠鍒囧嬁鍦ㄥ叾浠栦换浣曞钩鍙板啀娆″厖鍊笺�傚洜姝ら�犳垚鐨勮祫閲戞崯澶遍』鐢ㄦ埛鑷鎵挎媴锛侊紒锛�
</template>
</ConfirmDialog>
+ <NutToast :msg="state.msg" v-model:visible="state.show" type="warn" cover />
</NutForm>
</template>
@@ -103,9 +103,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,
@@ -114,28 +115,28 @@
} from '@life-payment/core-vue';
import { useGetRate, useGetGasParValue, useSetUserAccountBySelect } from '../../hooks';
import { useGasBillRechargeContext, GasUserAccountExtraProperties } from './context';
-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 RechargeTipsView from '../../components/RechargeTipsView/RechargeTipsView.vue';
import ConfirmDialog from '../../components/Dialog/ConfirmDialog.vue';
import ConfirmDialogInfoItem from '../../components/Dialog/ConfirmDialogInfoItem.vue';
+import SelectPayTypeFormItem from '../../components/SelectPayTypeFormItem/SelectPayTypeFormItem.vue';
+import { useSelectPayType, useGetPayStatusByOrderNo } from '../../hooks/selectPayType';
+import { RechargeProps } from '../PhoneBillRecharge/types';
defineOptions({
name: 'GasBillRechargeStep3',
});
-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 } = useGasBillRechargeContext();
@@ -143,15 +144,18 @@
const { blLifeRecharge } = useLifeRechargeContext();
const { lifePayGasRate } = useGetRate();
+const { gasParValueList } = useGetGasParValue();
const form = reactive({
parValue: 0,
- province: '',
- city: '',
+ // province: '',
+ // city: '',
gasOrgType: '',
gasAccount: '',
currentUserAccountId: '',
remark: '',
+ areaList: [] as string[],
+ lifePayType: initLifePayType(props.isInWeChat, props.isInAlipay),
});
const { userAccountAllList, handleUserAccountChange } = useSetUserAccountBySelect({
@@ -160,30 +164,31 @@
const currentUserAccountExtraProperties = JSON.parse(
currentUserAccount.extraProperties
) as GasUserAccountExtraProperties;
- // form.currentUserAccountId = currentUserAccount.id;
- // form.electricAccount = currentUserAccount.content;
- // form.province = currentUserAccount.province;
- // form.city = currentUserAccount.city;
+ form.currentUserAccountId = currentUserAccount.id;
+ form.gasAccount = currentUserAccount.content;
+ form.areaList = [currentUserAccount.province, currentUserAccount.city];
+ form.gasOrgType = currentUserAccount.operators;
- // form.electricType = currentUserAccountExtraProperties.electricType;
- // form.electricAccountType = currentUserAccountExtraProperties.electricAccountType;
- // form.sixID = currentUserAccountExtraProperties.sixID;
- // form.remark = currentUserAccount.remark;
- // const electricParValueItem = electricParValueList.value.find(
- // (x) => x.cityName === form.province
- // );
- // if (
- // electricParValueItem &&
- // electricParValueItem.parValue.every((x) => Number(x) !== form.parValue)
- // ) {
- // form.parValue = 0;
- // }
+ form.remark = currentUserAccount.remark;
+ const gasParValueItem = gasParValueList.value.find((x) => x.gasOrgCode === form.gasOrgType);
+ if (gasParValueItem && gasParValueItem.parValue.every((x) => Number(x) !== form.parValue)) {
+ form.parValue = 0;
+ }
},
});
function handleAddUserAccount() {
goTo('step1');
}
+
+const currentGasParValueItem = computed(() =>
+ gasParValueList.value.find((x) => x.gasOrgCode === form.gasOrgType)
+);
+
+const gasValueList = computed(() => {
+ const gasValueList = currentGasParValueItem.value?.parValue ?? [];
+ return blLifeRecharge.filterParValueList(gasValueList);
+});
const realParValue = computed(() =>
blLifeRecharge.getRechargeParValue(form.parValue, lifePayGasRate.value)
@@ -195,6 +200,7 @@
{ required: true, message: '璇烽�夋嫨鍏呭�奸噾棰�', validator: FormValidator.validatorNumberNotNull },
],
currentUserAccountId: [{ required: true, message: '璇烽�夋嫨鍏呭�兼埛鍙�' }],
+ lifePayType: [{ required: true, message: '璇烽�夋嫨鏀粯鏂瑰紡' }],
});
const formRef = ref<any>(null);
@@ -225,20 +231,45 @@
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: LifeGasDataCreateLifePayOrderInput = {
userId: blLifeRecharge.accountModel.userId,
+ channelId: blLifeRecharge.accountModel.channlesNum,
productData: {
parValue: props.isDev ? 0.1 : form.parValue,
gasOrgType: form.gasOrgType,
gasAccount: form.gasAccount,
- province: form.province,
- city: form.city,
+ province: form.areaList?.[0] ?? '',
+ city: form.areaList?.[1] ?? '',
},
};
let res = await blLifeRecharge.services.createLifePayGasOrder(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