mps-platform/cds-fontend-2025.V1/src/views/system/dept-transfer/index.vue

329 lines
8.7 KiB
Vue
Raw Normal View History

2025-07-16 10:31:51 +08:00
<script setup lang="tsx">
2025-09-02 18:37:39 +08:00
import { ref, watch } from 'vue';
2025-07-16 10:31:51 +08:00
import { NDivider } from 'naive-ui';
import { fetchBatchDeleteDeptTransfer, fetchGetDeptTransferList } from '@/service/api/system/dept-transfer';
2025-09-02 18:37:39 +08:00
import {fetchGetDeptTree, fetchGetMuUserSelect} from '@/service/api/system';
2025-07-16 10:31:51 +08:00
import { useAppStore } from '@/store/modules/app';
import { useAuth } from '@/hooks/business/auth';
import { useDownload } from '@/hooks/business/download';
import { useTable, useTableOperate } from '@/hooks/common/table';
import { $t } from '@/locales';
import ButtonIcon from '@/components/custom/button-icon.vue';
import DeptTransferOperateDrawer from './modules/dept-transfer-operate-drawer.vue';
import DeptTransferSearch from './modules/dept-transfer-search.vue';
import DeptTransferImportModal from './modules/dept-transfer-import-modal.vue';
2025-09-02 18:37:39 +08:00
import { useBoolean, useLoading } from '~/packages/hooks';
2025-07-16 10:31:51 +08:00
defineOptions({
name: 'DeptTransferList'
2025-07-16 10:31:51 +08:00
});
const appStore = useAppStore();
const { download } = useDownload();
const { hasAuth } = useAuth();
const { bool: importVisible, setTrue: openImportModal } = useBoolean();
const {
columns,
columnChecks,
data,
getData,
getDataByPage,
loading,
mobilePagination,
searchParams,
resetSearchParams
} = useTable({
apiFn: fetchGetDeptTransferList,
2025-07-16 10:31:51 +08:00
apiParams: {
pageNum: 1,
pageSize: 10,
// if you want to use the searchParams in Form, you need to define the following properties, and the value is null
// the value can not be undefined, otherwise the property in Form will not be reactive
2025-09-02 18:37:39 +08:00
nickName: null,
mktNo: null,
oldDeptId: null,
newDeptId: null,
transferDate: null,
2025-07-16 10:31:51 +08:00
params: {}
},
columns: () => [
{
type: 'selection',
align: 'center',
width: 48
},
{
key: 'index',
title: $t('common.index'),
align: 'center',
width: 64,
resizable: true
},
2025-09-02 18:37:39 +08:00
// {
// key: 'id',
// title: '主键ID',
// align: 'center',
// minWidth: 120,
// ellipsis: true,
// resizable: true
// },
2025-07-16 10:31:51 +08:00
{
2025-09-02 18:37:39 +08:00
key: 'nickName',
title: '用户姓名',
2025-07-16 10:31:51 +08:00
align: 'center',
minWidth: 120,
ellipsis: true,
resizable: true
},
{
2025-09-02 18:37:39 +08:00
key: 'mktNo',
title: '营销编号',
align: 'center',
minWidth: 120,
ellipsis: true,
resizable: true
},
{
key: 'oldDeptName',
title: '调岗前部门',
2025-07-16 10:31:51 +08:00
align: 'center',
minWidth: 120,
ellipsis: true,
resizable: true
},
{
2025-09-02 18:37:39 +08:00
key: 'newDeptName',
title: '调岗后部门',
2025-07-16 10:31:51 +08:00
align: 'center',
minWidth: 120,
ellipsis: true,
resizable: true
},
{
key: 'transferDate',
title: '调岗时间',
2025-07-16 10:31:51 +08:00
align: 'center',
minWidth: 120,
ellipsis: true,
resizable: true
},
{
key: 'remark',
title: '备注',
2025-07-16 10:31:51 +08:00
align: 'center',
minWidth: 120,
ellipsis: true,
resizable: true
},
{
key: 'operate',
title: $t('common.operate'),
fixed: 'right',
width: 130,
render: row => {
const divider = () => {
if (!hasAuth('system:deptTransfer:edit') || !hasAuth('system:deptTransfer:remove')) {
2025-07-16 10:31:51 +08:00
return null;
}
return <NDivider vertical />;
};
const editBtn = () => {
if (!hasAuth('system:deptTransfer:edit')) {
2025-07-16 10:31:51 +08:00
return null;
}
return (
<ButtonIcon
text
type="primary"
2025-08-21 11:40:09 +08:00
local-icon="drive-file-rename-outline-outline"
2025-07-16 10:31:51 +08:00
tooltipContent={$t('common.edit')}
onClick={() => edit(row.id!)}
2025-07-16 10:31:51 +08:00
/>
);
};
const deleteBtn = () => {
if (!hasAuth('system:deptTransfer:remove')) {
2025-07-16 10:31:51 +08:00
return null;
}
return (
<ButtonIcon
text
type="error"
2025-08-21 11:40:09 +08:00
local-icon="delete-outline"
2025-07-16 10:31:51 +08:00
tooltipContent={$t('common.delete')}
popconfirmContent={$t('common.confirmDelete')}
onPositiveClick={() => handleDelete(row.id!)}
2025-07-16 10:31:51 +08:00
/>
);
};
return (
<div class="flex-center gap-8px">
{editBtn()}
{divider()}
{deleteBtn()}
</div>
);
}
}
]
});
const scrollX = ref(0);
// 计算总宽度函数
const calculateTotalWidth = () => {
2025-09-02 18:37:39 +08:00
let totalWidth = 0;
const visibleColumns = columns.value;
for (let i = 0; i < visibleColumns.length; i++) {
const column = visibleColumns[i];
// 获取列的实际渲染宽度
// 注意:调整大小时会更新 column.width
let width = column.width;
// 如果没有显式宽度则使用minWidth或默认值
if (!width) {
width = column.minWidth || 120;
2025-07-16 10:31:51 +08:00
}
2025-09-02 18:37:39 +08:00
// 转换为数字类型
width = typeof width === 'string' ? Number.parseInt(width) : width;
totalWidth += width;
}
2025-07-16 10:31:51 +08:00
2025-09-02 18:37:39 +08:00
// 添加额外的50px余量防止边缘裁剪
return totalWidth + 50;
2025-07-16 10:31:51 +08:00
};
// 监听列变化并计算宽度
2025-09-02 18:37:39 +08:00
watch(
columns,
newColumns => {
2025-07-16 10:31:51 +08:00
scrollX.value = calculateTotalWidth();
2025-09-02 18:37:39 +08:00
},
{ deep: true }
);
const {startLoading: startDeptLoading, endLoading: endDeptLoading } = useLoading();
const operatorIdOptions = ref<CommonType.Option<CommonType.IdType>[]>([]);
async function getoperatorIdOptions() {
startDeptLoading();
const { error, data } = await fetchGetMuUserSelect();
if (!error) {
operatorIdOptions.value = data.map(item => ({
label: item.nickName,
value: item.mktNo
}));
}
endDeptLoading();
}
getoperatorIdOptions();
const deptData = ref<Api.Common.CommonTreeRecord>([]);
async function getTreeData() {
startDeptLoading();
const { data: tree, error } = await fetchGetDeptTree();
if (!error) {
deptData.value = tree;
}
endDeptLoading();
}
2025-07-16 10:31:51 +08:00
2025-09-02 18:37:39 +08:00
getTreeData();
2025-07-16 10:31:51 +08:00
const { drawerVisible, operateType, editingData, handleAdd, handleEdit, checkedRowKeys, onBatchDeleted, onDeleted } =
useTableOperate(data, getData);
async function handleBatchDelete() {
// request
const { error } = await fetchBatchDeleteDeptTransfer(checkedRowKeys.value);
2025-07-16 10:31:51 +08:00
if (error) return;
onBatchDeleted();
}
async function handleDelete(id: CommonType.IdType) {
2025-07-16 10:31:51 +08:00
// request
const { error } = await fetchBatchDeleteDeptTransfer([id]);
2025-07-16 10:31:51 +08:00
if (error) return;
onDeleted();
}
function edit(id: CommonType.IdType) {
handleEdit('id', id);
2025-07-16 10:31:51 +08:00
}
function handleImport() {
2025-09-02 18:37:39 +08:00
openImportModal();
2025-07-16 10:31:51 +08:00
}
function handleExport() {
download('/system/deptTransfer/export', searchParams, `部门调整_${new Date().getTime()}.xlsx`);
2025-07-16 10:31:51 +08:00
}
</script>
<template>
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
2025-09-02 18:37:39 +08:00
<DeptTransferSearch
v-model:model="searchParams"
:dept-data="deptData"
:operator-id-options="operatorIdOptions"
@reset="resetSearchParams"
@search="getDataByPage"
/>
<NCard title="部门调整列表" :bordered="false" size="small" class="card-wrapper sm:flex-1-hidden">
2025-07-16 10:31:51 +08:00
<template #header-extra>
<TableHeaderOperation
v-model:columns="columnChecks"
:disabled-delete="checkedRowKeys.length === 0"
:loading="loading"
:show-add="hasAuth('system:deptTransfer:add')"
:show-delete="hasAuth('system:deptTransfer:remove')"
:show-export="hasAuth('system:deptTransfer:export')"
2025-07-16 10:31:51 +08:00
@add="handleAdd"
@delete="handleBatchDelete"
@export="handleExport"
@refresh="getData"
>
2025-09-02 18:37:39 +08:00
<template #after>
<NButton v-if="hasAuth('system:deptTransfer:import')" size="small" ghost @click="handleImport">
2025-09-02 18:37:39 +08:00
<template #icon>
<SvgIcon local-icon="upload-rounded" />
</template>
{{ $t('common.import') }}
</NButton>
</template>
2025-07-16 10:31:51 +08:00
</TableHeaderOperation>
</template>
<!--scroll-x : 所有表格列宽度之和(包含操作列)+操作列宽度-->
<NDataTable
v-model:checked-row-keys="checkedRowKeys"
:columns="columns"
:data="data"
size="small"
:flex-height="!appStore.isMobile"
:scroll-x="scrollX"
:loading="loading"
remote
:row-key="row => row.id"
2025-07-16 10:31:51 +08:00
:pagination="mobilePagination"
class="sm:h-full"
@update-resize-widths="scrollX = calculateTotalWidth()"
/>
2025-09-02 18:37:39 +08:00
<DeptTransferImportModal v-model:visible="importVisible" @submitted="getDataByPage" />
2025-07-16 10:31:51 +08:00
<DeptTransferOperateDrawer
2025-07-16 10:31:51 +08:00
v-model:visible="drawerVisible"
:operate-type="operateType"
:row-data="editingData"
2025-09-02 18:37:39 +08:00
:dept-data="deptData"
:operator-id-options="operatorIdOptions"
2025-07-16 10:31:51 +08:00
@submitted="getDataByPage"
/>
</NCard>
</div>
</template>
<style scoped></style>