设备小部位新增
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslEquipmentSubPart/list',
|
||||
checkSubPartCode = '/xslmes/mesXslEquipmentSubPart/checkSubPartCode',
|
||||
save = '/xslmes/mesXslEquipmentSubPart/add',
|
||||
edit = '/xslmes/mesXslEquipmentSubPart/edit',
|
||||
deleteOne = '/xslmes/mesXslEquipmentSubPart/delete',
|
||||
deleteBatch = '/xslmes/mesXslEquipmentSubPart/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslEquipmentSubPart/importExcel',
|
||||
exportXls = '/xslmes/mesXslEquipmentSubPart/exportXls',
|
||||
queryById = '/xslmes/mesXslEquipmentSubPart/queryById',
|
||||
}
|
||||
|
||||
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 checkSubPartCode = (params: { subPartCode: string; dataId?: string }) =>
|
||||
defHttp.get(
|
||||
{ url: Api.checkSubPartCode, params },
|
||||
{
|
||||
successMessageMode: 'none',
|
||||
errorMessageMode: 'none',
|
||||
},
|
||||
);
|
||||
|
||||
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 });
|
||||
};
|
||||
@@ -0,0 +1,110 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
import { checkSubPartCode } from './MesXslEquipmentSubPart.api';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: '小部位代码', align: 'center', dataIndex: 'subPartCode', width: 120 },
|
||||
{ title: '类别名称', align: 'center', dataIndex: 'equipmentCategoryName', width: 140 },
|
||||
{ title: '大部位名称', align: 'center', dataIndex: 'equipmentPartName', width: 140 },
|
||||
{ title: '小部位名称', align: 'center', dataIndex: 'subPartName', width: 140 },
|
||||
{ title: '部位描述', align: 'center', dataIndex: 'subPartDescription', width: 200, ellipsis: true },
|
||||
{ title: '是否启用', align: 'center', dataIndex: 'enableStatus_dictText', width: 100 },
|
||||
{ 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),
|
||||
},
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '小部位代码', field: 'subPartCode', component: 'Input', colProps: { span: 6 } },
|
||||
{ label: '类别名称', field: 'equipmentCategoryName', component: 'Input', colProps: { span: 6 } },
|
||||
{ label: '大部位名称', field: 'equipmentPartName', component: 'Input', colProps: { span: 6 } },
|
||||
{ label: '小部位名称', field: 'subPartName', component: 'Input', colProps: { span: 6 } },
|
||||
{
|
||||
label: '是否启用',
|
||||
field: 'enableStatus',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_unit_status' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
];
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '小部位代码',
|
||||
field: 'subPartCode',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '同租户下小部位代码全局唯一(未删除数据中不可重复)' },
|
||||
dynamicRules: ({ model }) => [
|
||||
{ required: true, message: '请输入小部位代码' },
|
||||
{
|
||||
validator: async (_rule, value) => {
|
||||
const v = value == null ? '' : String(value).trim();
|
||||
if (!v) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
try {
|
||||
await checkSubPartCode({ subPartCode: v, dataId: model?.id });
|
||||
return Promise.resolve();
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.data?.message || e?.message || '小部位代码不能重复';
|
||||
return Promise.reject(msg);
|
||||
}
|
||||
},
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '',
|
||||
field: 'equipmentCategoryId',
|
||||
component: 'Input',
|
||||
show: false,
|
||||
dynamicRules: () => [{ required: true, message: '请选择所属设备类别' }],
|
||||
},
|
||||
{
|
||||
label: '所属类别',
|
||||
field: 'equipmentCategoryName',
|
||||
component: 'Input',
|
||||
slot: 'equipmentCategoryPicker',
|
||||
},
|
||||
{
|
||||
label: '',
|
||||
field: 'equipmentPartId',
|
||||
component: 'Input',
|
||||
show: false,
|
||||
dynamicRules: () => [{ required: true, message: '请选择所属设备大部位' }],
|
||||
},
|
||||
{
|
||||
label: '所属大部位',
|
||||
field: 'equipmentPartName',
|
||||
component: 'Input',
|
||||
slot: 'equipmentPartPicker',
|
||||
},
|
||||
{
|
||||
label: '小部位名称',
|
||||
field: 'subPartName',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入小部位名称' },
|
||||
},
|
||||
{
|
||||
label: '部位描述',
|
||||
field: 'subPartDescription',
|
||||
component: 'InputTextArea',
|
||||
componentProps: { rows: 3 },
|
||||
},
|
||||
{
|
||||
label: '是否启用',
|
||||
field: 'enableStatus',
|
||||
required: true,
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_unit_status', placeholder: '请选择' },
|
||||
defaultValue: '0',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'mes:mes_xsl_equipment_sub_part:add'" @click="handleAdd" preIcon="ant-design:plus-outlined">
|
||||
新增
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-auth="'mes:mes_xsl_equipment_sub_part:exportXls'"
|
||||
preIcon="ant-design:export-outlined"
|
||||
@click="onExportXls"
|
||||
>
|
||||
导出
|
||||
</a-button>
|
||||
<j-upload-button
|
||||
type="primary"
|
||||
v-auth="'mes:mes_xsl_equipment_sub_part: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_equipment_sub_part: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_equipment_sub_part:edit' },
|
||||
]"
|
||||
:dropDownActions="getDropDownAction(record)"
|
||||
/>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<MesXslEquipmentSubPartModal @register="registerModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslEquipmentSubPart" setup>
|
||||
import { BasicTable, TableAction } from '/@/components/Table';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import Icon from '/@/components/Icon';
|
||||
import MesXslEquipmentSubPartModal from './components/MesXslEquipmentSubPartModal.vue';
|
||||
import { columns, searchFormSchema } from './MesXslEquipmentSubPart.data';
|
||||
import { list, deleteOne, batchDelete, getExportUrl, getImportUrl } from './MesXslEquipmentSubPart.api';
|
||||
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '设备小部位',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
labelWidth: 120,
|
||||
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_equipment_sub_part:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" title="选择设备大部位" :width="960" @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/mesXslEquipmentPart/MesXslEquipmentPart.api';
|
||||
|
||||
const emit = defineEmits(['register', 'select']);
|
||||
|
||||
const selectedRow = ref<Recordable | null>(null);
|
||||
const filterCategoryId = ref('');
|
||||
|
||||
function handleSelectionChange(_keys: string[], rows: Recordable[]) {
|
||||
selectedRow.value = rows?.[0] ?? null;
|
||||
}
|
||||
|
||||
function fetchPartPage(params: Recordable) {
|
||||
const p = { ...params };
|
||||
if (filterCategoryId.value) {
|
||||
p.equipmentCategoryId = filterCategoryId.value;
|
||||
}
|
||||
return list(p);
|
||||
}
|
||||
|
||||
const [registerTable, { reload, setProps, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] =
|
||||
useTable({
|
||||
api: fetchPartPage,
|
||||
columns: [
|
||||
{ title: '部位代码', dataIndex: 'partCode', width: 120 },
|
||||
{ title: '部位名称', dataIndex: 'partName', width: 160 },
|
||||
{ title: '类别名称', dataIndex: 'equipmentCategoryName', width: 160 },
|
||||
],
|
||||
rowKey: 'id',
|
||||
useSearchForm: true,
|
||||
formConfig: {
|
||||
labelWidth: 90,
|
||||
schemas: [
|
||||
{ label: '部位代码', field: 'partCode', component: 'Input', colProps: { span: 8 } },
|
||||
{ label: '部位名称', field: 'partName', 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) => {
|
||||
filterCategoryId.value = data?.equipmentCategoryId ? String(data.equipmentCategoryId) : '';
|
||||
selectedRow.value = null;
|
||||
clearSelectedRowKeys?.();
|
||||
setProps({
|
||||
rowSelection: {
|
||||
type: 'radio',
|
||||
columnWidth: 48,
|
||||
onChange: handleSelectionChange,
|
||||
},
|
||||
clickToRowSelect: true,
|
||||
});
|
||||
setModalProps({ confirmLoading: false });
|
||||
const pid = data?.equipmentPartId as string | undefined;
|
||||
if (pid) {
|
||||
setSelectedRowKeys?.([pid]);
|
||||
try {
|
||||
const raw = await queryById({ id: pid });
|
||||
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', { equipmentPartId: '', equipmentPartName: '' });
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
emit('select', {
|
||||
equipmentPartId: row.id,
|
||||
equipmentPartName: row.partName || '',
|
||||
});
|
||||
closeModal();
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,113 @@
|
||||
<template>
|
||||
<BasicModal @register="registerModal" :title="title" width="720" v-bind="$attrs" destroyOnClose @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm">
|
||||
<template #equipmentCategoryPicker="{ 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="openCategorySelect">选择类别</a-button>
|
||||
<a-button v-if="model.equipmentCategoryId && !isDetail" @click="clearCategory">清除</a-button>
|
||||
</a-input-group>
|
||||
</template>
|
||||
<template #equipmentPartPicker="{ 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="openPartSelect">选择大部位</a-button>
|
||||
<a-button v-if="model.equipmentPartId && !isDetail" @click="clearPart">清除</a-button>
|
||||
</a-input-group>
|
||||
</template>
|
||||
</BasicForm>
|
||||
<MesXslEquipmentCategorySelectModal @register="registerCategoryModal" @select="onCategorySelect" />
|
||||
<MesXslEquipmentPartSelectModal @register="registerPartModal" @select="onPartSelect" />
|
||||
</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 { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { formSchema } from '../MesXslEquipmentSubPart.data';
|
||||
import { saveOrUpdate } from '../MesXslEquipmentSubPart.api';
|
||||
import MesXslEquipmentCategorySelectModal from '/@/views/xslmes/mesXslEquipmentType/components/MesXslEquipmentCategorySelectModal.vue';
|
||||
import MesXslEquipmentPartSelectModal from './MesXslEquipmentPartSelectModal.vue';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const { createMessage } = useMessage();
|
||||
const isUpdate = ref(true);
|
||||
const isDetail = ref(false);
|
||||
|
||||
const [registerCategoryModal, { openModal: openCategoryModal }] = useModal();
|
||||
const [registerPartModal, { openModal: openPartModal }] = useModal();
|
||||
|
||||
const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas: formSchema,
|
||||
showActionButtonGroup: false,
|
||||
});
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
await resetFields();
|
||||
setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
|
||||
isUpdate.value = !!data?.isUpdate;
|
||||
isDetail.value = !data?.showFooter;
|
||||
if (unref(isUpdate)) await setFieldsValue({ ...data.record });
|
||||
setProps({ disabled: !data?.showFooter });
|
||||
});
|
||||
|
||||
const title = computed(() =>
|
||||
!unref(isUpdate) ? '新增设备小部位' : unref(isDetail) ? '设备小部位详情' : '编辑设备小部位',
|
||||
);
|
||||
|
||||
function openCategorySelect() {
|
||||
const vals = getFieldsValue();
|
||||
openCategoryModal(true, { equipmentCategoryId: vals.equipmentCategoryId });
|
||||
}
|
||||
|
||||
function clearCategory() {
|
||||
setFieldsValue({ equipmentCategoryId: '', equipmentCategoryName: '', equipmentPartId: '', equipmentPartName: '' });
|
||||
}
|
||||
|
||||
function onCategorySelect(payload: { equipmentCategoryId?: string; equipmentCategoryName?: string }) {
|
||||
setFieldsValue({
|
||||
equipmentCategoryId: payload.equipmentCategoryId || '',
|
||||
equipmentCategoryName: payload.equipmentCategoryName || '',
|
||||
equipmentPartId: '',
|
||||
equipmentPartName: '',
|
||||
});
|
||||
}
|
||||
|
||||
function openPartSelect() {
|
||||
const vals = getFieldsValue();
|
||||
if (!vals.equipmentCategoryId) {
|
||||
createMessage.warning('请先选择所属设备类别');
|
||||
return;
|
||||
}
|
||||
openPartModal(true, {
|
||||
equipmentCategoryId: vals.equipmentCategoryId,
|
||||
equipmentPartId: vals.equipmentPartId,
|
||||
});
|
||||
}
|
||||
|
||||
function clearPart() {
|
||||
setFieldsValue({ equipmentPartId: '', equipmentPartName: '' });
|
||||
}
|
||||
|
||||
function onPartSelect(payload: { equipmentPartId?: string; equipmentPartName?: string }) {
|
||||
setFieldsValue({
|
||||
equipmentPartId: payload.equipmentPartId || '',
|
||||
equipmentPartName: payload.equipmentPartName || '',
|
||||
});
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate();
|
||||
setModalProps({ confirmLoading: true });
|
||||
await saveOrUpdate(values, isUpdate.value);
|
||||
closeModal();
|
||||
emit('success');
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user