<template>
|
<BasicModal
|
width="1200px"
|
:height="700"
|
v-bind="$attrs"
|
ok-text="保存"
|
@register="register"
|
:title="t(props.title)"
|
@ok="handleSubmit"
|
>
|
<div class="high-form">
|
<p style="color: red" v-text="err"></p>
|
<BasicTable
|
v-for="(table, index) in tableListRef"
|
:key="index"
|
:title="table.title"
|
:columns="table.columns"
|
:dataSource="table.dataSource"
|
>
|
<template #toolbar>
|
<a-button @click="tmpDownload" type="primary" preIcon="tmpDownload-white|svg">
|
模板
|
</a-button>
|
<ImpExcel @success="loadDataSuccess" dateFormat="YYYY-MM-DD">
|
<a-button type="success" class="m-3" preIcon="ImportExcel-white|svg">
|
导入Excel
|
</a-button>
|
</ImpExcel>
|
</template>
|
</BasicTable>
|
</div>
|
</BasicModal>
|
</template>
|
<script lang="ts" setup>
|
import { ref, unref, h } from 'vue';
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
import { useI18n } from '/@/hooks/web/useI18n';
|
import { aoaToSheetXlsx, ImpExcel, ExcelData } from '/@/components/Excel';
|
import { useMessage } from '/@/hooks/web/useMessage';
|
// import { useLocale } from '/@/locales/useLocale';
|
import { BasicTable } from '/@/components/Table';
|
import { ImportExcel, ValidateTableImport } from '/@/api/tigerapi/system';
|
import { useUserStore } from '/@/store/modules/user';
|
|
const emit = defineEmits(['success', 'register', 'toExcel']);
|
const props = defineProps({
|
title: {
|
type: String,
|
default: '',
|
},
|
mtitle: {
|
type: String,
|
default: '',
|
},
|
arr: {
|
type: Array,
|
default: () => [1, 2, 3, 4],
|
},
|
});
|
// const { getLocale } = useLocale();
|
const { t } = useI18n('');
|
const { createMessage, createConfirm, createErrorModal } = useMessage();
|
const tmpHeader = ref([]);
|
const filename = ref('');
|
const entityName = ref('');
|
const checkJson = ref('');
|
const where = ref('');
|
const typeFullName = ref('');
|
const baseColumns = ref([]);
|
const tableListRef = ref<
|
{
|
title: string;
|
columns?: any[];
|
dataSource?: any[];
|
}[]
|
>([]);
|
const [register, { setModalProps, closeModal }] = useModalInner((data) => {
|
setModalProps({ confirmLoading: false });
|
tableListRef.value = [
|
{
|
title: '列表信息',
|
columns: [
|
{
|
title: '字段1',
|
dataIndex: 'field1',
|
width: 200,
|
sorter: true,
|
resizable: true,
|
},
|
{
|
title: '字段2',
|
dataIndex: 'field2',
|
width: 200,
|
sorter: true,
|
resizable: true,
|
},
|
],
|
dataSource: [],
|
},
|
];
|
tmpHeader.value = data.tmpHeader;
|
filename.value = data.filename;
|
baseColumns.value = data.baseColumns;
|
entityName.value = data.entityName;
|
checkJson.value = JSON.stringify(data.checkJson);
|
where.value = JSON.stringify(data.where);
|
typeFullName.value = data.typeFullName;
|
});
|
var err = ref('');
|
async function loadDataSuccess(excelDataList: ExcelData[]) {
|
tableListRef.value = [];
|
|
for (const excelData of excelDataList) {
|
const {
|
// header,
|
results,
|
meta: { sheetName },
|
} = excelData;
|
|
let dataSource = [] as any[];
|
results.map((item) => {
|
let entity = { AUTH_ORG: useUserStore().userInfo?.orgCode.toString() } as any;
|
baseColumns.value.map((c) => {
|
entity[c['dataIndex']] = item[c['title']]; //c['dataIndex']=='BATCH_NO'?`${item[c['ORDER_NO']]}-01`: item[c['title']];
|
});
|
dataSource.push(entity);
|
});
|
|
tableListRef.value.push({
|
title: sheetName,
|
dataSource: dataSource,
|
columns: baseColumns.value,
|
});
|
}
|
console.log('console.log(tableListRef.value);', tableListRef.value);
|
var res = await ValidateTableImport(entityName.value, {
|
EntityJson: JSON.stringify(tableListRef.value[0].dataSource),
|
CheckJson: checkJson.value,
|
where: where.value,
|
typeFullName: typeFullName.value,
|
});
|
if (res.IsSuccessed) {
|
tableListRef.value[0].dataSource = res.Data;
|
err.value = '';
|
} else {
|
tableListRef.value = [
|
{
|
title: '列表信息',
|
columns: [
|
{
|
title: '字段1',
|
dataIndex: 'field1',
|
width: 200,
|
sorter: true,
|
resizable: true,
|
},
|
{
|
title: '字段2',
|
dataIndex: 'field2',
|
width: 200,
|
sorter: true,
|
resizable: true,
|
},
|
],
|
dataSource: [],
|
},
|
];
|
createMessage.error('导入失败' + res.Message);
|
err.value = res.Message;
|
}
|
}
|
|
/**
|
* @desc 导出模板
|
*/
|
function tmpDownload() {
|
aoaToSheetXlsx({
|
data: '',
|
header: tmpHeader.value,
|
filename: filename.value, //'工单料站表信息.xlsx'
|
});
|
}
|
|
/**
|
* @desc 导入提交
|
*/
|
async function handleSubmit() {
|
try {
|
const values = tableListRef.value;
|
setModalProps({ confirmLoading: true });
|
createConfirm({
|
iconType: 'warning',
|
title: () => h('span', t('导入信息')),
|
content: () => h('span', t('确认有修改的数据是否正确,有异常的数据无法导入')),
|
onOk: async () => {
|
const apiAction = await ImportExcel(entityName.value, {
|
EntityJson: JSON.stringify(tableListRef.value[0].dataSource),
|
typeFullName: typeFullName.value,
|
});
|
if (apiAction.IsSuccessed) {
|
closeModal();
|
createMessage.success(t('导入成功'));
|
emit('success', {
|
isUpdate: unref(false),
|
values: { ...values, id: 0 },
|
});
|
} else {
|
createErrorModal({
|
title: t('sys.api.errorTip'),
|
content: apiAction.Message,
|
});
|
}
|
},
|
});
|
} finally {
|
setModalProps({ confirmLoading: false });
|
}
|
}
|
</script>
|
<style lang="less" scoped>
|
.high-form {
|
padding: 5px 10px 10px;
|
background: #f5f9fe;
|
}
|
</style>
|