<script setup lang="ts">
|
import type { Recordable } from '@vben/types';
|
|
import { onMounted, ref } from 'vue';
|
|
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
|
import { $t } from '@vben/locales';
|
import { addFullName, getPopupContainer, getVxePopupContainer } from '@vben/utils';
|
|
import { Dropdown, Menu, MenuItem, Modal, Popconfirm, Space } from 'ant-design-vue';
|
|
import { useVbenVxeGrid, vxeCheckboxChecked, type VxeGridProps, vxeSortEvent } from '#/adapter/vxe-table';
|
import { delInspPlan, inspPlanExport, listInspPlan } from '#/api/eims/insp-plan';
|
import { generateCode } from '#/api/eims/utils';
|
import { getDeptTree, userList } from '#/api/system/user';
|
import { EIMS_INSPECT_STATUS } from '#/constants/dict';
|
import { commonDownloadExcel } from '#/utils/file/download';
|
import inspRecordDrawer from '#/views/eims/insp-record/insp-record-drawer.vue';
|
|
import { columns, querySchema } from './data';
|
import inspPlanDrawer from './insp-plan-drawer.vue';
|
|
defineExpose({
|
tableSelect
|
});
|
|
const formOptions: VbenFormProps = {
|
commonConfig: {
|
labelWidth: 80,
|
componentProps: {
|
allowClear: true
|
}
|
},
|
collapsed: true,
|
schema: querySchema(),
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
// 日期选择格式化
|
fieldMappingTime: [['planTime', ['params[beginPlanTime]', 'params[endPlanTime]'], ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59']]]
|
};
|
|
const gridOptions: VxeGridProps = {
|
checkboxConfig: {
|
// 高亮
|
highlight: true,
|
// 翻页时保留选中状态
|
reserve: true
|
// 点击行选中
|
// trigger: 'row'
|
},
|
columns,
|
height: 'auto',
|
keepSource: true,
|
pagerConfig: {},
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues = {}) => {
|
return await listInspPlan({
|
pageNum: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues
|
});
|
}
|
}
|
},
|
rowConfig: {
|
isHover: true,
|
keyField: 'id'
|
},
|
sortConfig: {
|
// 远程排序
|
remote: true,
|
// 支持多字段排序 默认关闭
|
multiple: true
|
},
|
id: 'insp-plan-index'
|
};
|
const equId = ref<string>();
|
const [BasicTable, tableApi] = useVbenVxeGrid({
|
formOptions,
|
gridOptions,
|
gridEvents: {
|
sortChange: (sortParams) => vxeSortEvent(tableApi, sortParams),
|
cellClick: (e: any) => {
|
const { row } = e;
|
equId.value = row.equId;
|
}
|
}
|
});
|
|
const [InspPlanDrawer, inspPlanDrawerApi] = useVbenDrawer({
|
connectedComponent: inspPlanDrawer
|
});
|
|
const [InspRecordDrawer, inspRecordDrawerApi] = useVbenDrawer({
|
connectedComponent: inspRecordDrawer
|
});
|
|
function handleAdd() {
|
inspPlanDrawerApi.setData({});
|
inspPlanDrawerApi.open();
|
}
|
|
async function handleEdit(record: Recordable<any>) {
|
inspPlanDrawerApi.setData({ id: record.id });
|
inspPlanDrawerApi.open();
|
}
|
|
async function handleDelete(row: Recordable<any>) {
|
await delInspPlan(row.id);
|
await tableApi.query();
|
}
|
|
function handleMultiDelete() {
|
const rows = tableApi.grid.getCheckboxRecords();
|
const ids = rows.map((row: any) => row.id);
|
Modal.confirm({
|
title: '提示',
|
okType: 'danger',
|
content: `确认删除选中的${ids.length}条记录吗?`,
|
onOk: async () => {
|
await delInspPlan(ids);
|
await tableApi.query();
|
}
|
});
|
}
|
|
function handleDownloadExcel() {
|
commonDownloadExcel(inspPlanExport, '点检计划记录', tableApi.formApi.form.values, {
|
fieldMappingTime: formOptions.fieldMappingTime
|
});
|
}
|
|
/**
|
* 生成点检记录
|
* @param record
|
*/
|
async function handleAddOrder(record: Recordable<any>) {
|
/**
|
* 生成点检记录code
|
*/
|
const code = await generateCode('DJSD');
|
if (!code) {
|
Modal.error({
|
content: '生成点检记录失败,请重试!',
|
title: '提示'
|
});
|
return false;
|
}
|
const planInsp = {
|
equId: record.equId,
|
planId: record.id,
|
equName: record.equName,
|
inspUser: record.inspUser,
|
inspUserName: record.inspUserName,
|
inspDept: record.inspDept,
|
inspDeptName: record.inspDeptName,
|
inspType: record.inspType,
|
planTime: record.inspNextTime,
|
status: EIMS_INSPECT_STATUS.WEIDIANJIAN,
|
inspCode: code,
|
inspName: record.inspName
|
};
|
|
inspRecordDrawerApi.setData({ planInsp });
|
inspRecordDrawerApi.open();
|
// await addMaintOrder(order.value);
|
}
|
/**
|
* 初始化部门选择
|
*/
|
async function setupDeptSelect() {
|
// updateSchema
|
const deptTree = await getDeptTree();
|
// 选中后显示在输入框的值 即父节点 / 子节点
|
addFullName(deptTree, 'label', ' / ');
|
tableApi.formApi.updateSchema([
|
{
|
componentProps: (formModel) => ({
|
class: 'w-full',
|
fieldNames: {
|
key: 'id',
|
value: 'id',
|
children: 'children'
|
},
|
getPopupContainer,
|
async onSelect(deptId: number | string) {
|
/** 根据部门ID加载用户 */
|
await setupUserOptions(deptId);
|
/** 变化后需要重新选择用户 */
|
formModel.inspUser = undefined;
|
},
|
placeholder: '请选择',
|
showSearch: true,
|
treeData: deptTree,
|
treeDefaultExpandAll: true,
|
treeLine: { showLeafIcon: false },
|
// 筛选的字段
|
treeNodeFilterProp: 'label',
|
// 选中后显示在输入框的值
|
treeNodeLabelProp: 'fullName'
|
}),
|
fieldName: 'inspDept'
|
}
|
]);
|
}
|
|
/**
|
* 用户的加载
|
*/
|
async function setupUserOptions(deptId: any) {
|
const params = { deptId };
|
const userPageResult = await userList({
|
pageNum: 1,
|
pageSize: 500,
|
...params
|
});
|
const options = userPageResult.rows.map((item) => ({
|
label: item.nickName || item.userName,
|
value: item.userId
|
}));
|
// 筛选
|
const filterOption = (input: string, option: any) => {
|
return option.label.toLowerCase().includes(input.toLowerCase());
|
};
|
|
const placeholder = options.length > 0 ? '请选择' : '该部门下暂无用户';
|
tableApi.formApi.updateSchema([
|
{
|
componentProps: { options, placeholder, filterOption },
|
fieldName: 'inspUser'
|
}
|
]);
|
}
|
|
onMounted(async () => {
|
await setupDeptSelect();
|
});
|
|
// 选中数据
|
function tableSelect() {
|
return tableApi.grid.getCheckboxRecords();
|
}
|
</script>
|
|
<template>
|
<Page :auto-content-height="true">
|
<div class="flex h-full gap-[8px] flex-col">
|
<BasicTable table-title="点检计划列表">
|
<template #toolbar-tools>
|
<Space>
|
<a-button v-access:code="['eims:inspectPlan:export']" @click="handleDownloadExcel">
|
{{ $t('pages.common.export') }}
|
</a-button>
|
<a-button
|
:disabled="!vxeCheckboxChecked(tableApi)"
|
danger
|
type="primary"
|
v-access:code="['eims:inspectPlan:remove']"
|
@click="handleMultiDelete"
|
>
|
{{ $t('pages.common.delete') }}
|
</a-button>
|
<a-button type="primary" v-access:code="['eims:inspectPlan:add']" @click="handleAdd">
|
{{ $t('pages.common.add') }}
|
</a-button>
|
</Space>
|
</template>
|
|
<template #equName="{ row }">
|
<Space>
|
<span>{{ row.equName }}</span>
|
</Space>
|
</template>
|
|
<template #action="{ row }">
|
<Space>
|
<ghost-button class="btn-success" v-access:code="['eims:inspectPlan:edit']" @click.stop="handleAddOrder(row)"> 生成点检 </ghost-button>
|
<ghost-button v-access:code="['eims:inspectPlan:edit']" @click.stop="handleEdit(row)">
|
{{ $t('pages.common.edit') }}
|
</ghost-button>
|
</Space>
|
<Dropdown :get-popup-container="getVxePopupContainer" placement="bottomRight">
|
<template #overlay>
|
<Menu>
|
<Popconfirm :get-popup-container="getVxePopupContainer" placement="left" title="确认删除?" @confirm="handleDelete(row)">
|
<MenuItem key="1" @click.stop="">
|
{{ $t('pages.common.delete') }}
|
</MenuItem>
|
</Popconfirm>
|
</Menu>
|
</template>
|
<a-button size="small" type="link" v-access:code="['eims:inspectPlan:remove']">
|
{{ $t('pages.common.more') }}
|
</a-button>
|
</Dropdown>
|
</template>
|
</BasicTable>
|
</div>
|
<InspPlanDrawer @reload="tableApi.query()" />
|
<InspRecordDrawer @reload="tableApi.query()" />
|
</Page>
|
</template>
|