| | |
| | | QueryRateChannelInput, |
| | | CreateEditRateChannelOutput, |
| | | } from '@life-payment/core-vue'; |
| | | import { useQuery } from '@tanstack/vue-query'; |
| | | import { MaybeRef, unref, computed } from 'vue'; |
| | | import { useQuery, useQueryClient } from '@tanstack/vue-query'; |
| | | import { MaybeRef, unref, computed, Ref } from 'vue'; |
| | | |
| | | type UseLifePayRateChannelAllListOptions = { |
| | | params?: MaybeRef<QueryRateChannelInput>; |
| | |
| | | const { params = {} } = options; |
| | | |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | | |
| | | const queryClient = useQueryClient(); |
| | | |
| | | const _params = computed(() => ({ |
| | | status: blLifeRecharge.constants.LifePayRateChannelStatus.Enabled, |
| | |
| | | placeholderData: () => [] as CreateEditRateChannelOutput[], |
| | | }); |
| | | |
| | | function ensureLifePayRateChannelAllList() { |
| | | return queryClient.ensureQueryData({ |
| | | queryKey: ['blLifeRecharge/getLifePayRateChannelAllList', _params], |
| | | }); |
| | | } |
| | | |
| | | function getRateChannelByCode(code: string) { |
| | | return allRateChannelList.value.find((item) => item.code === code); |
| | | } |
| | | |
| | | return { |
| | | allRateChannelList, |
| | | ensureLifePayRateChannelAllList, |
| | | getRateChannelByCode, |
| | | }; |
| | | } |
| | | |
| | | type UseCheckCanRechargeOptions = { |
| | | msg: Ref<string>; |
| | | show: Ref<boolean>; |
| | | }; |
| | | |
| | | export function useCheckCanRecharge(options: UseCheckCanRechargeOptions) { |
| | | const { msg, show } = options; |
| | | |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | | |
| | | const { getRateChannelByCode, ensureLifePayRateChannelAllList } = useLifePayRateChannelAllList({ |
| | | params: { |
| | | status: null, |
| | | }, |
| | | }); |
| | | |
| | | /** |
| | | * |
| | | * @param rateChannelCode |
| | | * @description rateChannelCode值话费为IspCode、电费为electricType、燃气费为gasOrgType |
| | | * @returns |
| | | */ |
| | | function isCanRecharge(rateChannelCode: string) { |
| | | const rateChannel = getRateChannelByCode(rateChannelCode); |
| | | return rateChannel?.status === blLifeRecharge.constants.LifePayRateChannelStatus.Enabled; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param rateChannelCode |
| | | * @description rateChannelCode值话费为IspCode、电费为electricType、燃气费为gasOrgType |
| | | * @returns |
| | | */ |
| | | function checkCanRecharge(rateChannelCode: string) { |
| | | const rateChannel = getRateChannelByCode(rateChannelCode); |
| | | if (!isCanRecharge(rateChannelCode)) { |
| | | //通道正在升级,给您带来不便尽情谅解 |
| | | msg.value = rateChannel?.remark ?? ''; |
| | | show.value = true; |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | return { |
| | | isCanRecharge, |
| | | checkCanRecharge, |
| | | ensureLifePayRateChannelAllList, |
| | | }; |
| | | } |