|  |  |  | 
|---|
|  |  |  | import * as electronSignServices from '@/services/api/electronSign'; | 
|---|
|  |  |  | import AddOrEditTemplateDialog from './components/AddOrEditTemplateDialog.vue'; | 
|---|
|  |  |  | import { downloadFileByUrl, Message } from '@bole-core/core'; | 
|---|
|  |  |  | import { convertApi2FormUrlOnlyOne, format, setOSSLink } from '@/utils'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | convertApi2FormUrlOnlyOne, | 
|---|
|  |  |  | convertPdfToImage, | 
|---|
|  |  |  | format, | 
|---|
|  |  |  | openLink, | 
|---|
|  |  |  | setOSSLink, | 
|---|
|  |  |  | } from '@/utils'; | 
|---|
|  |  |  | import { EnumContractTemplateStatus, EnumContractTemplateStatusText } from '@/constants'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | defineOptions({ | 
|---|
|  |  |  | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const operationBtnMap: Record<string, OperationBtnType> = { | 
|---|
|  |  |  | editBtn: { emits: { onClick: (role) => openDialog(role) } }, | 
|---|
|  |  |  | editTemplateBtn: { | 
|---|
|  |  |  | editBtn: { | 
|---|
|  |  |  | emits: { onClick: (role) => openDialog(role) }, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | editTemplateBtn: { | 
|---|
|  |  |  | emits: { onClick: (role) => goEditTemplate(role) }, | 
|---|
|  |  |  | extraProps: { | 
|---|
|  |  |  | hide: (row) => false, | 
|---|
|  |  |  | hide: (row: API.GetEnterpriseContractTemplatesQueryResultItem) => | 
|---|
|  |  |  | row.status !== EnumContractTemplateStatus.Wait, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | downloadBtn: { | 
|---|
|  |  |  | 
|---|
|  |  |  | emits: { onClick: (role) => handleDelete(role) }, | 
|---|
|  |  |  | props: { type: 'danger' }, | 
|---|
|  |  |  | extraProps: { | 
|---|
|  |  |  | hide: (row) => false, | 
|---|
|  |  |  | hide: (row: API.GetEnterpriseContractTemplatesQueryResultItem) => | 
|---|
|  |  |  | row.status !== EnumContractTemplateStatus.Completed, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | file: [] as UploadUserFile[], | 
|---|
|  |  |  | access: '' as any as EnumElectronSignAccess, | 
|---|
|  |  |  | title: '新增模板', | 
|---|
|  |  |  | isEnterpriseUserCreated: false, | 
|---|
|  |  |  | templateEditData: '', | 
|---|
|  |  |  | enterpriseId: '', | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function openDialog(row?: API.GetEnterpriseContractTemplatesQueryResultItem) { | 
|---|
|  |  |  | if (row) { | 
|---|
|  |  |  | handleEdit({ | 
|---|
|  |  |  | id: row.id, | 
|---|
|  |  |  | templateId: row.templateId, | 
|---|
|  |  |  | name: row.name, | 
|---|
|  |  |  | code: row.code, | 
|---|
|  |  |  | file: convertApi2FormUrlOnlyOne(row.file), | 
|---|
|  |  |  | access: row.access, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | handleAdd(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | async function openDialog(row?: API.GetEnterpriseContractTemplatesQueryResultItem) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (row) { | 
|---|
|  |  |  | let detail = await electronSignServices.getContractTemplate({ id: row.id }); | 
|---|
|  |  |  | handleEdit({ | 
|---|
|  |  |  | id: row.id, | 
|---|
|  |  |  | templateId: row.templateId, | 
|---|
|  |  |  | name: row.name, | 
|---|
|  |  |  | code: row.code, | 
|---|
|  |  |  | file: convertApi2FormUrlOnlyOne(row.file), | 
|---|
|  |  |  | access: row.access, | 
|---|
|  |  |  | isEnterpriseUserCreated: detail.isEnterpriseUserCreated, | 
|---|
|  |  |  | templateEditData: detail.templateEditData, | 
|---|
|  |  |  | enterpriseId: enterpriseId, | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | handleAdd(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (error) {} | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | async function handleAddOrEdit() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | let isEdit = !!editForm.id; | 
|---|
|  |  |  | let pdfToImage = await convertPdfToImage(editForm.file?.[0].url); | 
|---|
|  |  |  | let params: API.SaveContractTemplateCommand = { | 
|---|
|  |  |  | name: editForm.name, | 
|---|
|  |  |  | file: editForm.file[0]?.path ?? '', | 
|---|
|  |  |  | 
|---|
|  |  |  | code: editForm.code, | 
|---|
|  |  |  | access: editForm.access, | 
|---|
|  |  |  | templateId: editForm.templateId, | 
|---|
|  |  |  | // values: [ | 
|---|
|  |  |  | //   { | 
|---|
|  |  |  | //     id: '3fa85f64-5717-4562-b3fc-2c963f66afa6', | 
|---|
|  |  |  | //     type: 10, | 
|---|
|  |  |  | //     recorder: 10, | 
|---|
|  |  |  | //     userType: 10, | 
|---|
|  |  |  | //     label: 'string', | 
|---|
|  |  |  | //     name: 'string', | 
|---|
|  |  |  | //     required: true, | 
|---|
|  |  |  | //   }, | 
|---|
|  |  |  | // ], | 
|---|
|  |  |  | templateEditData: JSON.stringify( | 
|---|
|  |  |  | pdfToImage.map( | 
|---|
|  |  |  | (x) => | 
|---|
|  |  |  | ({ | 
|---|
|  |  |  | path: x.path, | 
|---|
|  |  |  | width: x.width, | 
|---|
|  |  |  | height: x.height, | 
|---|
|  |  |  | } as TemplateEditDataItem) | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | ), | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (isEdit) { | 
|---|
|  |  |  | params.id = editForm.id; | 
|---|
|  |  |  | 
|---|
|  |  |  | } catch (error) {} | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const router = useRouter(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | function goEditTemplate(row: API.GetEnterpriseContractTemplatesQueryResultItem) { | 
|---|
|  |  |  | openLink( | 
|---|
|  |  |  | router.resolve({ | 
|---|
|  |  |  | name: 'TemplateKeyEdit', | 
|---|
|  |  |  | params: { | 
|---|
|  |  |  | id: row.id ?? '', | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }).fullPath | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { openLogDialog, logDialogProps } = useOpenLogDialog({ | 
|---|
|  |  |  | service: async ({ pageIndex, pageSize }, extraParamState) => { | 
|---|
|  |  |  | try { | 
|---|