zhengyiming
4 天以前 babd7a49ba48c83334bbe9a4c992d784e062f6e3
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
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 ?? '';
  }
 
  const queryClient = useQueryClient();
 
  function ensureUserInsureProductSetting() {
    return queryClient.ensureQueryData<API.InsureProductSettingDto[]>({
      queryKey: ['dictionaryServices/getUserInsureProductSetting'],
    });
  }
 
  /**是否是生煎保账号 */
  const isSjbAccount = computed(() => allUserInsureProductSettingList.value.length > 0);
 
  return {
    allUserInsureProductSettingList,
    getInsureProductByIdNumber,
    getInsureProductIdByIdNumber,
    refetch,
    ensureUserInsureProductSetting,
    isSjbAccount,
  };
}
 
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,
  });
 
  function getInsureProductSchemeByCode(code: string) {
    return allInsureProductSchemeList.value.find((x) => x.code === code);
  }
 
  return {
    allInsureProductSchemeList,
    refetch,
    getInsureProductSchemeByCode,
  };
}