From 5cd618c9523ad30dccf858a00ff6d99a28de4187 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期四, 11 九月 2025 10:24:35 +0800
Subject: [PATCH] feat: 公告

---
 packages/components/src/hooks/rate.ts |  101 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/packages/components/src/hooks/rate.ts b/packages/components/src/hooks/rate.ts
new file mode 100644
index 0000000..48b30b4
--- /dev/null
+++ b/packages/components/src/hooks/rate.ts
@@ -0,0 +1,101 @@
+import {
+  useLifeRechargeContext,
+  QueryRateChannelInput,
+  CreateEditRateChannelOutput,
+} from '@life-payment/core-vue';
+import { useQuery, useQueryClient } from '@tanstack/vue-query';
+import { MaybeRef, unref, computed, Ref } from 'vue';
+
+type UseLifePayRateChannelAllListOptions = {
+  params?: MaybeRef<QueryRateChannelInput>;
+};
+
+export function useLifePayRateChannelAllList(options: UseLifePayRateChannelAllListOptions = {}) {
+  const { params = {} } = options;
+
+  const { blLifeRecharge } = useLifeRechargeContext();
+
+  const queryClient = useQueryClient();
+
+  const _params = computed(() => ({
+    status: blLifeRecharge.constants.LifePayRateChannelStatus.Enabled,
+    ...unref(params),
+  }));
+
+  const { data: allRateChannelList } = useQuery({
+    queryKey: ['blLifeRecharge/getLifePayRateChannelAllList', _params],
+    queryFn: async () => {
+      return await blLifeRecharge.services.getLifePayRateChannelAllList(_params.value, {
+        showLoading: false,
+      });
+    },
+    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銆佺噧姘旇垂涓篻asOrgType
+   * @returns
+   */
+  function isCanRecharge(rateChannelCode: string) {
+    const rateChannel = getRateChannelByCode(rateChannelCode);
+    return rateChannel?.status === blLifeRecharge.constants.LifePayRateChannelStatus.Enabled;
+  }
+
+  /**
+   *
+   * @param rateChannelCode
+   * @description rateChannelCode鍊艰瘽璐逛负IspCode銆佺數璐逛负electricType銆佺噧姘旇垂涓篻asOrgType
+   * @returns
+   */
+  function checkCanRecharge(rateChannelCode: string) {
+    const rateChannel = getRateChannelByCode(rateChannelCode);
+    if (!isCanRecharge(rateChannelCode)) {
+      //閫氶亾姝e湪鍗囩骇锛岀粰鎮ㄥ甫鏉ヤ笉渚垮敖鎯呰皡瑙�
+      msg.value = rateChannel?.remark ?? '';
+      show.value = true;
+      return false;
+    }
+    return true;
+  }
+
+  return {
+    isCanRecharge,
+    checkCanRecharge,
+    ensureLifePayRateChannelAllList,
+  };
+}

--
Gitblit v1.9.1