From db365a5eff31c040c42463df4966bf34a5de6a6d Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期三, 12 三月 2025 15:00:42 +0800
Subject: [PATCH] fix: 二期需求
---
packages/components/src/hooks/index.ts | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 164 insertions(+), 6 deletions(-)
diff --git a/packages/components/src/hooks/index.ts b/packages/components/src/hooks/index.ts
index 687cb7c..912a1b6 100644
--- a/packages/components/src/hooks/index.ts
+++ b/packages/components/src/hooks/index.ts
@@ -5,8 +5,15 @@
PhoneParValueResponse,
QueryLifePayOrderListInput,
LifeRechargeConstants,
-} from '../utils';
-import { useQuery } from '@tanstack/vue-query';
+ ElectricParValueResponse,
+ ElectricSupportAreaResponse,
+ QueryUserAccountAllListInput,
+ UserAccountListOutput,
+ AddUpdateUserAccountInput,
+ GasParValueResponse,
+ GasParValueOutput,
+} 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';
@@ -26,20 +33,28 @@
() =>
lifePayRateList.value.find(
(x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿璇濊垂鎶樻墸
- )?.rate ?? 1
+ )?.rate ?? 100
);
const lifePayElectricRate = computed(
() =>
lifePayRateList.value.find(
(x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿鐢佃垂鎶樻墸
- )?.rate ?? 1
+ )?.rate ?? 100
+ );
+
+ const lifePayGasRate = computed(
+ () =>
+ lifePayRateList.value.find(
+ (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.榛樿鐕冩皵鎶樻墸
+ )?.rate ?? 100
);
return {
lifePayRateList,
lifePayPhoneRate,
lifePayElectricRate,
+ lifePayGasRate,
};
}
@@ -49,16 +64,35 @@
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),
});
return {
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,
};
}
@@ -106,3 +140,127 @@
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;
+};
+
+export function useSetUserAccountBySelect({
+ lifePayOrderType,
+ onSetUserAccount,
+}: UseSetUserAccountBySelectOptions) {
+ const { userAccountAllList } = useUserAccountAllList({
+ lifePayOrderType: lifePayOrderType,
+ onSuccess(data) {
+ if (data.length > 0) {
+ const currentUserAccount = data[0];
+ onSetUserAccount?.(currentUserAccount);
+ }
+ },
+ });
+
+ 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,
+ };
+}
--
Gitblit v1.9.1