zhengyiming
2025-02-26 57857a130a6a0e32c7898477f5407286d13ffe15
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import {
  useLifeRechargeContext,
  LifePayRateListOutput,
  PhoneParValueOutput,
  PhoneParValueResponse,
  QueryLifePayOrderListInput,
  LifeRechargeConstants,
  ElectricParValueResponse,
  ElectricSupportAreaResponse,
} from '@life-payment/core-vue';
import { useQuery } from '@tanstack/vue-query';
import { computed, MaybeRef, reactive, unref } from 'vue';
import { useInfiniteLoading } from './infiniteLoading';
import { OrderInputType } from '../constants';
 
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,
  };
}
 
export function useGetElectricParValue() {
  const { blLifeRecharge } = useLifeRechargeContext();
 
  const { data: electricParValueList, isLoading } = useQuery({
    queryKey: ['blLifeRecharge/getElectricSupportArea'],
    queryFn: async () => {
      return await blLifeRecharge.services.getElectricSupportArea({ showLoading: false });
    },
    select(data) {
      return data.electricAreaList ?? [];
    },
    placeholderData: () => ({} as ElectricSupportAreaResponse),
  });
 
  return {
    electricParValueList,
  };
}
 
export type UseGetUserLifePayOrderPageOptions = {
  lifePayOrderType?: MaybeRef<LifeRechargeConstants.LifePayOrderTypeEnum>;
};
 
export function useGetUserLifePayOrderPage(options: UseGetUserLifePayOrderPageOptions = {}) {
  const { lifePayOrderType } = options;
 
  const { blLifeRecharge } = useLifeRechargeContext();
 
  // const queryState = reactive({
  //   lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum,
  // });
 
  const { infiniteLoadingProps } = useInfiniteLoading(
    ({ pageParam }) => {
      let params: QueryLifePayOrderListInput = {
        pageModel: {
          rows: 20,
          page: pageParam,
          orderInput: [{ property: 'id', order: OrderInputType.Desc }],
        },
        lifePayOrderType: unref(lifePayOrderType),
        userId: blLifeRecharge.accountModel.userId,
      };
 
      return blLifeRecharge.services.getUserLifePayOrderPage(params, {
        showLoading: false,
      });
    },
    {
      queryKey: [
        'blLifeRecharge/getUserLifePayOrderPage',
        {
          lifePayOrderType,
          userId: blLifeRecharge.accountModel.userId,
        },
      ],
    }
  );
 
  return {
    infiniteLoadingProps,
  };
}