| | |
| | | LifeRechargeConstants, |
| | | ElectricParValueResponse, |
| | | ElectricSupportAreaResponse, |
| | | QueryUserAccountAllListInput, |
| | | UserAccountListOutput, |
| | | AddUpdateUserAccountInput, |
| | | GasParValueResponse, |
| | | GasParValueOutput, |
| | | } from '@life-payment/core-vue'; |
| | | import { useQuery } from '@tanstack/vue-query'; |
| | | 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'; |
| | | |
| | | export function useGetRate() { |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | |
| | | () => |
| | | 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, |
| | | }; |
| | | } |
| | | |
| | |
| | | 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), |
| | | }); |
| | |
| | | const { data: electricParValueList, isLoading } = useQuery({ |
| | | queryKey: ['blLifeRecharge/getElectricSupportArea'], |
| | | queryFn: async () => { |
| | | return await blLifeRecharge.services.getElectricSupportArea({ showLoading: false }); |
| | | return await blLifeRecharge.services.getElectricSupportArea({}, { showLoading: false }); |
| | | }, |
| | | select(data) { |
| | | return data.electricAreaList ?? []; |
| | |
| | | // }); |
| | | |
| | | const { infiniteLoadingProps } = useInfiniteLoading( |
| | | ({ pageParam }) => { |
| | | async ({ pageParam }) => { |
| | | let params: QueryLifePayOrderListInput = { |
| | | pageModel: { |
| | | rows: 20, |
| | |
| | | userId: blLifeRecharge.accountModel.userId, |
| | | }; |
| | | |
| | | return blLifeRecharge.services.getUserLifePayOrderPage(params, { |
| | | 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: [ |
| | |
| | | userId: blLifeRecharge.accountModel.userId, |
| | | }, |
| | | ], |
| | | |
| | | select(data) { |
| | | console.log('data: ', data); |
| | | // data.pages.map((item) => item.data.map((x) => convertOrderFrontStatus(x))) |
| | | return data; |
| | | }, |
| | | } |
| | | ); |
| | | |
| | |
| | | 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, |
| | | }; |
| | | } |
| | | |
| | | 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 }; |
| | | } |