<script lang="ts" setup>
|
import type { FormType } from '../data';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { HrmEmployeeApi } from '#/api/hrm/employee';
|
|
import type { DefaultOptionType } from 'ant-design-vue/es/select';
|
|
import { computed, nextTick, watch } from 'vue';
|
|
import { IconifyIcon } from '#/packages/icons/src';
|
|
import { DICT_TYPE } from '#/packages/constants/src';
|
import { getDictOptions } from '#/packages/effects/hooks/src';
|
|
import { Button, DatePicker, Input, Select } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { getEducationListByEmployeeId } from '#/api/hrm/employee/education';
|
import { $t } from '#/locales';
|
|
const props = defineProps<{
|
employeeId?: number;
|
formType: FormType;
|
}>();
|
|
const isReadOnly = computed(() => props.formType === 'detail');
|
|
const degreeOptions = getDictOptions(DICT_TYPE.HRM_DEGREE, 'number') as DefaultOptionType[];
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
gridOptions: {
|
columns: [
|
{ field: 'schoolName', title: '学校名称', minWidth: 150, slots: { default: 'schoolName' } },
|
{ field: 'major', title: '专业', minWidth: 120, slots: { default: 'major' } },
|
{
|
field: 'degree',
|
title: '学历',
|
minWidth: 100,
|
slots: { default: 'degree' },
|
},
|
{
|
field: 'startDate',
|
title: '入学时间',
|
minWidth: 120,
|
slots: { default: 'startDate' },
|
},
|
{
|
field: 'endDate',
|
title: '毕业时间',
|
minWidth: 120,
|
slots: { default: 'endDate' },
|
},
|
{ field: 'certificateNo', title: '证书编号', minWidth: 140, slots: { default: 'certificateNo' } },
|
{
|
title: '操作',
|
width: 80,
|
fixed: 'right',
|
slots: { default: 'actions' },
|
visible: !isReadOnly.value,
|
},
|
],
|
border: true,
|
showOverflow: true,
|
autoResize: true,
|
keepSource: true,
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
pagerConfig: {
|
enabled: false,
|
},
|
toolbarConfig: {
|
enabled: false,
|
},
|
} as VxeTableGridOptions<HrmEmployeeApi.Education>,
|
});
|
|
/** 添加教育经历 */
|
async function handleAdd() {
|
await gridApi.grid.insertAt({} as HrmEmployeeApi.Education, -1);
|
}
|
|
/** 删除教育经历 */
|
async function handleDelete(row: HrmEmployeeApi.Education) {
|
await gridApi.grid.remove(row);
|
}
|
|
/** 提供获取表格数据的方法供父组件调用 */
|
defineExpose({
|
getData: (): HrmEmployeeApi.Education[] => {
|
const data = gridApi.grid.getData() as HrmEmployeeApi.Education[];
|
const removeRecords = gridApi.grid.getRemoveRecords() as HrmEmployeeApi.Education[];
|
const insertRecords = gridApi.grid.getInsertRecords() as HrmEmployeeApi.Education[];
|
return [
|
...data.filter((row) => !removeRecords.some((removed) => removed.id === row.id)),
|
...insertRecords.map((row: any) => ({ ...row, id: undefined })),
|
];
|
},
|
});
|
|
/** 监听员工ID变化,加载子表数据 */
|
watch(
|
() => props.employeeId,
|
async (val) => {
|
if (!val) {
|
return;
|
}
|
await nextTick();
|
await gridApi.grid.loadData(await getEducationListByEmployeeId(props.employeeId!));
|
},
|
{ immediate: true },
|
);
|
</script>
|
|
<template>
|
<Grid class="w-full">
|
<template #schoolName="{ row }">
|
<Input v-model:value="row.schoolName" :disabled="isReadOnly" placeholder="请输入学校名称" />
|
</template>
|
<template #major="{ row }">
|
<Input v-model:value="row.major" :disabled="isReadOnly" placeholder="请输入专业" />
|
</template>
|
<template #degree="{ row }">
|
<Select
|
v-model:value="row.degree"
|
:disabled="isReadOnly"
|
:options="degreeOptions"
|
placeholder="请选择学历"
|
allowClear
|
/>
|
</template>
|
<template #startDate="{ row }">
|
<DatePicker
|
v-model:value="row.startDate"
|
:disabled="isReadOnly"
|
placeholder="请选择入学时间"
|
valueFormat="YYYY-MM-DD"
|
style="width: 100%"
|
/>
|
</template>
|
<template #endDate="{ row }">
|
<DatePicker
|
v-model:value="row.endDate"
|
:disabled="isReadOnly"
|
placeholder="请选择毕业时间"
|
valueFormat="YYYY-MM-DD"
|
style="width: 100%"
|
/>
|
</template>
|
<template #certificateNo="{ row }">
|
<Input v-model:value="row.certificateNo" :disabled="isReadOnly" placeholder="请输入证书编号" />
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.delete'),
|
danger: true,
|
type: 'link',
|
icon: ACTION_ICON.DELETE,
|
onClick: handleDelete.bind(null, row),
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
<div v-if="!isReadOnly" class="-mt-4 flex justify-center">
|
<Button type="primary" ghost @click="handleAdd">
|
<IconifyIcon icon="lucide:plus" />
|
添加教育经历
|
</Button>
|
</div>
|
</template>
|