zhengyiming
2025-03-27 538e4f454ba3126ef92278ab9cb675adb9e3b287
packages/components/src/views/PhoneBillRecharge/PhoneBillRechargeStep2.vue
@@ -60,6 +60,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">
@@ -67,7 +72,7 @@
          <div class="recharge-button-text">立即充值</div>
        </div>
      </nut-button>
      <RechargeTipsView :tips="tips" />
      <RechargeTipsView :lifePayOrderType="LifeRechargeConstants.LifePayOrderTypeEnum.话费订单" />
    </div>
    <ConfirmDialog v-model:visible="confirmDialogVisible" @ok="goPay">
      <template #info>
@@ -77,6 +82,7 @@
        <ConfirmDialogInfoItem label="实付金额" :content="`¥${realParValue}`" danger />
      </template>
    </ConfirmDialog>
    <NutToast :msg="state.msg" v-model:visible="state.show" type="warn" cover />
  </NutForm>
</template>
@@ -88,10 +94,11 @@
  Radio as NutRadio,
  Input as NutInput,
  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, provide } from 'vue';
import { FormValidator } from '../../utils';
import { reactive, ref, computed, toRef } from 'vue';
import { FormValidator, initLifePayType } from '../../utils';
import {
  useLifeRechargeContext,
  BlLifeRecharge,
@@ -102,20 +109,18 @@
import ConfirmDialog from '../../components/Dialog/ConfirmDialog.vue';
import ConfirmDialogInfoItem from '../../components/Dialog/ConfirmDialogInfoItem.vue';
import { useGetRate, useGetPhoneParValue, useSetUserAccountBySelect } from '../../hooks';
import { CustomerServiceTips } from '../../constants';
import AccountAddCard from '../../components/Card/AccountAddCard.vue';
import AccountCard from '../../components/Card/AccountCard.vue';
import { usePhoneBillRechargeContext, PhoneUserAccountExtraProperties } from './context';
import SelectPayTypeFormItem from '../../components/SelectPayTypeFormItem/SelectPayTypeFormItem.vue';
import { useSelectPayType, useGetPayStatusByOrderNo } from '../../hooks/selectPayType';
import { RechargeProps } from './types';
defineOptions({
  name: 'PhoneBillRechargeStep2',
});
type Props = {
  isDev?: boolean;
};
const props = withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<RechargeProps>(), {
  isDev: false,
});
@@ -128,6 +133,7 @@
  name: '',
  currentUserAccountId: '',
  remark: '',
  lifePayType: initLifePayType(props.isInWeChat, props.isInAlipay),
});
const { userAccountAllList, handleUserAccountChange } = useSetUserAccountBySelect({
@@ -153,6 +159,8 @@
const emit = defineEmits<{
  (e: 'goPay', orderNo: string): void;
  (e: 'paySuccess', orderNo: string): void;
  (e: 'missName', userAccountId: string): void;
}>();
const { lifePayPhoneRate } = useGetRate();
@@ -183,6 +191,7 @@
    { required: true, message: '请选择充值金额', validator: FormValidator.validatorNumberNotNull },
  ],
  currentUserAccountId: [{ required: true, message: '请选择充值手机号' }],
  lifePayType: [{ required: true, message: '请选择支付方式' }],
});
const formRef = ref<any>(null);
@@ -191,25 +200,29 @@
  if (!formRef.value) return;
  formRef.value.validate().then(({ valid, errors }: any) => {
    if (valid) {
      if (!form.name) {
        emit('missName', form.currentUserAccountId);
        return;
      }
      recharge();
    }
  });
}
const tips = [
  '平台提供慢充服务,订单提交后,话费将于0 - 24小时内到账。若未能按时到账,系统将自动发起退款。',
  '充值期间,若同一号码款项未到账,请勿在其他平台重复充值;主副卡不可同时充值。因上述操作导致的资金损失,由用户自行承担。',
  '本平台话费充值服务不适用于已停机号码。电信号码若有欠费,也无法完成充值。电信已完成维护的区域包括:广东、江苏、湖北、四川、江西、河北、河南、福建、辽宁。其它区域正在分批次进行维护中,在此期间可能会出现充值不成功并自动退款的情况,请您谅解。',
  '如接到陌生来电,对方以缴费或误操作等理由要求处理款项,务必立即拉黑,谨防诈骗。',
  '充值发票由运营商提供,您可登录网上营业厅下载电子发票。',
  CustomerServiceTips,
];
const confirmDialogVisible = ref(false);
function recharge() {
  confirmDialogVisible.value = true;
}
const { state, invokeAliPay, invokeWeixinPay } = useSelectPayType({
  getOpenId: toRef(props, 'getOpenId'),
  isInWeChat: toRef(props, 'isInWeChat'),
  isH5: toRef(props, 'isH5'),
  appId: toRef(props, 'appId'),
});
const currentOrderNo = ref('');
async function goPay() {
  try {
@@ -218,13 +231,33 @@
      channelId: blLifeRecharge.accountModel.channlesNum,
      productData: {
        ispCode: form.ispCode,
        parValue: props.isDev ? 0.1 : form.parValue,
        parValue: form.parValue,
        phone: form.phone,
        name: form.ispCode === BlLifeRecharge.constants.IspCode.dianxin ? form.name : '',
        name: form.name,
      },
    };
    let res = await blLifeRecharge.services.createLifePayPhoneOrder(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(
    () =>
      form.lifePayType === LifeRechargeConstants.LifePayTypeEnum.WxPay &&
      props.isFocus &&
      !!currentOrderNo.value
  ),
  onPaySuccess: (orderNo) => {
    emit('paySuccess', orderNo);
    currentOrderNo.value = '';
  },
});
</script>