zhengyiming
2025-02-21 9b87bcbcad94873dedee7389d1ef9742a8d72c2b
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
import {
  useLifeRechargeContext,
  LifePayRateListOutput,
  PhoneParValueOutput,
  PhoneParValueResponse,
} from '../utils';
import { useQuery } from '@tanstack/vue-query';
import { computed } from 'vue';
 
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,
  };
}