import {
|
useLifeRechargeContext,
|
LifePayRateListOutput,
|
PhoneParValueOutput,
|
PhoneParValueResponse,
|
QueryLifePayOrderListInput,
|
LifeRechargeConstants,
|
} from '../utils';
|
import { useQuery } from '@tanstack/vue-query';
|
import { computed, MaybeRef, reactive, unref } from 'vue';
|
import { useInfiniteLoading } from './infiniteLoading';
|
import { OrderInputType } from '../constants';
|
|
export function useGetRate() {
|
const { blLifeRecharge } = useLifeRechargeContext();
|
|
const { data: lifePayRateList, isLoading } = useQuery({
|
queryKey: ['blLifeRecharge/getRate'],
|
queryFn: async () => {
|
return await blLifeRecharge.services.getRate({ showLoading: false });
|
},
|
placeholderData: () => [] as LifePayRateListOutput[],
|
});
|
|
const lifePayPhoneRate = computed(
|
() =>
|
lifePayRateList.value.find(
|
(x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认话费折扣
|
)?.rate ?? 1
|
);
|
|
const lifePayElectricRate = computed(
|
() =>
|
lifePayRateList.value.find(
|
(x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认电费折扣
|
)?.rate ?? 1
|
);
|
|
return {
|
lifePayRateList,
|
lifePayPhoneRate,
|
lifePayElectricRate,
|
};
|
}
|
|
export function useGetPhoneParValue() {
|
const { blLifeRecharge } = useLifeRechargeContext();
|
|
const { data: phoneParValueList, isLoading } = useQuery({
|
queryKey: ['blLifeRecharge/getPhoneParValue'],
|
queryFn: async () => {
|
return await blLifeRecharge.services.getPhoneParValue({ showLoading: false });
|
},
|
select(data) {
|
return data.phoneParValue ?? [];
|
},
|
placeholderData: () => ({} as PhoneParValueResponse),
|
});
|
|
return {
|
phoneParValueList,
|
};
|
}
|
|
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(
|
({ pageParam }) => {
|
let params: QueryLifePayOrderListInput = {
|
pageModel: {
|
rows: 20,
|
page: pageParam,
|
orderInput: [{ property: 'id', order: OrderInputType.Desc }],
|
},
|
lifePayOrderType: unref(lifePayOrderType),
|
userId: blLifeRecharge.accountModel.userId,
|
};
|
|
return blLifeRecharge.services.getUserLifePayOrderPage(params, {
|
showLoading: false,
|
});
|
},
|
{
|
queryKey: [
|
'blLifeRecharge/getUserLifePayOrderPage',
|
{
|
lifePayOrderType,
|
userId: blLifeRecharge.accountModel.userId,
|
},
|
],
|
}
|
);
|
|
return {
|
infiniteLoadingProps,
|
};
|
}
|