zhengyiming
1 天以前 f6748abe2ad85f0600f905f22f92f53e603b885d
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
import * as insuranceClaimServices from '@/services/api/InsuranceClaim';
import * as insuranceOrderServices from '@/services/api/InsuranceOrder';
import { downloadFileByUrl, setOSSLink } from '@/utils';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
 
type UseInsuranceOrderMaterialListOptions = {
  insuranceOrderId: MaybeRef<string>;
};
 
export function useInsuranceOrderMaterialList({
  insuranceOrderId,
}: UseInsuranceOrderMaterialListOptions) {
  const { data: insuranceOrderMaterialList, refetch } = useQuery({
    queryKey: ['insuranceOrderServices/getInsuranceOrderMaterialList', insuranceOrderId],
    queryFn: async () => {
      let res = await insuranceOrderServices.getInsuranceOrderMaterialList(
        {
          id: unref(insuranceOrderId),
        },
        { showLoading: false }
      );
      return res;
    },
    placeholderData: () => [] as API.InsuranceOrderMaterialListOutput[],
    enabled: computed(() => !!unref(insuranceOrderId)),
  });
 
  return {
    insuranceOrderMaterialList,
    refetch,
  };
}
 
type UseInsurancePolicyPayOptions = {
  id: MaybeRef<string>;
};
 
export function useInsurancePolicyPay({ id }: UseInsurancePolicyPayOptions) {
  const { data: insurancePolicyPayList, isLoading } = useQuery({
    queryKey: ['insuranceOrderServices/getInsurancePolicyPay', id],
    queryFn: async () => {
      return await insuranceOrderServices.getInsurancePolicyPay({
        id: unref(id),
      });
    },
    placeholderData: () => [] as API.InsurancePolicyPayDto[],
  });
 
  return {
    insurancePolicyPayList,
    isLoading,
  };
}
 
export function useInsureActions() {
  const router = useRouter();
  async function handleGoDownloadInvoice(id: string) {
    try {
      await insuranceOrderServices.getInvoiceId({ id: id });
      router.push({
        name: 'InsureDownloadInvoice',
        params: {
          id: id,
        },
      });
    } catch (error) {}
  }
 
  async function handleGoStampFiles(id: string) {
    try {
      router.push({
        name: 'InsurancePolicyStampFiles',
        params: {
          id: id,
        },
      });
    } catch (error) {}
  }
 
  return {
    handleGoDownloadInvoice,
    handleGoStampFiles,
  };
}
 
export function useDownloadPolicyFileId() {
  async function handleDownload(row: API.InsurancePolicyPayDto) {
    try {
      if (row.policyOssUrl) {
        downloadFileByUrl(setOSSLink(row.policyOssUrl), `保单_${row.channelOrderNo}`);
      } else {
        let res = await insuranceOrderServices.downloadPolicyFileId({ id: row.id });
        if (res) {
          window.open(res, '_blank');
        }
      }
    } catch (error) {}
  }
 
  return {
    handleDownload,
  };
}