zhengyiming
5 天以前 eed2448d2e9d3dd2b1ec17d5c4ae74b102d793c5
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
import * as dictionaryServices from '@/services/api/Dictionary';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
 
export function useInsureProductSettingAllList() {
  const { data: allInsureProductSettingList, refetch } = useQuery({
    queryKey: ['dictionaryServices/getInsureProductSettingAllList'],
    queryFn: async () => {
      let res = await dictionaryServices.getInsureProductSettingAllList({}, { showLoading: false });
      return res;
    },
    placeholderData: () => [] as API.InsureProductSettingDto[],
  });
 
  return {
    allInsureProductSettingList,
    refetch,
  };
}
 
export function useUserInsureProductSetting() {
  const { data: allUserInsureProductSettingList, refetch } = useQuery({
    queryKey: ['dictionaryServices/getUserInsureProductSetting'],
    queryFn: async () => {
      let res = await dictionaryServices.getUserInsureProductSetting({ showLoading: false });
      return res;
    },
    placeholderData: () => [] as API.InsureProductSettingDto[],
  });
 
  function getInsureProductByIdNumber(productIdNumber: string) {
    return allUserInsureProductSettingList.value.find((x) => x.productIdNumber === productIdNumber);
  }
 
  function getInsureProductIdByIdNumber(productIdNumber: string) {
    const insureProduct = getInsureProductByIdNumber(productIdNumber);
    return insureProduct?.id ?? '';
  }
 
  return {
    allUserInsureProductSettingList,
    getInsureProductByIdNumber,
    getInsureProductIdByIdNumber,
    refetch,
  };
}
 
type UseInsureProductSchemeAllListOptions = {
  insureProductId?: MaybeRef<string>;
};
 
export function useInsureProductSchemeAllList(options: UseInsureProductSchemeAllListOptions = {}) {
  const { insureProductId } = options;
 
  const { data: allInsureProductSchemeList, refetch } = useQuery({
    queryKey: ['dictionaryServices/getInsureProductSchemeAllList', insureProductId],
    queryFn: async () => {
      let res = await dictionaryServices.getInsureProductSchemeAllList(
        {
          insureProductId: unref(insureProductId),
        },
        { showLoading: false }
      );
      return res;
    },
    placeholderData: () => [] as API.InsureProductSchemeDto[],
    enabled: computed(() => !!unref(insureProductId)),
    staleTime: Infinity,
  });
 
  return {
    allInsureProductSchemeList,
    refetch,
  };
}