From f0857de728ef105e898bb02441feb7ef63df4c7a Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 01 十二月 2025 13:18:05 +0800
Subject: [PATCH] fix: s
---
packages/components/src/hooks/index.ts | 350 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 328 insertions(+), 22 deletions(-)
diff --git a/packages/components/src/hooks/index.ts b/packages/components/src/hooks/index.ts
index 8513ce7..8288b45 100644
--- a/packages/components/src/hooks/index.ts
+++ b/packages/components/src/hooks/index.ts
@@ -3,39 +3,105 @@
LifePayRateListOutput,
PhoneParValueOutput,
PhoneParValueResponse,
-} from '../utils';
-import { useQuery } from '@tanstack/vue-query';
-import { computed } from 'vue';
+ QueryLifePayOrderListInput,
+ LifeRechargeConstants,
+ ElectricParValueResponse,
+ ElectricSupportAreaResponse,
+ QueryUserAccountAllListInput,
+ UserAccountListOutput,
+ AddUpdateUserAccountInput,
+ GasParValueResponse,
+ 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 ?? 1
- );
+ 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 ?? 1
- );
+ 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(() => {
+ 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,
};
}
@@ -45,10 +111,10 @@
const { data: phoneParValueList, isLoading } = useQuery({
queryKey: ['blLifeRecharge/getPhoneParValue'],
queryFn: async () => {
- return await blLifeRecharge.services.getPhoneParValue({ showLoading: false });
+ return await blLifeRecharge.services.getPhoneParValue({}, { showLoading: false });
},
select(data) {
- return data.phoneParValue ?? [];
+ return data?.phoneParValue ?? [];
},
placeholderData: () => ({} as PhoneParValueResponse),
});
@@ -57,3 +123,243 @@
phoneParValueList,
};
}
+
+export function useGetElectricParValue() {
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ const { data: electricParValueList, isLoading } = useQuery({
+ queryKey: ['blLifeRecharge/getElectricSupportArea'],
+ queryFn: async () => {
+ return await blLifeRecharge.services.getElectricSupportArea({}, { showLoading: false });
+ },
+ select(data) {
+ return data.electricAreaList ?? [];
+ },
+ placeholderData: () => ({} as ElectricSupportAreaResponse),
+ });
+
+ return {
+ electricParValueList,
+ };
+}
+
+export type UseGetUserLifePayOrderPageOptions = {
+ lifePayOrderType?: MaybeRef<LifeRechargeConstants.LifePayOrderTypeEnum>;
+};
+
+export function useGetUserLifePayOrderPage(options: UseGetUserLifePayOrderPageOptions = {}) {
+ const { lifePayOrderType } = options;
+
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ // const queryState = reactive({
+ // lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum,
+ // });
+
+ const { infiniteLoadingProps } = useInfiniteLoading(
+ async ({ pageParam }) => {
+ let params: QueryLifePayOrderListInput = {
+ pageModel: {
+ rows: 20,
+ page: pageParam,
+ orderInput: [{ property: 'id', order: OrderInputType.Desc }],
+ },
+ lifePayOrderType: unref(lifePayOrderType),
+ userId: blLifeRecharge.accountModel.userId,
+ };
+
+ let res = await blLifeRecharge.services.getUserLifePayOrderPage(params, {
+ showLoading: false,
+ });
+ res.data = res.data.map((x) => ({
+ ...x,
+ frontStatus: convertOrderFrontStatus(
+ x.payStatus,
+ x.lifePayOrderStatus,
+ x.lifePayRefundStatus
+ ),
+ }));
+ return res;
+ },
+ {
+ queryKey: [
+ 'blLifeRecharge/getUserLifePayOrderPage',
+ {
+ lifePayOrderType,
+ userId: blLifeRecharge.accountModel.userId,
+ },
+ ],
+
+ select(data) {
+ console.log('data: ', data);
+ // data.pages.map((item) => item.data.map((x) => convertOrderFrontStatus(x)))
+ return data;
+ },
+ }
+ );
+
+ return {
+ infiniteLoadingProps,
+ };
+}
+
+type UseUserAccountAllListOptions = {
+ lifePayOrderType: MaybeRef<LifeRechargeConstants.LifePayOrderTypeEnum>;
+ onSuccess?: (data: UserAccountListOutput[]) => any;
+};
+
+export function useUserAccountAllList({
+ lifePayOrderType,
+ onSuccess,
+}: UseUserAccountAllListOptions) {
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ const { data: userAccountAllList, isLoading } = useQuery({
+ queryKey: [
+ 'blLifeRecharge/getUserAccountAllList',
+ blLifeRecharge.accountModel.userId,
+ lifePayOrderType,
+ ],
+ queryFn: async () => {
+ let params: QueryUserAccountAllListInput = {
+ userId: blLifeRecharge.accountModel.userId,
+ lifePayOrderType: unref(lifePayOrderType),
+ };
+ return await blLifeRecharge.services.getUserAccountAllList(params, { showLoading: false });
+ },
+ placeholderData: () => [] as UserAccountListOutput[],
+ onSuccess(data) {
+ onSuccess?.(data);
+ },
+ });
+
+ const queryClient = useQueryClient();
+
+ function invalidateQueries() {
+ return queryClient.invalidateQueries({
+ queryKey: [
+ 'blLifeRecharge/getUserAccountAllList',
+ blLifeRecharge.accountModel.userId,
+ lifePayOrderType,
+ ],
+ });
+ }
+
+ return {
+ userAccountAllList,
+ isLoading,
+ invalidateQueries,
+ };
+}
+
+export function useAddUpdateUserAccount() {
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ const queryClient = useQueryClient();
+
+ function invalidateQueries(lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum) {
+ return queryClient.invalidateQueries({
+ queryKey: [
+ 'blLifeRecharge/getUserAccountAllList',
+ blLifeRecharge.accountModel.userId,
+ lifePayOrderType,
+ ],
+ });
+ }
+
+ async function addUpdateUserAccount(params: AddUpdateUserAccountInput) {
+ let res = await blLifeRecharge.services.addUpdateUserAccount(params);
+ if (res) {
+ invalidateQueries(params.lifePayType);
+ }
+ return res;
+ }
+
+ return { addUpdateUserAccount };
+}
+
+type UseSetUserAccountBySelectOptions = {
+ lifePayOrderType: MaybeRef<LifeRechargeConstants.LifePayOrderTypeEnum>;
+ onSetUserAccount: (currentUserAccount: UserAccountListOutput) => any;
+ getDefaultUserAccount?: (
+ userAccountList: UserAccountListOutput[]
+ ) => Promise<UserAccountListOutput | undefined>;
+};
+
+export function useSetUserAccountBySelect({
+ lifePayOrderType,
+ onSetUserAccount,
+ getDefaultUserAccount = (data) => Promise.resolve(data[0]),
+}: UseSetUserAccountBySelectOptions) {
+ const { userAccountAllList } = useUserAccountAllList({
+ lifePayOrderType: lifePayOrderType,
+ async onSuccess(data) {
+ try {
+ if (data.length > 0) {
+ const currentUserAccount = await getDefaultUserAccount(data);
+ if (currentUserAccount) {
+ onSetUserAccount?.(currentUserAccount);
+ }
+ }
+ } catch (error) {}
+ },
+ });
+
+ function handleUserAccountChange(val: string) {
+ const currentUserAccount = userAccountAllList.value.find((x) => x.id === val);
+ onSetUserAccount?.(currentUserAccount);
+ }
+
+ return {
+ handleUserAccountChange,
+ userAccountAllList,
+ };
+}
+
+export function useGetGasParValue() {
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ const { data: gasParValueList, isLoading } = useQuery({
+ queryKey: ['blLifeRecharge/getGasParValue'],
+ queryFn: async () => {
+ return await blLifeRecharge.services.getGasParValue({}, { showLoading: false });
+ },
+ select(data) {
+ return data?.gasParValue ?? [];
+ },
+ placeholderData: () => ({} as GasParValueResponse),
+ });
+
+ return {
+ gasParValueList,
+ };
+}
+
+type UseIntroInfoOptions = {
+ lifePayOrderType: MaybeRef<LifeRechargeConstants.LifePayOrderTypeEnum>;
+ onSuccess?: (data: API.LifePayIntroInfoOutput[]) => any;
+};
+
+export function useIntroInfo({ lifePayOrderType, onSuccess }: UseIntroInfoOptions) {
+ const { blLifeRecharge } = useLifeRechargeContext();
+
+ const { data: introInfo } = useQuery({
+ queryKey: ['blLifeRecharge/getIntroInfo', lifePayOrderType],
+ queryFn: async () => {
+ return await blLifeRecharge.services.getIntroInfo(
+ {
+ type: unref(lifePayOrderType),
+ },
+ {
+ showLoading: false,
+ }
+ );
+ },
+ placeholderData: () => [] as API.LifePayIntroInfoOutput[],
+ onSuccess: (data) => {
+ onSuccess?.(data);
+ },
+ });
+
+ return { introInfo };
+}
--
Gitblit v1.9.1