zhengyiming
22 小时以前 6ac59f6fa91e51272b8cd4797458995e168ec0f9
packages/components/src/hooks/index.ts
@@ -18,17 +18,19 @@
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'],
    queryFn: async () => {
      return await blLifeRecharge.services.getRate({ showLoading: false });
    },
    placeholderData: () => [] as LifePayRateListOutput[],
  });
  // 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);
@@ -50,10 +52,15 @@
    if (hasChannel.value && channelRate.value.channlesRate) {
      return channelRate.value.channlesRate;
    }
    // return (
    //   lifePayRateList.value.find(
    //     (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认话费折扣
    //   )?.rate ?? 0
    // );
    return (
      lifePayRateList.value.find(
        (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认话费折扣
      )?.rate ?? 0
      allRateChannelList.value
        .filter((x) => x.lifePayOrderType == blLifeRecharge.constants.LifePayOrderTypeEnum.话费订单)
        .toSorted((a, b) => a.platformRate - b.platformRate)?.[0]?.platformRate ?? 0
    );
  });
@@ -61,10 +68,15 @@
    if (hasChannel.value && channelRate.value.channlesRate) {
      return channelRate.value.channlesRate;
    }
    // return (
    //   lifePayRateList.value.find(
    //     (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认电费折扣
    //   )?.rate ?? 0
    // );
    return (
      lifePayRateList.value.find(
        (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认电费折扣
      )?.rate ?? 0
      allRateChannelList.value
        .filter((x) => x.lifePayOrderType == blLifeRecharge.constants.LifePayOrderTypeEnum.电费订单)
        .toSorted((a, b) => a.platformRate - b.platformRate)?.[0]?.platformRate ?? 0
    );
  });
@@ -72,18 +84,24 @@
    if (hasChannel.value && channelRate.value.channlesRate) {
      return channelRate.value.channlesRate;
    }
    // return (
    //   lifePayRateList.value.find(
    //     (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认燃气折扣
    //   )?.rate ?? 0
    // );
    return (
      lifePayRateList.value.find(
        (x) => x.rateType === blLifeRecharge.constants.LifePayRateTypeEnum.默认燃气折扣
      )?.rate ?? 0
      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,
  };
}
@@ -263,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);
        }
      }
    },
  });