<template>
|
<ProDialog title="人员导入" v-model="visible" @close="onDialogClose" destroy-on-close draggable>
|
<ProForm :model="form" ref="dialogForm" label-width="100px">
|
<ProFormItemV2
|
label="选择文件:"
|
prop="userList"
|
:check-rules="[{ message: '请上传人员名单', type: 'array' }]"
|
>
|
<div style="display: flex">
|
<ProFormUpload
|
v-model:file-url="form.url"
|
:limit="1"
|
:limitFileSize="10"
|
accept="xlsx,xls"
|
:needUploadOss="false"
|
:on-success="handleImport"
|
></ProFormUpload>
|
<el-button
|
type="primary"
|
class="el-button-link-clear legalPersonIdImgUrl-btn"
|
link
|
@click="emit('onDownloadTemplate')"
|
>模板下载</el-button
|
>
|
</div>
|
</ProFormItemV2>
|
</ProForm>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button type="primary" @click="handleConfirm">提交</el-button>
|
<el-button type="default" @click="emit('onCancel')">取消</el-button>
|
</span>
|
</template>
|
</ProDialog>
|
</template>
|
|
<script setup lang="ts">
|
import {
|
ProDialog,
|
ProForm,
|
ProFormItemV2,
|
ProFormUpload,
|
ProFormSelect,
|
UploadUserFile,
|
XLSXUtils,
|
} from '@bole-core/components';
|
import { FormInstance, FormRules, useFormItem } from 'element-plus';
|
import { useUser } from '@/hooks';
|
|
defineOptions({
|
name: 'BatchImportDialog',
|
});
|
|
type Form = {
|
title?: string;
|
customerId: string;
|
contractTemplateId: string;
|
templateDataId: string;
|
url: UploadUserFile[];
|
userList: any[];
|
};
|
|
const visible = defineModel({ type: Boolean });
|
const form = defineModel<Form>('form');
|
|
const emit = defineEmits<{
|
(e: 'onDownloadTemplate'): void;
|
(e: 'onConfirm'): void;
|
(e: 'onCancel'): void;
|
}>();
|
|
const { user } = useUser();
|
|
const dialogForm = ref<FormInstance>();
|
|
function onDialogClose() {
|
if (!dialogForm.value) return;
|
dialogForm.value.resetFields();
|
}
|
|
function handleConfirm() {
|
if (!dialogForm.value) return;
|
dialogForm.value.validate((valid) => {
|
if (valid) {
|
emit('onConfirm');
|
} else {
|
return;
|
}
|
});
|
}
|
|
const XLSXHeaderMap = {
|
name: '姓名',
|
phone: '手机号',
|
};
|
|
function handleImport(response: UploadUserFile) {
|
XLSXUtils.resloveXLSXFromUploadInput<typeof XLSXHeaderMap>({
|
//@ts-ignore
|
file: response.file,
|
resloveKeyList: Object.keys(XLSXHeaderMap),
|
onSuccess: async (worksheetList) => {
|
const userXLSXList = worksheetList[0];
|
form.value.userList = userXLSXList;
|
dialogForm.value?.validateField?.('userList');
|
},
|
});
|
}
|
</script>
|