zhengyiming
21 小时以前 5cd618c9523ad30dccf858a00ff6d99a28de4187
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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、燃气费为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,
  };
}