<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { HrmEmployeeContractApi } from '#/api/hrm/employee/contract';
|
|
import { Page, useVbenModal } from '#/packages/effects/common-ui/src';
|
|
import { message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
deleteEmployeeContract,
|
getEmployeeContractPage,
|
} from '#/api/hrm/employee/contract';
|
import { $t } from '#/locales';
|
|
import { useGridColumns, useGridFormSchema } from './data';
|
import Form from './modules/form.vue';
|
import Terminate from './modules/terminate.vue';
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const [TerminateModal, terminateModalApi] = useVbenModal({
|
connectedComponent: Terminate,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 新增合同 */
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
/** 编辑合同 */
|
function handleEdit(row: HrmEmployeeContractApi.EmployeeContract) {
|
formModalApi.setData({ id: row.id, formType: 'update' }).open();
|
}
|
|
/** 续签合同:带入上份合同基础信息,创建新合同(后端自动关联 parentId) */
|
function handleRenew(row: HrmEmployeeContractApi.EmployeeContract) {
|
formModalApi.setData({ formType: 'create', renewFrom: row }).open();
|
}
|
|
/** 解除/终止合同 */
|
function handleTerminate(row: HrmEmployeeContractApi.EmployeeContract) {
|
terminateModalApi.setData({ id: row.id }).open();
|
}
|
|
/** 删除合同 */
|
async function handleDelete(row: HrmEmployeeContractApi.EmployeeContract) {
|
await deleteEmployeeContract(row.id!);
|
message.success($t('ui.actionMessage.deleteSuccess', ['员工合同']));
|
handleRefresh();
|
}
|
|
/** 是否可解除/终止:仅未解除/未终止的合同可操作 */
|
function isTerminable(row: HrmEmployeeContractApi.EmployeeContract) {
|
return row.terminateStatus === 0;
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) =>
|
await getEmployeeContractPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
}),
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<HrmEmployeeContractApi.EmployeeContract>,
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<TerminateModal @success="handleRefresh" />
|
<Grid table-title="员工合同列表">
|
<template #parentNo="{ row }">
|
<span>{{ row.parentNo || '-' }}</span>
|
</template>
|
<template #isCurrent="{ row }">
|
<Tag v-if="row.isCurrent" color="processing">当前</Tag>
|
<span v-else>-</span>
|
</template>
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['员工合同']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['hrm:employee-contract:create'],
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '续签',
|
type: 'link',
|
icon: ACTION_ICON.ADD,
|
auth: ['hrm:employee-contract:create'],
|
ifShow: isTerminable(row),
|
onClick: handleRenew.bind(null, row),
|
},
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['hrm:employee-contract:update'],
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '解除/终止',
|
type: 'link',
|
icon: ACTION_ICON.CLOSE,
|
auth: ['hrm:employee-contract:update'],
|
ifShow: isTerminable(row),
|
onClick: handleTerminate.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['hrm:employee-contract:delete'],
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', ['员工合同']),
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|