优化混炼示方,新增种类配置
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslMixerMaterialKindCfg/list',
|
||||
save = '/xslmes/mesXslMixerMaterialKindCfg/add',
|
||||
edit = '/xslmes/mesXslMixerMaterialKindCfg/edit',
|
||||
addBatch = '/xslmes/mesXslMixerMaterialKindCfg/addBatch',
|
||||
expandLines = '/xslmes/mesXslMixerMaterialKindCfg/expandLines',
|
||||
deleteOne = '/xslmes/mesXslMixerMaterialKindCfg/delete',
|
||||
deleteBatch = '/xslmes/mesXslMixerMaterialKindCfg/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslMixerMaterialKindCfg/importExcel',
|
||||
exportXls = '/xslmes/mesXslMixerMaterialKindCfg/exportXls',
|
||||
queryById = '/xslmes/mesXslMixerMaterialKindCfg/queryById',
|
||||
}
|
||||
|
||||
export const list = (params) => defHttp.get({ url: Api.list, params });
|
||||
|
||||
export const queryById = (params) => defHttp.get({ url: Api.queryById, params });
|
||||
|
||||
export const expandLines = (params) => defHttp.get({ url: Api.expandLines, params });
|
||||
|
||||
export const addBatch = (params) => defHttp.post({ url: Api.addBatch, params }, { successMessageMode: 'none' });
|
||||
|
||||
export const deleteOne = (params, handleSuccess) =>
|
||||
defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => handleSuccess());
|
||||
|
||||
export const batchDelete = (params, handleSuccess) =>
|
||||
defHttp.delete({ url: Api.deleteBatch, params }, { joinParamsToUrl: true }).then(() => handleSuccess());
|
||||
|
||||
export const saveOrUpdate = (params, isUpdate) => {
|
||||
const url = isUpdate ? Api.edit : Api.save;
|
||||
return defHttp.post({ url, params }, { successMessageMode: 'none' });
|
||||
};
|
||||
|
||||
export const getExportUrl = Api.exportXls;
|
||||
export const getImportUrl = Api.importExcel;
|
||||
@@ -0,0 +1,156 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
import { JVxeColumn, JVxeTypes } from '/@/components/jeecg/JVxeTable/types';
|
||||
import { list as dictList } from '/@/views/system/dict/dict.api';
|
||||
import { loadTreeData } from '/@/api/common/api';
|
||||
|
||||
export const SOURCE_TYPE_OPTIONS = [
|
||||
{ label: '数据字典', value: 'dict' },
|
||||
{ label: '分类字典', value: 'category' },
|
||||
];
|
||||
|
||||
export const sourceTypeTextMap: Record<string, string> = {
|
||||
dict: '数据字典',
|
||||
category: '分类字典',
|
||||
};
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: '种类键值', align: 'center', dataIndex: 'kindKey', width: 120 },
|
||||
{ title: '种类名称', align: 'center', dataIndex: 'kindName', width: 140 },
|
||||
{
|
||||
title: '数据源',
|
||||
align: 'center',
|
||||
dataIndex: 'sourceType',
|
||||
width: 100,
|
||||
customRender: ({ text }) => sourceTypeTextMap[String(text || '')] || text || '',
|
||||
},
|
||||
{ title: '根名称', align: 'center', dataIndex: 'sourceRootName', width: 140 },
|
||||
{ title: '对应分类', align: 'center', dataIndex: 'categoryRefName', width: 140 },
|
||||
{ title: '优先级', align: 'center', dataIndex: 'priority', width: 80 },
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 80, defaultHidden: true },
|
||||
{ title: '创建时间', align: 'center', dataIndex: 'createTime', width: 165 },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '种类键值', field: 'kindKey', component: 'Input', colProps: { span: 6 } },
|
||||
{ label: '种类名称', field: 'kindName', component: 'Input', colProps: { span: 6 } },
|
||||
{
|
||||
label: '数据源',
|
||||
field: 'sourceType',
|
||||
component: 'Select',
|
||||
componentProps: { options: SOURCE_TYPE_OPTIONS, allowClear: true },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
{ label: '根编码', field: 'sourceRootCode', component: 'Input', colProps: { span: 6 } },
|
||||
];
|
||||
|
||||
export const batchFormSchema: FormSchema[] = [
|
||||
{
|
||||
label: '数据源',
|
||||
field: 'sourceType',
|
||||
component: 'Select',
|
||||
required: true,
|
||||
defaultValue: 'category',
|
||||
componentProps: { options: SOURCE_TYPE_OPTIONS },
|
||||
},
|
||||
{
|
||||
label: '数据字典',
|
||||
field: 'dictRootCode',
|
||||
component: 'ApiSelect',
|
||||
required: true,
|
||||
ifShow: ({ values }) => values.sourceType === 'dict',
|
||||
componentProps: {
|
||||
api: () => dictList({ pageNo: 1, pageSize: 500 }),
|
||||
resultField: 'records',
|
||||
labelField: 'dictName',
|
||||
valueField: 'dictCode',
|
||||
showSearch: true,
|
||||
placeholder: '请选择数据字典根',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '分类字典',
|
||||
field: 'categoryRootCode',
|
||||
component: 'ApiSelect',
|
||||
required: true,
|
||||
ifShow: ({ values }) => values.sourceType === 'category',
|
||||
componentProps: {
|
||||
api: loadTreeData,
|
||||
params: { async: false, pcode: '0' },
|
||||
resultField: '',
|
||||
labelField: 'title',
|
||||
valueField: 'code',
|
||||
showSearch: true,
|
||||
placeholder: '请选择分类字典根',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const editFormSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{ label: '', field: 'sourceType', component: 'Input', show: false },
|
||||
{ label: '', field: 'sourceRootCode', component: 'Input', show: false },
|
||||
{ label: '', field: 'sourceRootName', component: 'Input', show: false },
|
||||
{ label: '', field: 'categoryRefId', component: 'Input', show: false },
|
||||
{ label: '', field: 'categoryRefCode', component: 'Input', show: false },
|
||||
{
|
||||
label: '种类键值',
|
||||
field: 'kindKey',
|
||||
component: 'Input',
|
||||
componentProps: { disabled: true },
|
||||
},
|
||||
{
|
||||
label: '种类名称',
|
||||
field: 'kindName',
|
||||
component: 'Input',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: '对应分类',
|
||||
field: 'categoryRefName',
|
||||
component: 'Input',
|
||||
componentProps: { disabled: true },
|
||||
},
|
||||
{
|
||||
label: '优先级',
|
||||
field: 'priority',
|
||||
component: 'InputNumber',
|
||||
required: true,
|
||||
componentProps: { min: 0, precision: 0, style: { width: '100%' } },
|
||||
},
|
||||
{
|
||||
label: '租户ID',
|
||||
field: 'tenantId',
|
||||
component: 'InputNumber',
|
||||
componentProps: { disabled: true, style: { width: '100%' } },
|
||||
},
|
||||
];
|
||||
|
||||
export const batchJVxeColumns: JVxeColumn[] = [
|
||||
{ title: '', key: 'categoryRefId', type: JVxeTypes.hidden },
|
||||
{ title: '', key: 'categoryRefCode', type: JVxeTypes.hidden },
|
||||
{ title: '', key: 'sourceType', type: JVxeTypes.hidden },
|
||||
{ title: '', key: 'sourceRootCode', type: JVxeTypes.hidden },
|
||||
{ title: '', key: 'sourceRootName', type: JVxeTypes.hidden },
|
||||
{ title: '', key: 'tenantId', type: JVxeTypes.hidden },
|
||||
{ title: '种类键值', key: 'kindKey', type: JVxeTypes.normal, width: 200, minWidth: 160, disabled: true },
|
||||
{ title: '种类名称', key: 'kindName', type: JVxeTypes.input, width: 180, minWidth: 140 },
|
||||
{ title: '对应分类', key: 'categoryRefName', type: JVxeTypes.normal, width: 180, minWidth: 140, disabled: true },
|
||||
{
|
||||
title: '优先级',
|
||||
key: 'priority',
|
||||
type: JVxeTypes.inputNumber,
|
||||
width: 110,
|
||||
minWidth: 90,
|
||||
align: 'center',
|
||||
validateRules: [{ required: true, message: '请输入优先级' }],
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
kindKey: { title: '种类键值', order: 0, view: 'text' },
|
||||
kindName: { title: '种类名称', order: 1, view: 'text' },
|
||||
sourceType: { title: '数据源', order: 2, view: 'list', enum: SOURCE_TYPE_OPTIONS },
|
||||
sourceRootCode: { title: '根编码', order: 3, view: 'text' },
|
||||
categoryRefName: { title: '对应分类', order: 4, view: 'text' },
|
||||
priority: { title: '优先级', order: 5, view: 'number' },
|
||||
};
|
||||
@@ -0,0 +1,162 @@
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-auth="'xslmes:mes_xsl_mixer_material_kind_cfg:add'"
|
||||
@click="handleBatchAdd"
|
||||
preIcon="ant-design:plus-outlined"
|
||||
>
|
||||
新增
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-auth="'xslmes:mes_xsl_mixer_material_kind_cfg:exportXls'"
|
||||
preIcon="ant-design:export-outlined"
|
||||
@click="onExportXls"
|
||||
>
|
||||
导出
|
||||
</a-button>
|
||||
<j-upload-button
|
||||
type="primary"
|
||||
v-auth="'xslmes:mes_xsl_mixer_material_kind_cfg: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="'xslmes:mes_xsl_mixer_material_kind_cfg:deleteBatch'">
|
||||
批量操作
|
||||
<Icon icon="mdi:chevron-down" />
|
||||
</a-button>
|
||||
</a-dropdown>
|
||||
<super-query :config="superQueryConfig" @search="handleSuperQuery" />
|
||||
</template>
|
||||
<template #action="{ record }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: 'xslmes:mes_xsl_mixer_material_kind_cfg:edit',
|
||||
},
|
||||
]"
|
||||
:dropDownActions="getDropDownAction(record)"
|
||||
/>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<MesXslMixerMaterialKindCfgBatchModal @register="registerBatchModal" @success="handleSuccess" />
|
||||
<MesXslMixerMaterialKindCfgEditModal @register="registerEditModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslMixerMaterialKindCfg" setup>
|
||||
import { reactive } from 'vue';
|
||||
import { BasicTable, TableAction } from '/@/components/Table';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import Icon from '/@/components/Icon';
|
||||
import MesXslMixerMaterialKindCfgBatchModal from './components/MesXslMixerMaterialKindCfgBatchModal.vue';
|
||||
import MesXslMixerMaterialKindCfgEditModal from './components/MesXslMixerMaterialKindCfgEditModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema } from './MesXslMixerMaterialKindCfg.data';
|
||||
import { batchDelete, deleteOne, getExportUrl, getImportUrl, list } from './MesXslMixerMaterialKindCfg.api';
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const [registerBatchModal, { openModal: openBatchModal }] = useModal();
|
||||
const [registerEditModal, { openModal: openEditModal }] = useModal();
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '密炼物料种类配置',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
labelWidth: 100,
|
||||
autoSubmitOnEnter: true,
|
||||
showAdvancedButton: true,
|
||||
},
|
||||
actionColumn: {
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { customRender: 'action' },
|
||||
},
|
||||
beforeFetch: (params) => Object.assign(params, queryParam),
|
||||
},
|
||||
exportConfig: {
|
||||
name: '密炼物料种类配置',
|
||||
url: getExportUrl,
|
||||
params: queryParam,
|
||||
},
|
||||
importConfig: {
|
||||
url: getImportUrl,
|
||||
success: handleSuccess,
|
||||
},
|
||||
});
|
||||
|
||||
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
|
||||
const superQueryConfig = reactive(superQuerySchema);
|
||||
|
||||
function handleSuperQuery(params) {
|
||||
Object.keys(params).forEach((k) => {
|
||||
queryParam[k] = params[k];
|
||||
});
|
||||
reload();
|
||||
}
|
||||
|
||||
function handleBatchAdd() {
|
||||
openBatchModal(true, { showFooter: true });
|
||||
}
|
||||
|
||||
function handleEdit(record: Recordable) {
|
||||
openEditModal(true, { record, isUpdate: true, showFooter: true });
|
||||
}
|
||||
|
||||
function handleDetail(record: Recordable) {
|
||||
openEditModal(true, { record, isUpdate: true, showFooter: false });
|
||||
}
|
||||
|
||||
async function handleDelete(record) {
|
||||
await deleteOne({ id: record.id }, handleSuccess);
|
||||
}
|
||||
|
||||
async function batchHandleDelete() {
|
||||
await batchDelete({ ids: selectedRowKeys.value.join(',') }, handleSuccess);
|
||||
}
|
||||
|
||||
function handleSuccess() {
|
||||
selectedRowKeys.value = [];
|
||||
reload();
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [
|
||||
{
|
||||
label: '详情',
|
||||
onClick: handleDetail.bind(null, record),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
placement: 'topLeft',
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_mixer_material_kind_cfg:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,189 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
v-bind="$attrs"
|
||||
destroyOnClose
|
||||
title="新增密炼物料种类配置"
|
||||
:width="'92%'"
|
||||
:defaultFullscreen="true"
|
||||
wrapClassName="mes-xsl-mixer-material-kind-batch-modal"
|
||||
@register="registerModal"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<div class="batch-modal-body">
|
||||
<BasicForm @register="registerForm">
|
||||
<template #expandAction>
|
||||
<a-button type="primary" :loading="expanding" @click="handleExpand">带出明细</a-button>
|
||||
</template>
|
||||
</BasicForm>
|
||||
<a-divider orientation="left">种类配置明细</a-divider>
|
||||
<div class="batch-table-wrap">
|
||||
<JVxeTable
|
||||
v-if="tableReady"
|
||||
ref="lineTableRef"
|
||||
toolbar
|
||||
row-number
|
||||
rowSelection
|
||||
keep-source
|
||||
:insert-row="false"
|
||||
:max-height="tableMaxHeight"
|
||||
:loading="lineLoading"
|
||||
:columns="batchJVxeColumns"
|
||||
:dataSource="lineDataSource"
|
||||
:toolbar-config="{ btn: ['remove'] }"
|
||||
:add-btn-cfg="{ enabled: false }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { BasicModal, useModalInner } 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 { useUserStore } from '/@/store/modules/user';
|
||||
import { batchFormSchema, batchJVxeColumns } from '../MesXslMixerMaterialKindCfg.data';
|
||||
import { addBatch, expandLines } from '../MesXslMixerMaterialKindCfg.api';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const { createMessage } = useMessage();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const tableReady = ref(false);
|
||||
const lineLoading = ref(false);
|
||||
const expanding = ref(false);
|
||||
const lineDataSource = ref<Recordable[]>([]);
|
||||
const lineTableRef = ref<JVxeTableInstance>();
|
||||
const tableMaxHeight = ref(560);
|
||||
|
||||
function refreshTableHeight() {
|
||||
// 预留顶部表单、标题与底部按钮区域,表格尽量占满可视区
|
||||
tableMaxHeight.value = Math.max(420, window.innerHeight - 300);
|
||||
}
|
||||
|
||||
const [registerForm, { resetFields, validate, getFieldsValue }] = useForm({
|
||||
labelWidth: 110,
|
||||
schemas: [
|
||||
...batchFormSchema,
|
||||
{
|
||||
label: '',
|
||||
field: 'expandAction',
|
||||
component: 'Input',
|
||||
slot: 'expandAction',
|
||||
colProps: { span: 24 },
|
||||
},
|
||||
],
|
||||
showActionButtonGroup: false,
|
||||
baseColProps: { span: 12 },
|
||||
});
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async () => {
|
||||
tableReady.value = false;
|
||||
lineDataSource.value = [];
|
||||
refreshTableHeight();
|
||||
await resetFields();
|
||||
setModalProps({ confirmLoading: false, showCancelBtn: true, showOkBtn: true });
|
||||
tableReady.value = true;
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
refreshTableHeight();
|
||||
window.addEventListener('resize', refreshTableHeight);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', refreshTableHeight);
|
||||
});
|
||||
|
||||
function resolveTenantId() {
|
||||
const tenant = userStore.getTenant;
|
||||
if (tenant == null || tenant === '') {
|
||||
return undefined;
|
||||
}
|
||||
const num = Number(tenant);
|
||||
return Number.isNaN(num) ? undefined : num;
|
||||
}
|
||||
|
||||
function resolveSourceRootCode(values: Recordable) {
|
||||
if (values.sourceType === 'dict') {
|
||||
return values.dictRootCode;
|
||||
}
|
||||
return values.categoryRootCode;
|
||||
}
|
||||
|
||||
async function handleExpand() {
|
||||
try {
|
||||
const values = await validate();
|
||||
const sourceRootCode = resolveSourceRootCode(values);
|
||||
if (!sourceRootCode) {
|
||||
createMessage.warning(values.sourceType === 'dict' ? '请选择数据字典根' : '请选择分类字典根');
|
||||
return;
|
||||
}
|
||||
expanding.value = true;
|
||||
const tenantId = resolveTenantId();
|
||||
const raw = await expandLines({
|
||||
sourceType: values.sourceType,
|
||||
sourceRootCode,
|
||||
tenantId,
|
||||
});
|
||||
const rows = Array.isArray(raw) ? raw : (raw as Recordable)?.result ?? [];
|
||||
if (!rows.length) {
|
||||
createMessage.warning('未带出任何明细,可能均已配置');
|
||||
return;
|
||||
}
|
||||
const mergedTenant = tenantId ?? rows[0]?.tenantId;
|
||||
lineDataSource.value = rows.map((row) => ({
|
||||
...row,
|
||||
tenantId: mergedTenant,
|
||||
}));
|
||||
createMessage.success(`已带出 ${rows.length} 条明细`);
|
||||
} catch (e: any) {
|
||||
createMessage.error(e?.message || '带出明细失败');
|
||||
} finally {
|
||||
expanding.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const lineRef = lineTableRef.value as any;
|
||||
const tableData = (lineRef?.getTableData?.() || lineDataSource.value || []) as Recordable[];
|
||||
if (!tableData.length) {
|
||||
createMessage.warning('请先选择根字典/分类并带出明细');
|
||||
return;
|
||||
}
|
||||
const errMap = await lineRef?.validateTable?.();
|
||||
if (errMap) {
|
||||
createMessage.warning('请完善明细中的种类名称与优先级');
|
||||
return;
|
||||
}
|
||||
const tenantId = resolveTenantId();
|
||||
const payload = tableData.map((row) => ({
|
||||
...row,
|
||||
tenantId: row.tenantId ?? tenantId,
|
||||
}));
|
||||
try {
|
||||
setModalProps({ confirmLoading: true });
|
||||
await addBatch(payload);
|
||||
createMessage.success('新增成功');
|
||||
closeModal();
|
||||
emit('success');
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.batch-modal-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: calc(100vh - 200px);
|
||||
}
|
||||
|
||||
.batch-table-wrap {
|
||||
flex: 1;
|
||||
min-height: 420px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,52 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" destroyOnClose :title="title" width="640px" @register="registerModal" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, unref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { editFormSchema } from '../MesXslMixerMaterialKindCfg.data';
|
||||
import { saveOrUpdate } from '../MesXslMixerMaterialKindCfg.api';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const { createMessage } = useMessage();
|
||||
const isUpdate = ref(true);
|
||||
const isDetail = ref(false);
|
||||
|
||||
const [registerForm, { resetFields, setFieldsValue, validate, setProps }] = useForm({
|
||||
labelWidth: 110,
|
||||
schemas: editFormSchema,
|
||||
showActionButtonGroup: false,
|
||||
baseColProps: { span: 24 },
|
||||
});
|
||||
|
||||
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 (data?.record) {
|
||||
await setFieldsValue({ ...data.record });
|
||||
}
|
||||
setProps({ disabled: !data?.showFooter });
|
||||
});
|
||||
|
||||
const title = computed(() => (!unref(isUpdate) ? '新增' : unref(isDetail) ? '详情' : '编辑'));
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate();
|
||||
setModalProps({ confirmLoading: true });
|
||||
await saveOrUpdate(values, true);
|
||||
createMessage.success('编辑成功');
|
||||
closeModal();
|
||||
emit('success');
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user