From 5cd618c9523ad30dccf858a00ff6d99a28de4187 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期四, 11 九月 2025 10:24:35 +0800 Subject: [PATCH] feat: 公告 --- packages/components/src/hooks/rate.ts | 69 +++++++++++++++++++++++++++++++++- 1 files changed, 67 insertions(+), 2 deletions(-) diff --git a/packages/components/src/hooks/rate.ts b/packages/components/src/hooks/rate.ts index 5db3d7c..48b30b4 100644 --- a/packages/components/src/hooks/rate.ts +++ b/packages/components/src/hooks/rate.ts @@ -3,8 +3,8 @@ 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>; @@ -14,6 +14,8 @@ const { params = {} } = options; const { blLifeRecharge } = useLifeRechargeContext(); + + const queryClient = useQueryClient(); const _params = computed(() => ({ status: blLifeRecharge.constants.LifePayRateChannelStatus.Enabled, @@ -30,7 +32,70 @@ 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銆佺噧姘旇垂涓篻asOrgType + * @returns + */ + function isCanRecharge(rateChannelCode: string) { + const rateChannel = getRateChannelByCode(rateChannelCode); + return rateChannel?.status === blLifeRecharge.constants.LifePayRateChannelStatus.Enabled; + } + + /** + * + * @param rateChannelCode + * @description rateChannelCode鍊艰瘽璐逛负IspCode銆佺數璐逛负electricType銆佺噧姘旇垂涓篻asOrgType + * @returns + */ + function checkCanRecharge(rateChannelCode: string) { + const rateChannel = getRateChannelByCode(rateChannelCode); + if (!isCanRecharge(rateChannelCode)) { + //閫氶亾姝e湪鍗囩骇锛岀粰鎮ㄥ甫鏉ヤ笉渚垮敖鎯呰皡瑙� + msg.value = rateChannel?.remark ?? ''; + show.value = true; + return false; + } + return true; + } + + return { + isCanRecharge, + checkCanRecharge, + ensureLifePayRateChannelAllList, }; } -- Gitblit v1.9.1