From 6ac59f6fa91e51272b8cd4797458995e168ec0f9 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期四, 11 九月 2025 09:13:08 +0800 Subject: [PATCH] feat: 公告 --- packages/components/src/hooks/index.ts | 104 +++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 78 insertions(+), 26 deletions(-) diff --git a/packages/components/src/hooks/index.ts b/packages/components/src/hooks/index.ts index d8ff400..624ec3d 100644 --- a/packages/components/src/hooks/index.ts +++ b/packages/components/src/hooks/index.ts @@ -11,51 +11,97 @@ UserAccountListOutput, AddUpdateUserAccountInput, GasParValueResponse, - GasParValueOutput, + ChannelRateOutput, } from '@life-payment/core-vue'; import { useQuery, useQueryClient } from '@tanstack/vue-query'; import { computed, MaybeRef, reactive, unref } from 'vue'; import { useInfiniteLoading } from './infiniteLoading'; import { OrderInputType } from '../constants'; import { convertOrderFrontStatus } from '../utils'; +import { useLifePayRateChannelAllList } from './rate'; export function useGetRate() { const { blLifeRecharge } = useLifeRechargeContext(); - const { data: lifePayRateList, isLoading } = useQuery({ - queryKey: ['blLifeRecharge/getRate'], + // const { data: lifePayRateList, isLoading } = useQuery({ + // queryKey: ['blLifeRecharge/getRate'], + // queryFn: async () => { + // return await blLifeRecharge.services.getRate({ showLoading: false }); + // }, + // placeholderData: () => [] as LifePayRateListOutput[], + // }); + const { allRateChannelList } = useLifePayRateChannelAllList(); + + const hasChannel = computed(() => !!blLifeRecharge.accountModel.channlesNum); + + const { data: channelRate } = useQuery({ + queryKey: ['blLifeRecharge/getChannelRate', blLifeRecharge.accountModel.channlesNum], queryFn: async () => { - return await blLifeRecharge.services.getRate({ showLoading: false }); + return await blLifeRecharge.services.getChannelRate( + { + checkChannelId: blLifeRecharge.accountModel.channlesNum, + }, + { showLoading: false } + ); }, - placeholderData: () => [] as LifePayRateListOutput[], + placeholderData: () => ({} as ChannelRateOutput), + enabled: hasChannel, }); - const lifePayPhoneRate = computed( - () => - lifePayRateList.value.find( - (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿璇濊垂鎶樻墸 - )?.rate ?? 100 - ); + const lifePayPhoneRate = computed(() => { + if (hasChannel.value && channelRate.value.channlesRate) { + return channelRate.value.channlesRate; + } + // return ( + // lifePayRateList.value.find( + // (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿璇濊垂鎶樻墸 + // )?.rate ?? 0 + // ); + return ( + allRateChannelList.value + .filter((x) => x.lifePayOrderType == blLifeRecharge.constants.LifePayOrderTypeEnum.璇濊垂璁㈠崟) + .toSorted((a, b) => a.platformRate - b.platformRate)?.[0]?.platformRate ?? 0 + ); + }); - const lifePayElectricRate = computed( - () => - lifePayRateList.value.find( - (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿鐢佃垂鎶樻墸 - )?.rate ?? 100 - ); + const lifePayElectricRate = computed(() => { + if (hasChannel.value && channelRate.value.channlesRate) { + return channelRate.value.channlesRate; + } + // return ( + // lifePayRateList.value.find( + // (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿鐢佃垂鎶樻墸 + // )?.rate ?? 0 + // ); + return ( + allRateChannelList.value + .filter((x) => x.lifePayOrderType == blLifeRecharge.constants.LifePayOrderTypeEnum.鐢佃垂璁㈠崟) + .toSorted((a, b) => a.platformRate - b.platformRate)?.[0]?.platformRate ?? 0 + ); + }); - const lifePayGasRate = computed( - () => - lifePayRateList.value.find( - (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿鐕冩皵鎶樻墸 - )?.rate ?? 100 - ); + const lifePayGasRate = computed(() => { + if (hasChannel.value && channelRate.value.channlesRate) { + return channelRate.value.channlesRate; + } + // return ( + // lifePayRateList.value.find( + // (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿鐕冩皵鎶樻墸 + // )?.rate ?? 0 + // ); + return ( + allRateChannelList.value + .filter((x) => x.lifePayOrderType == blLifeRecharge.constants.LifePayOrderTypeEnum.鐕冩皵璁㈠崟) + .toSorted((a, b) => a.platformRate - b.platformRate)?.[0]?.platformRate ?? 0 + ); + }); return { - lifePayRateList, + // lifePayRateList, lifePayPhoneRate, lifePayElectricRate, lifePayGasRate, + allRateChannelList, }; } @@ -235,18 +281,24 @@ type UseSetUserAccountBySelectOptions = { lifePayOrderType: MaybeRef<LifeRechargeConstants.LifePayOrderTypeEnum>; onSetUserAccount: (currentUserAccount: UserAccountListOutput) => any; + getDefaultUserAccount?: ( + userAccountList: UserAccountListOutput[] + ) => UserAccountListOutput | undefined; }; export function useSetUserAccountBySelect({ lifePayOrderType, onSetUserAccount, + getDefaultUserAccount = (data) => data[0], }: UseSetUserAccountBySelectOptions) { const { userAccountAllList } = useUserAccountAllList({ lifePayOrderType: lifePayOrderType, onSuccess(data) { if (data.length > 0) { - const currentUserAccount = data[0]; - onSetUserAccount?.(currentUserAccount); + const currentUserAccount = getDefaultUserAccount(data); + if (currentUserAccount) { + onSetUserAccount?.(currentUserAccount); + } } }, }); -- Gitblit v1.9.1