| | |
| | | <template> |
| | | <div class="select-pay-type-view"> |
| | | <div class="select-pay-type-view-item"> |
| | | <div class="select-pay-type-view-item" v-if="showAliPay" @click="handleAliPay"> |
| | | <img class="select-pay-type-view-item-icon" :src="IconAliPay" /> |
| | | <div class="select-pay-type-view-item-text">支付宝支付</div> |
| | | </div> |
| | | <div class="select-pay-type-view-item"> |
| | | <div class="select-pay-type-view-item" v-if="showWeixinPay" @click="handleWeixinPay"> |
| | | <img class="select-pay-type-view-item-icon" :src="IconWeixin" /> |
| | | <div class="select-pay-type-view-item-text">微信支付</div> |
| | | </div> |
| | | <NutToast :msg="state.msg" v-model:visible="state.show" type="warn" cover /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import IconWeixin from '../../../assets/icon-weixin-pay.png'; |
| | | import IconAliPay from '../../../assets/icon-alipay.png'; |
| | | import IconWeixin from '../../assets/icon-weixin-pay.png'; |
| | | import IconAliPay from '../../assets/icon-alipay.png'; |
| | | import { LifeRechargeConstants } from '@life-payment/core-vue'; |
| | | import { Toast as NutToast } from '@nutui/nutui-taro'; |
| | | import { computed, toRef } from 'vue'; |
| | | import { useSelectPayType, useGetPayStatusByOrderNo } from '../../hooks/selectPayType'; |
| | | |
| | | defineOptions({ |
| | | name: 'SelectPayTypeView', |
| | | }); |
| | | |
| | | // type Props = {}; |
| | | type Props = { |
| | | orderNo?: string; |
| | | lifePayOrderType?: LifeRechargeConstants.LifePayOrderTypeEnum; |
| | | showAliPay?: boolean; |
| | | showWeixinPay?: boolean; |
| | | isInWeChat?: boolean; |
| | | isH5?: boolean; |
| | | appId?: string; |
| | | isFocus?: boolean; |
| | | getOpenId?: () => Promise<string>; |
| | | }; |
| | | |
| | | // const props = withDefaults(defineProps<Props>(), {}); |
| | | const props = withDefaults(defineProps<Props>(), { |
| | | showAliPay: true, |
| | | showWeixinPay: true, |
| | | }); |
| | | |
| | | const emit = defineEmits<{ |
| | | ( |
| | | e: 'paySuccess', |
| | | orderNo: string, |
| | | lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum |
| | | ): void; |
| | | (e: 'payOrderForJsAPISuccess'): void; |
| | | }>(); |
| | | |
| | | const { state, invokeAliPay, invokeWeixinPay } = useSelectPayType({ |
| | | getOpenId: toRef(props, 'getOpenId'), |
| | | isInWeChat: toRef(props, 'isInWeChat'), |
| | | isH5: toRef(props, 'isH5'), |
| | | appId: toRef(props, 'appId'), |
| | | }); |
| | | |
| | | async function handleAliPay() { |
| | | try { |
| | | await invokeAliPay(props.orderNo); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function handleWeixinPay() { |
| | | try { |
| | | await invokeWeixinPay(props.orderNo); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | useGetPayStatusByOrderNo({ |
| | | orderNo: toRef(props, 'orderNo'), |
| | | enabled: computed(() => props.isFocus), |
| | | onPaySuccess() { |
| | | emit('paySuccess', props.orderNo, props.lifePayOrderType); |
| | | }, |
| | | }); |
| | | </script> |