设备点检配置新增

This commit is contained in:
2026-05-20 15:30:37 +08:00
parent b86c94add9
commit 1b45d6124d
18 changed files with 1440 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
const { createConfirm } = useMessage();
enum Api {
list = '/xslmes/mesXslEquipInspectConfig/list',
save = '/xslmes/mesXslEquipInspectConfig/add',
edit = '/xslmes/mesXslEquipInspectConfig/edit',
deleteOne = '/xslmes/mesXslEquipInspectConfig/delete',
deleteBatch = '/xslmes/mesXslEquipInspectConfig/deleteBatch',
importExcel = '/xslmes/mesXslEquipInspectConfig/importExcel',
exportXls = '/xslmes/mesXslEquipInspectConfig/exportXls',
queryById = '/xslmes/mesXslEquipInspectConfig/queryById',
queryLineList = '/xslmes/mesXslEquipInspectConfig/queryLineListByConfigId',
}
export const getExportUrl = Api.exportXls;
export const getImportUrl = Api.importExcel;
export const list = (params) => defHttp.get({ url: Api.list, params });
export const queryById = (params: { id: string }) => defHttp.get({ url: Api.queryById, params });
export const queryLineListByConfigId = (params: { id: string }) => defHttp.get({ url: Api.queryLineList, params });
export const deleteOne = (params, handleSuccess) => {
return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
};
export const batchDelete = (params, handleSuccess) => {
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除选中数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
},
});
};
export const saveOrUpdate = (params, isUpdate) => {
const url = isUpdate ? Api.edit : Api.save;
return defHttp.post({ url, params });
};

View File

@@ -0,0 +1,86 @@
import { BasicColumn, FormSchema } from '/@/components/Table';
import { JVxeColumn, JVxeTypes } from '/@/components/jeecg/JVxeTable/types';
export const columns: BasicColumn[] = [
{ title: '设备名称', align: 'center', dataIndex: 'equipmentName', width: 160 },
{ title: '设备编号', align: 'center', dataIndex: 'equipmentCode', width: 140 },
{ title: '类型', align: 'center', dataIndex: 'configType_dictText', width: 90 },
{ title: '创建人', align: 'center', dataIndex: 'createBy', width: 100 },
{
title: '创建时间',
align: 'center',
dataIndex: 'createTime',
width: 165,
customRender: ({ text }) => (!text ? '' : String(text).length > 19 ? String(text).substring(0, 19) : text),
},
];
export const searchFormSchema: FormSchema[] = [
{ label: '设备名称', field: 'equipmentName', component: 'Input', colProps: { span: 6 } },
{ label: '设备编号', field: 'equipmentCode', component: 'Input', colProps: { span: 6 } },
{
label: '类型',
field: 'configType',
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_im_item_category' },
colProps: { span: 6 },
},
];
export const formSchema: FormSchema[] = [
{ label: '', field: 'id', component: 'Input', show: false },
{ label: '', field: 'equipmentLedgerId', component: 'Input', show: false },
{
label: '设备名称',
field: 'equipmentName',
component: 'Input',
slot: 'equipmentLedgerPicker',
dynamicRules: () => [{ required: true, message: '请选择设备台账' }],
},
{
label: '设备编号',
field: 'equipmentCode',
component: 'Input',
componentProps: { readonly: true, placeholder: '选择设备后自动带出' },
},
{
label: '类型',
field: 'configType',
component: 'JDictSelectTag',
required: true,
componentProps: { dictCode: 'xslmes_im_item_category', placeholder: '点检/保养' },
},
];
export const lineJVxeColumns: JVxeColumn[] = [
{ title: '', key: 'inspectMaintainItemId', type: JVxeTypes.hidden },
{ title: '点检项目编号', key: 'itemCode', type: JVxeTypes.normal, width: 130, disabled: true },
{ title: '项目名称', key: 'itemName', type: JVxeTypes.normal, width: 140, disabled: true },
{
title: '项目类别',
key: 'itemCategory',
type: JVxeTypes.select,
width: 100,
disabled: true,
dictCode: 'xslmes_im_item_category',
},
{
title: '项目类型',
key: 'itemType',
type: JVxeTypes.select,
width: 100,
disabled: true,
dictCode: 'xslmes_im_item_type',
},
{ title: '设备部位', key: 'equipmentPartName', type: JVxeTypes.normal, width: 120, disabled: true },
{ title: '设备小部位', key: 'equipmentSubPartName', type: JVxeTypes.normal, width: 120, disabled: true },
{
title: '点检方式',
key: 'inspectMethod',
type: JVxeTypes.select,
width: 100,
disabled: true,
dictCode: 'xslmes_im_inspect_method',
},
{ title: '判断基准', key: 'judgmentCriteria', type: JVxeTypes.normal, width: 180, disabled: true },
];

View File

@@ -0,0 +1,132 @@
<template>
<div>
<BasicTable @register="registerTable" :rowSelection="rowSelection">
<template #tableTitle>
<a-button
type="primary"
v-auth="'mes:mes_xsl_equip_inspect_config:add'"
@click="handleAdd"
preIcon="ant-design:plus-outlined"
>
新增
</a-button>
<a-button
type="primary"
v-auth="'mes:mes_xsl_equip_inspect_config:exportXls'"
preIcon="ant-design:export-outlined"
@click="onExportXls"
>
导出
</a-button>
<j-upload-button
type="primary"
v-auth="'mes:mes_xsl_equip_inspect_config:importExcel'"
preIcon="ant-design:import-outlined"
@click="onImportXls"
>
导入
</j-upload-button>
<a-dropdown v-if="selectedRowKeys.length > 0">
<template #overlay>
<a-menu>
<a-menu-item key="1" @click="batchHandleDelete">
<Icon icon="ant-design:delete-outlined" />
删除
</a-menu-item>
</a-menu>
</template>
<a-button v-auth="'mes:mes_xsl_equip_inspect_config:deleteBatch'">
批量操作
<Icon icon="mdi:chevron-down" />
</a-button>
</a-dropdown>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{ label: '编辑', onClick: handleEdit.bind(null, record), auth: 'mes:mes_xsl_equip_inspect_config:edit' },
]"
:dropDownActions="getDropDownAction(record)"
/>
</template>
</BasicTable>
<MesXslEquipInspectConfigModal @register="registerModal" @success="handleSuccess" />
</div>
</template>
<script lang="ts" name="xslmes-mesXslEquipInspectConfig" setup>
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import Icon from '/@/components/Icon';
import MesXslEquipInspectConfigModal from './components/MesXslEquipInspectConfigModal.vue';
import { columns, searchFormSchema } from './MesXslEquipInspectConfig.data';
import { list, deleteOne, batchDelete, getExportUrl, getImportUrl } from './MesXslEquipInspectConfig.api';
const [registerModal, { openModal }] = useModal();
const { tableContext, onExportXls, onImportXls } = useListPage({
tableProps: {
title: '设备点检配置',
api: list,
columns,
canResize: true,
formConfig: {
schemas: searchFormSchema,
labelWidth: 100,
autoSubmitOnEnter: true,
showAdvancedButton: true,
},
actionColumn: {
width: 200,
fixed: 'right',
},
},
exportConfig: {
name: '设备点检配置',
url: getExportUrl,
},
importConfig: {
url: getImportUrl,
success: handleSuccess,
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
function handleAdd() {
openModal(true, { isUpdate: false, showFooter: true });
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true, showFooter: true });
}
function handleDetail(record: Recordable) {
openModal(true, { record, isUpdate: true, showFooter: false });
}
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
async function batchHandleDelete() {
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
function handleSuccess() {
selectedRowKeys.value = [];
reload();
}
function getDropDownAction(record) {
return [
{ label: '详情', onClick: handleDetail.bind(null, record) },
{
label: '删除',
popConfirm: { title: '是否确认删除', confirm: handleDelete.bind(null, record) },
auth: 'mes:mes_xsl_equip_inspect_config:delete',
},
];
}
</script>

View File

@@ -0,0 +1,239 @@
<template>
<BasicModal
v-bind="$attrs"
destroyOnClose
:title="title"
width="1100px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm">
<template #equipmentLedgerPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择设备台账" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openLedgerSelect">选择</a-button>
<a-button v-if="model.equipmentLedgerId && !isDetail" @click="clearLedger">清除</a-button>
</a-input-group>
</template>
</BasicForm>
<a-divider orientation="left">点检项目明细</a-divider>
<JVxeTable
v-if="tableReady"
ref="lineTableRef"
toolbar
row-number
rowSelection
keep-source
:insert-row="false"
:max-height="380"
:loading="lineLoading"
:columns="lineJVxeColumns"
:dataSource="lineDataSource"
:disabled="!showFooterFlag"
:toolbar-config="{ btn: ['remove'], slots: ['suffix'] }"
:add-btn-cfg="{ enabled: false }"
>
<template #toolbarSuffix>
<a-button
v-if="showFooterFlag"
type="primary"
preIcon="ant-design:plus-outlined"
@click="openBatchItemSelect"
>
选择点检及保养项目
</a-button>
</template>
</JVxeTable>
<MesXslEquipmentLedgerSelectModal @register="registerLedgerModal" @select="onLedgerSelect" />
<MesXslInspectMaintainItemSelectModal @register="registerItemModal" @select="onItemsSelect" />
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref, unref } from 'vue';
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import type { JVxeTableInstance } from '/@/components/jeecg/JVxeTable/types';
import { useMessage } from '/@/hooks/web/useMessage';
import { formSchema, lineJVxeColumns } from '../MesXslEquipInspectConfig.data';
import { saveOrUpdate, queryById, queryLineListByConfigId } from '../MesXslEquipInspectConfig.api';
import MesXslEquipmentLedgerSelectModal from './MesXslEquipmentLedgerSelectModal.vue';
import MesXslInspectMaintainItemSelectModal from './MesXslInspectMaintainItemSelectModal.vue';
const emit = defineEmits(['register', 'success']);
const { createMessage } = useMessage();
const isUpdate = ref(false);
const isDetail = ref(false);
const showFooterFlag = ref(true);
const tableReady = ref(false);
const lineLoading = ref(false);
const lineDataSource = ref<Recordable[]>([]);
const lineTableRef = ref<JVxeTableInstance>();
const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] = useForm({
labelWidth: 110,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 12 },
});
const [registerLedgerModal, { openModal: openLedgerModal }] = useModal();
const [registerItemModal, { openModal: openItemModal }] = useModal();
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
tableReady.value = false;
lineDataSource.value = [];
await resetFields();
setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
isUpdate.value = !!data?.isUpdate;
isDetail.value = !data?.showFooter;
showFooterFlag.value = !!data?.showFooter;
setProps({ disabled: !data?.showFooter });
if (unref(isUpdate) && data?.record?.id) {
lineLoading.value = true;
try {
const mainRaw = await queryById({ id: data.record.id });
const m = (mainRaw as any)?.id != null ? mainRaw : (mainRaw as any)?.result ?? mainRaw;
const linesRaw = await queryLineListByConfigId({ id: data.record.id });
const list = Array.isArray(linesRaw) ? linesRaw : (linesRaw as any)?.result ?? [];
await setFieldsValue({ ...m });
lineDataSource.value = [...(list || [])];
} finally {
lineLoading.value = false;
}
}
tableReady.value = true;
});
const title = computed(() =>
!unref(isUpdate) ? '新增设备点检配置' : unref(isDetail) ? '设备点检配置详情' : '编辑设备点检配置',
);
function itemToLineRow(item: Recordable) {
return {
inspectMaintainItemId: item.id,
itemCode: item.itemCode,
itemName: item.itemName,
itemCategory: item.itemCategory,
itemType: item.itemType,
equipmentPartName: item.equipmentPartName,
equipmentSubPartName: item.equipmentSubPartName,
inspectMethod: item.inspectMethod,
judgmentCriteria: item.judgmentCriteria,
};
}
function getExistingItemIds(): Set<string> {
const lineRef = lineTableRef.value as any;
const tableData = (lineRef?.getTableData?.() || lineDataSource.value || []) as Recordable[];
const ids = new Set<string>();
for (const r of tableData) {
if (r?.inspectMaintainItemId) {
ids.add(String(r.inspectMaintainItemId));
}
}
return ids;
}
function openLedgerSelect() {
const vals = getFieldsValue();
openLedgerModal(true, { equipmentLedgerId: vals.equipmentLedgerId });
}
function clearLedger() {
setFieldsValue({ equipmentLedgerId: '', equipmentName: '', equipmentCode: '' });
}
function onLedgerSelect(payload: { equipmentLedgerId?: string; equipmentName?: string; equipmentCode?: string }) {
setFieldsValue({
equipmentLedgerId: payload.equipmentLedgerId || '',
equipmentName: payload.equipmentName || '',
equipmentCode: payload.equipmentCode || '',
});
}
function openBatchItemSelect() {
const configType = getFieldsValue()?.configType;
if (!configType) {
createMessage.warning('请先选择类型(点检/保养)');
return;
}
openItemModal(true, { itemCategory: configType, multiple: true });
}
function onItemsSelect(payload: Recordable | Recordable[]) {
const items = Array.isArray(payload) ? payload : payload ? [payload] : [];
if (!items.length) {
return;
}
const existing = getExistingItemIds();
const toAdd: Recordable[] = [];
const skipped: string[] = [];
for (const item of items) {
if (!item?.id) {
continue;
}
const id = String(item.id);
if (existing.has(id)) {
skipped.push(item.itemName || item.itemCode || id);
continue;
}
existing.add(id);
toAdd.push(itemToLineRow(item));
}
if (!toAdd.length) {
if (skipped.length) {
createMessage.warning('所选项目均已在明细中,未添加新行');
}
return;
}
const lineRef = lineTableRef.value as any;
if (lineRef?.pushRows) {
lineRef.pushRows(toAdd);
} else {
lineDataSource.value = [...lineDataSource.value, ...toAdd];
}
if (skipped.length) {
createMessage.warning(`已添加 ${toAdd.length} 项,跳过 ${skipped.length} 项重复项目`);
}
}
async function handleSubmit() {
try {
const values = await validate();
const lineRef = lineTableRef.value as any;
const tableData = (lineRef?.getTableData?.() || []) as Recordable[];
const lineList = tableData
.filter((r) => r && r.inspectMaintainItemId)
.map((r) => ({
inspectMaintainItemId: r.inspectMaintainItemId,
itemCode: r.itemCode,
itemName: r.itemName,
itemCategory: r.itemCategory,
itemType: r.itemType,
equipmentPartName: r.equipmentPartName,
equipmentSubPartName: r.equipmentSubPartName,
inspectMethod: r.inspectMethod,
judgmentCriteria: r.judgmentCriteria,
}));
if (!lineList.length) {
createMessage.warning('请通过「选择点检及保养项目」至少添加一条明细');
return;
}
const ids = new Set<string>();
for (const line of lineList) {
if (ids.has(line.inspectMaintainItemId)) {
createMessage.warning('明细中点检项目不能重复');
return;
}
ids.add(line.inspectMaintainItemId);
}
setModalProps({ confirmLoading: true });
await saveOrUpdate({ ...values, lineList }, unref(isUpdate));
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

View File

@@ -0,0 +1,93 @@
<template>
<BasicModal v-bind="$attrs" title="选择设备台账" :width="1000" @register="registerModal" @ok="handleOk">
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import { list, queryById } from '/@/views/xslmes/mesXslEquipmentLedger/MesXslEquipmentLedger.api';
const emit = defineEmits(['register', 'select']);
const selectedRow = ref<Recordable | null>(null);
function handleSelectionChange(_keys: string[], rows: Recordable[]) {
selectedRow.value = rows?.[0] ?? null;
}
const [registerTable, { reload, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] = useTable({
api: list,
columns: [
{ title: '设备名称', dataIndex: 'equipmentName', width: 160 },
{ title: '设备编号', dataIndex: 'equipmentCode', width: 140 },
{ title: '设备类别', dataIndex: 'equipmentCategoryName', width: 120 },
{ title: '设备类型', dataIndex: 'equipmentTypeName', width: 120 },
],
rowKey: 'id',
useSearchForm: true,
formConfig: {
labelWidth: 90,
schemas: [
{ label: '设备名称', field: 'equipmentName', component: 'Input', colProps: { span: 8 } },
{ label: '设备编号', field: 'equipmentCode', component: 'Input', colProps: { span: 8 } },
],
},
pagination: { pageSize: 10 },
canResize: false,
showIndexColumn: false,
immediate: true,
rowSelection: {
type: 'radio',
columnWidth: 48,
onChange: handleSelectionChange,
},
clickToRowSelect: true,
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
selectedRow.value = null;
clearSelectedRowKeys?.();
setModalProps({ confirmLoading: false });
const lid = data?.equipmentLedgerId as string | undefined;
if (lid) {
setSelectedRowKeys?.([lid]);
try {
const raw = await queryById({ id: lid });
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
if (row) {
selectedRow.value = row;
}
} catch {
// 忽略
}
}
reload();
});
async function handleOk() {
const keys = (getSelectRowKeys?.() || []) as string[];
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
if (!row && keys.length) {
try {
const raw = await queryById({ id: keys[0] });
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
} catch {
// 忽略
}
}
if (!row?.id) {
emit('select', { equipmentLedgerId: '', equipmentName: '', equipmentCode: '' });
closeModal();
return;
}
emit('select', {
equipmentLedgerId: row.id,
equipmentName: row.equipmentName || '',
equipmentCode: row.equipmentCode || '',
});
closeModal();
}
</script>

View File

@@ -0,0 +1,89 @@
<template>
<BasicModal v-bind="$attrs" :title="modalTitle" :width="1100" @register="registerModal" @ok="handleOk">
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import { list } from '/@/views/xslmes/mesXslInspectMaintainItem/MesXslInspectMaintainItem.api';
const emit = defineEmits(['register', 'select']);
const multipleMode = ref(true);
const filterItemCategory = ref('');
const selectedRows = ref<Recordable[]>([]);
const modalTitle = computed(() => (multipleMode.value ? '选择点检及保养项目(可多选)' : '选择点检及保养项目'));
function handleSelectionChange(_keys: string[], rows: Recordable[]) {
selectedRows.value = rows || [];
}
function fetchItemPage(params: Recordable) {
const p = { ...params };
if (filterItemCategory.value) {
p.itemCategory = filterItemCategory.value;
}
return list(p);
}
const [registerTable, { reload, getSelectRows, clearSelectedRowKeys }] = useTable({
api: fetchItemPage,
columns: [
{ title: '项目编号', dataIndex: 'itemCode', width: 120 },
{ title: '项目名称', dataIndex: 'itemName', width: 140 },
{ title: '项目类别', dataIndex: 'itemCategory_dictText', width: 90 },
{ title: '项目类型', dataIndex: 'itemType_dictText', width: 90 },
{ title: '设备部位', dataIndex: 'equipmentPartName', width: 110 },
{ title: '设备小部位', dataIndex: 'equipmentSubPartName', width: 110 },
{ title: '点检方式', dataIndex: 'inspectMethod_dictText', width: 90 },
{ title: '判断基准', dataIndex: 'judgmentCriteria', width: 160, ellipsis: true },
],
rowKey: 'id',
useSearchForm: true,
formConfig: {
labelWidth: 90,
schemas: [
{ label: '项目编号', field: 'itemCode', component: 'Input', colProps: { span: 8 } },
{ label: '项目名称', field: 'itemName', component: 'Input', colProps: { span: 8 } },
],
},
pagination: { pageSize: 10 },
canResize: false,
showIndexColumn: false,
immediate: true,
rowSelection: {
type: 'checkbox',
columnWidth: 48,
onChange: handleSelectionChange,
},
clickToRowSelect: true,
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
multipleMode.value = data?.multiple !== false;
filterItemCategory.value = data?.itemCategory ? String(data.itemCategory) : '';
selectedRows.value = [];
clearSelectedRowKeys?.();
setModalProps({ confirmLoading: false });
reload();
});
async function handleOk() {
let rows = selectedRows.value?.length ? [...selectedRows.value] : ((getSelectRows?.() || []) as Recordable[]);
const valid = rows.filter((r) => r?.id && (r.itemCode != null || r.itemName != null));
if (!valid.length) {
closeModal();
return;
}
if (multipleMode.value) {
emit('select', valid);
} else {
emit('select', valid[0]);
}
closeModal();
}
</script>