<template>
|
<ProDialog
|
title="上传材料"
|
v-model="visible"
|
destroy-on-close
|
draggable
|
bodyNoPaddingBottom
|
@close="onDialogClose"
|
>
|
<FieldRadio
|
v-model="tab"
|
:value-enum="UploadMaterialDialogTabText"
|
style="margin-bottom: 20px"
|
></FieldRadio>
|
<ProDialogTableWrapper :height="500" v-if="tab === UploadMaterialDialogTab.Has">
|
<ProTableV2
|
:columns="columns"
|
:operationBtns="operationBtns"
|
:showPagination="false"
|
:table-data="insuranceOrderMaterialList"
|
:column-render-map="columnsRenderProps"
|
>
|
</ProTableV2>
|
</ProDialogTableWrapper>
|
<ProForm
|
:model="form"
|
ref="dialogForm"
|
label-width="120px"
|
v-else-if="tab === UploadMaterialDialogTab.Add"
|
>
|
<ProFormItemV2
|
label="材料名称:"
|
prop="materialName"
|
:check-rules="[{ message: '请输入材料名称' }]"
|
>
|
<ProFormText
|
placeholder="请输入材料名称"
|
v-model.trim="form.materialName"
|
:maxlength="30"
|
></ProFormText>
|
</ProFormItemV2>
|
<ProFormItemV2
|
label="上传模板:"
|
prop="url"
|
:check-rules="[{ message: '请上传模板', type: 'upload' }]"
|
>
|
<ProFormUpload v-model:file-url="form.url" :limit="1" :limitFileSize="10"></ProFormUpload>
|
</ProFormItemV2>
|
</ProForm>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button type="primary" @click="handleConfirm">确 定</el-button>
|
</span>
|
</template>
|
</ProDialog>
|
</template>
|
|
<script setup lang="ts">
|
import {
|
ProDialog,
|
ProTableV2,
|
useTable,
|
defineColumns,
|
defineOperationBtns,
|
ProDialogTableWrapper,
|
FieldRadio,
|
UploadUserFile,
|
ProForm,
|
ProFormItemV2,
|
ProFormText,
|
ProFormUpload,
|
ProTableV2Props,
|
} from '@bole-core/components';
|
import { setOSSLink, downloadFileByUrl, filterCN, filterNumbersFromString } from '@/utils';
|
import { FormInstance } from 'element-plus';
|
import * as insuranceOrderServices from '@/services/api/InsuranceOrder';
|
import { useInsuranceOrderMaterialList } from '@/hooks';
|
import { useQueryClient } from '@tanstack/vue-query';
|
import { Message } from '@bole-core/core';
|
|
defineOptions({
|
name: 'UploadMaterialDialog',
|
});
|
|
// type Props = {};
|
|
// const props = withDefaults(defineProps<Props>(), {});
|
|
enum UploadMaterialDialogTab {
|
Has = 1,
|
Add,
|
}
|
|
const UploadMaterialDialogTabText = {
|
[UploadMaterialDialogTab.Has]: '已上传',
|
[UploadMaterialDialogTab.Add]: '上传',
|
};
|
|
const tab = ref(UploadMaterialDialogTab.Has);
|
|
const visible = defineModel({ type: Boolean });
|
|
type Form = {
|
title?: string;
|
id: string;
|
materialName: string;
|
url: UploadUserFile[];
|
};
|
|
const form = defineModel<Form>('form');
|
|
const emit = defineEmits<{
|
(e: 'onConfirm'): void;
|
(e: 'onAddUpdateMaterial'): void;
|
(e: 'onCancel'): void;
|
}>();
|
|
watch(
|
visible,
|
(visible) => {
|
if (visible) {
|
form.value.materialName = '';
|
form.value.url = [];
|
tab.value = UploadMaterialDialogTab.Has;
|
refetch();
|
}
|
},
|
{
|
immediate: true,
|
}
|
);
|
|
const dialogForm = ref<FormInstance>();
|
|
function onDialogClose() {
|
if (!dialogForm.value) return;
|
dialogForm.value.resetFields();
|
}
|
|
function handleConfirm() {
|
if (tab.value === UploadMaterialDialogTab.Has) {
|
emit('onConfirm');
|
} else {
|
if (!dialogForm.value) return;
|
dialogForm.value.validate((valid) => {
|
if (valid) {
|
addUpdateCustomerContractTemplate();
|
} else {
|
return;
|
}
|
});
|
}
|
}
|
|
const queryClient = useQueryClient();
|
|
async function addUpdateCustomerContractTemplate() {
|
try {
|
let params: API.AddInsuranceOrderMaterialInput = {
|
insuranceOrderId: form.value.id,
|
fileName: form.value.url?.[0]?.name,
|
url: form.value.url?.[0]?.path,
|
materialName: form.value.materialName,
|
};
|
let res = await insuranceOrderServices.addInsuranceOrderMaterial(params);
|
if (res) {
|
form.value.materialName = '';
|
form.value.url = [];
|
tab.value = UploadMaterialDialogTab.Has;
|
refetch();
|
emit('onAddUpdateMaterial');
|
}
|
} catch (error) {}
|
}
|
|
const columns = defineColumns([
|
{
|
id: '1',
|
enCode: 'materialName',
|
name: '材料名称',
|
},
|
{
|
id: '2',
|
enCode: 'url',
|
name: '材料详情',
|
},
|
]);
|
|
const operationBtns = defineOperationBtns([
|
{
|
data: {
|
enCode: 'downloadBtn',
|
name: '下载',
|
},
|
emits: {
|
onClick: (role) => handleDownload(role),
|
},
|
},
|
{
|
data: {
|
enCode: 'delBtn',
|
name: '删除',
|
},
|
emits: {
|
onClick: (role) => handleDelete(role),
|
},
|
props: { type: 'danger' },
|
},
|
]);
|
|
const { insuranceOrderMaterialList, refetch } = useInsuranceOrderMaterialList({
|
insuranceOrderId: computed(() => form.value.id),
|
});
|
|
const columnsRenderProps: ProTableV2Props['columnRenderMap'] = {
|
url: {
|
type: 'url',
|
showDownloadBtn: false,
|
formatter: (row: API.InsuranceOrderMaterialListOutput) => setOSSLink(row.url),
|
},
|
};
|
|
function handleDownload(row: API.InsuranceOrderMaterialListOutput) {
|
downloadFileByUrl(setOSSLink(row.url));
|
}
|
|
async function handleDelete(row: API.InsuranceOrderMaterialListOutput) {
|
try {
|
await Message.deleteMessage();
|
const res = await insuranceOrderServices.deleteInsuranceOrderMaterial(row.id);
|
if (res) {
|
Message.successMessage('删除成功');
|
refetch({ type: 'inactive' });
|
}
|
} catch (error) {}
|
}
|
</script>
|