zhengyiming
21 小时以前 5cd618c9523ad30dccf858a00ff6d99a28de4187
packages/components/src/hooks/rate.ts
@@ -3,8 +3,8 @@
  QueryRateChannelInput,
  CreateEditRateChannelOutput,
} from '@life-payment/core-vue';
import { useQuery } from '@tanstack/vue-query';
import { MaybeRef, unref, computed } from 'vue';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import { MaybeRef, unref, computed, Ref } from 'vue';
type UseLifePayRateChannelAllListOptions = {
  params?: MaybeRef<QueryRateChannelInput>;
@@ -14,6 +14,8 @@
  const { params = {} } = options;
  const { blLifeRecharge } = useLifeRechargeContext();
  const queryClient = useQueryClient();
  const _params = computed(() => ({
    status: blLifeRecharge.constants.LifePayRateChannelStatus.Enabled,
@@ -30,7 +32,70 @@
    placeholderData: () => [] as CreateEditRateChannelOutput[],
  });
  function ensureLifePayRateChannelAllList() {
    return queryClient.ensureQueryData({
      queryKey: ['blLifeRecharge/getLifePayRateChannelAllList', _params],
    });
  }
  function getRateChannelByCode(code: string) {
    return allRateChannelList.value.find((item) => item.code === code);
  }
  return {
    allRateChannelList,
    ensureLifePayRateChannelAllList,
    getRateChannelByCode,
  };
}
type UseCheckCanRechargeOptions = {
  msg: Ref<string>;
  show: Ref<boolean>;
};
export function useCheckCanRecharge(options: UseCheckCanRechargeOptions) {
  const { msg, show } = options;
  const { blLifeRecharge } = useLifeRechargeContext();
  const { getRateChannelByCode, ensureLifePayRateChannelAllList } = useLifePayRateChannelAllList({
    params: {
      status: null,
    },
  });
  /**
   *
   * @param rateChannelCode
   * @description rateChannelCode值话费为IspCode、电费为electricType、燃气费为gasOrgType
   * @returns
   */
  function isCanRecharge(rateChannelCode: string) {
    const rateChannel = getRateChannelByCode(rateChannelCode);
    return rateChannel?.status === blLifeRecharge.constants.LifePayRateChannelStatus.Enabled;
  }
  /**
   *
   * @param rateChannelCode
   * @description rateChannelCode值话费为IspCode、电费为electricType、燃气费为gasOrgType
   * @returns
   */
  function checkCanRecharge(rateChannelCode: string) {
    const rateChannel = getRateChannelByCode(rateChannelCode);
    if (!isCanRecharge(rateChannelCode)) {
      //通道正在升级,给您带来不便尽情谅解
      msg.value = rateChannel?.remark ?? '';
      show.value = true;
      return false;
    }
    return true;
  }
  return {
    isCanRecharge,
    checkCanRecharge,
    ensureLifePayRateChannelAllList,
  };
}