2024-10-04 10:43:58 +08:00
|
|
|
import { addDialog } from '@/components/BaseDialog/index';
|
|
|
|
import DeptDialog from '@/views/system/dept/dept-dialog.vue';
|
2024-10-08 10:44:31 +08:00
|
|
|
import { useDeptStore } from '@/store/system/dept';
|
2024-10-04 10:43:58 +08:00
|
|
|
import { h, ref } from 'vue';
|
2024-10-24 23:19:35 +08:00
|
|
|
import { message, messageBox } from '@/utils/message';
|
2024-10-04 10:43:58 +08:00
|
|
|
import type { FormItemProps } from '@/views/system/dept/utils/types';
|
|
|
|
import { $t } from '@/plugins/i18n';
|
2024-10-24 23:19:35 +08:00
|
|
|
import DeleteBatchDialog from '@/components/Table/DeleteBatchDialog.vue';
|
2024-10-04 10:43:58 +08:00
|
|
|
|
|
|
|
export const formRef = ref();
|
2024-10-05 15:20:48 +08:00
|
|
|
export const deleteIds = ref([]);
|
2024-10-04 10:43:58 +08:00
|
|
|
const deptStore = useDeptStore();
|
|
|
|
|
2024-10-24 23:19:35 +08:00
|
|
|
/** 搜索初始化部门 */
|
2024-10-04 10:43:58 +08:00
|
|
|
export async function onSearch() {
|
|
|
|
deptStore.loading = true;
|
|
|
|
await deptStore.getDeptList();
|
|
|
|
deptStore.loading = false;
|
|
|
|
}
|
|
|
|
|
2024-10-24 23:19:35 +08:00
|
|
|
/** 添加部门 */
|
2024-10-06 15:14:21 +08:00
|
|
|
export function onAdd(parentId: number = 0) {
|
2024-10-04 10:43:58 +08:00
|
|
|
addDialog({
|
2024-10-24 10:42:44 +08:00
|
|
|
title: `${$t('addNew')}${$t('dept')}`,
|
2024-10-04 10:43:58 +08:00
|
|
|
width: '30%',
|
|
|
|
props: {
|
|
|
|
formInline: {
|
2024-10-06 15:14:21 +08:00
|
|
|
parentId,
|
2024-10-06 18:59:44 +08:00
|
|
|
manager: undefined,
|
2024-10-04 10:43:58 +08:00
|
|
|
deptName: undefined,
|
|
|
|
summary: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(DeptDialog, { ref: formRef }),
|
|
|
|
beforeSure: (done, { options }) => {
|
|
|
|
const form = options.props.formInline as FormItemProps;
|
|
|
|
formRef.value.formRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
|
|
const result = await deptStore.addDept(form);
|
|
|
|
if (!result) return;
|
|
|
|
done();
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* * 更新部门
|
|
|
|
* @param row
|
|
|
|
*/
|
|
|
|
export function onUpdate(row: any) {
|
|
|
|
addDialog({
|
|
|
|
title: `${$t('modify')}${$t('dept')}`,
|
|
|
|
width: '30%',
|
|
|
|
props: {
|
|
|
|
formInline: {
|
|
|
|
parentId: row.parentId,
|
2024-10-31 10:01:43 +08:00
|
|
|
manager: row.manager ? row.manager.split(',') : row.manager,
|
2024-10-04 10:43:58 +08:00
|
|
|
deptName: row.deptName,
|
|
|
|
summary: row.summary,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(DeptDialog, { ref: formRef }),
|
|
|
|
beforeSure: (done, { options }) => {
|
|
|
|
const form = options.props.formInline as FormItemProps;
|
|
|
|
formRef.value.formRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
|
|
const result = await deptStore.updateDept({ ...form, id: row.id });
|
|
|
|
if (!result) return;
|
|
|
|
done();
|
|
|
|
await onSearch();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-24 23:19:35 +08:00
|
|
|
/** 删除部门 */
|
2024-10-04 10:43:58 +08:00
|
|
|
export const onDelete = async (row: any) => {
|
|
|
|
const id = row.id;
|
|
|
|
|
|
|
|
// 是否确认删除
|
|
|
|
const result = await messageBox({
|
2024-10-24 10:42:44 +08:00
|
|
|
title: $t('confirmDelete'),
|
2024-10-04 10:43:58 +08:00
|
|
|
showMessage: false,
|
|
|
|
confirmMessage: undefined,
|
2024-10-24 10:42:44 +08:00
|
|
|
cancelMessage: $t('confirmDelete'),
|
2024-10-04 10:43:58 +08:00
|
|
|
});
|
|
|
|
if (!result) return;
|
|
|
|
|
|
|
|
// 删除数据
|
|
|
|
await deptStore.deleteDept([id]);
|
|
|
|
await onSearch();
|
|
|
|
};
|
2024-10-05 15:20:48 +08:00
|
|
|
|
2024-10-24 23:19:35 +08:00
|
|
|
/** 批量删除 */
|
2024-10-05 15:20:48 +08:00
|
|
|
export const onDeleteBatch = async () => {
|
|
|
|
const ids = deleteIds.value;
|
2024-10-24 23:19:35 +08:00
|
|
|
const formDeletedBatchRef = ref();
|
2024-10-05 15:20:48 +08:00
|
|
|
|
2024-10-24 23:19:35 +08:00
|
|
|
addDialog({
|
|
|
|
title: $t('deleteBatchTip'),
|
|
|
|
width: '30%',
|
|
|
|
props: { formInline: { confirmText: '' } },
|
|
|
|
draggable: true,
|
|
|
|
fullscreenIcon: true,
|
|
|
|
closeOnClickModal: false,
|
|
|
|
contentRenderer: () => h(DeleteBatchDialog, { ref: formDeletedBatchRef }),
|
|
|
|
beforeSure: (done, { options }) => {
|
|
|
|
formDeletedBatchRef.value.formDeletedBatchRef.validate(async (valid: any) => {
|
|
|
|
if (!valid) return;
|
2024-10-05 15:20:48 +08:00
|
|
|
|
2024-10-24 23:19:35 +08:00
|
|
|
const text = options.props.formInline.confirmText.toLowerCase();
|
|
|
|
if (text === 'yes' || text === 'y') {
|
|
|
|
// 删除数据
|
|
|
|
await deptStore.deleteDept(ids);
|
|
|
|
await onSearch();
|
|
|
|
|
|
|
|
done();
|
|
|
|
} else message($t('deleteBatchTip'), { type: 'warning' });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2024-10-05 15:20:48 +08:00
|
|
|
};
|