更新VSCode配置,启用Maven支持,设置Java 17环境,调整MybatisPlusSaasConfig以开启系统租户控制并添加新租户表。更新pom.xml以包含新模块jeecg-module-xslmes,优化Vue3环境配置以统一API路径,增强代理设置以支持完整的后端路径。修复useForm钩子中的字段重置逻辑,改进axios配置以处理相对URL的上下文路径问题。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslWarehouse/list',
|
||||
queryById = '/xslmes/mesXslWarehouse/queryById',
|
||||
save = '/xslmes/mesXslWarehouse/add',
|
||||
edit = '/xslmes/mesXslWarehouse/edit',
|
||||
updateStatus = '/xslmes/mesXslWarehouse/updateStatus',
|
||||
deleteOne = '/xslmes/mesXslWarehouse/delete',
|
||||
deleteBatch = '/xslmes/mesXslWarehouse/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslWarehouse/importExcel',
|
||||
exportXls = '/xslmes/mesXslWarehouse/exportXls',
|
||||
}
|
||||
|
||||
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 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 });
|
||||
};
|
||||
|
||||
/** 启用/停用:status 0 启用 1 停用(字典 xslmes_unit_status) */
|
||||
export const updateStatus = (params: { id: string; status: string }, handleSuccess?: () => void) => {
|
||||
return defHttp.post({ url: Api.updateStatus, params }, { joinParamsToUrl: true }).then(() => {
|
||||
handleSuccess?.();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
|
||||
/** 分类字典 code:二楼-客户库(与后端 MesXslWarehouseCategory 一致) */
|
||||
export const WH_CATEGORY_CUSTOMER_CODE = 'XSLMES_WH_F2_KH';
|
||||
/** 分类字典 code:二楼-供应商库 */
|
||||
export const WH_CATEGORY_SUPPLIER_CODE = 'XSLMES_WH_F2_GYS';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: 'ID', align: 'center', dataIndex: 'id', width: 280, ellipsis: true, defaultHidden: true },
|
||||
{ title: '仓库编码', align: 'center', dataIndex: 'warehouseCode', width: 120 },
|
||||
{ title: '仓库名称', align: 'center', dataIndex: 'warehouseName', width: 160 },
|
||||
{ title: '仓库分类', align: 'center', dataIndex: 'warehouseCategory_dictText', width: 120 },
|
||||
{ title: 'ERP编码', align: 'center', dataIndex: 'erpCode', width: 120 },
|
||||
{ title: '客户简称', align: 'center', dataIndex: 'customerShortName', width: 120, ellipsis: true },
|
||||
{ title: '供应商简称', align: 'center', dataIndex: 'supplierShortName', width: 120 },
|
||||
{ title: '状态', align: 'center', dataIndex: 'status_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),
|
||||
},
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '仓库编码', field: 'warehouseCode', component: 'JInput', colProps: { span: 6 } },
|
||||
{ label: '仓库名称', field: 'warehouseName', component: 'JInput', colProps: { span: 6 } },
|
||||
{
|
||||
label: '仓库分类',
|
||||
field: 'warehouseCategory',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'sys_category,name,id' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_unit_status' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
];
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '仓库编码',
|
||||
field: 'warehouseCode',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入仓库编码' },
|
||||
},
|
||||
{
|
||||
label: '仓库名称',
|
||||
field: 'warehouseName',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入仓库名称' },
|
||||
},
|
||||
{
|
||||
label: '仓库分类',
|
||||
field: 'warehouseCategory',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
slot: 'warehouseCategoryField',
|
||||
},
|
||||
{
|
||||
label: 'ERP编码',
|
||||
field: 'erpCode',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入ERP编码' },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_unit_status', placeholder: '请选择状态' },
|
||||
},
|
||||
{ label: '客户ID', field: 'customerId', component: 'Input', show: false },
|
||||
{
|
||||
label: '客户简称',
|
||||
field: 'customerShortName',
|
||||
component: 'Input',
|
||||
slot: 'customerPicker',
|
||||
ifShow: false,
|
||||
},
|
||||
{ label: '供应商ID', field: 'supplierId', component: 'Input', show: false },
|
||||
{
|
||||
label: '供应商简称',
|
||||
field: 'supplierShortName',
|
||||
component: 'Input',
|
||||
slot: 'supplierPicker',
|
||||
ifShow: false,
|
||||
},
|
||||
{
|
||||
label: '租户ID',
|
||||
field: 'tenantId',
|
||||
component: 'InputNumber',
|
||||
componentProps: { placeholder: '租户ID,可空', style: { width: '100%' } },
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
warehouseCode: { title: '仓库编码', order: 0, view: 'text' },
|
||||
warehouseName: { title: '仓库名称', order: 1, view: 'text' },
|
||||
warehouseCategory: { title: '仓库分类', order: 2, view: 'list', dictCode: 'sys_category,name,id' },
|
||||
status: { title: '状态', order: 3, view: 'list', dictCode: 'xslmes_unit_status' },
|
||||
};
|
||||
@@ -0,0 +1,651 @@
|
||||
<template>
|
||||
<div class="mes-xsl-warehouse-page">
|
||||
<div class="mes-xsl-warehouse-layout">
|
||||
<div class="mes-xsl-warehouse-sider-col">
|
||||
<aside
|
||||
:class="['mes-xsl-warehouse-sider', { 'is-collapsed': siderCollapsed, 'is-dragging': siderDragging }]"
|
||||
:style="siderAsideStyle"
|
||||
>
|
||||
<Card class="mes-xsl-warehouse-sider-card" size="small" title="仓库分类" :bordered="true">
|
||||
<template #extra>
|
||||
<a-space v-show="!siderCollapsed" size="small" class="mes-xsl-warehouse-sider-extra">
|
||||
<a-button type="link" size="small" v-auth="'xslmes:mes_xsl_warehouse_category:add'" @click="handleAddCategory">新增</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
v-auth="'xslmes:mes_xsl_warehouse_category:edit'"
|
||||
:disabled="!categorySelectedId"
|
||||
@click="handleEditCategory"
|
||||
>
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
danger
|
||||
v-auth="'xslmes:mes_xsl_warehouse_category:delete'"
|
||||
:disabled="!categorySelectedId"
|
||||
@click="handleDeleteCategory"
|
||||
>
|
||||
删除
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
<Spin :spinning="treeLoading">
|
||||
<BasicTree
|
||||
:treeData="categoryTreeData"
|
||||
:selectedKeys="selectedKeys"
|
||||
defaultExpandLevel="2"
|
||||
@update:selectedKeys="onTreeSelect"
|
||||
/>
|
||||
</Spin>
|
||||
</Card>
|
||||
</aside>
|
||||
<!-- 分隔条:贴在侧栏右缘,三角把手 + 拖拽改宽度(与单位管理一致) -->
|
||||
<div
|
||||
class="mes-xsl-warehouse-resizer"
|
||||
:class="{ 'is-dragging': siderDragging }"
|
||||
role="separator"
|
||||
aria-orientation="vertical"
|
||||
:aria-valuenow="siderCollapsed ? 0 : siderWidth"
|
||||
:aria-valuemin="SIDER_MIN"
|
||||
:aria-valuemax="SIDER_MAX"
|
||||
tabindex="0"
|
||||
@pointerdown="onSiderResizerPointerDown"
|
||||
@keydown.left.prevent="nudgeSiderWidth(-16)"
|
||||
@keydown.right.prevent="nudgeSiderWidth(16)"
|
||||
>
|
||||
<a-tooltip :title="siderCollapsed ? '展开(可向右拖拽)' : '收起(点击)或左右拖拽调整宽度'">
|
||||
<span class="mes-xsl-warehouse-resizer-knob" aria-hidden="true">
|
||||
<span class="mes-xsl-warehouse-tri" :class="{ 'mes-xsl-warehouse-tri--collapsed': siderCollapsed }" />
|
||||
</span>
|
||||
</a-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mes-xsl-warehouse-main">
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_warehouse:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_warehouse:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
|
||||
<j-upload-button type="primary" v-auth="'xslmes:mes_xsl_warehouse: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_warehouse:deleteBatch'">
|
||||
批量操作
|
||||
<Icon icon="mdi:chevron-down" />
|
||||
</a-button>
|
||||
</a-dropdown>
|
||||
<super-query :config="superQueryConfig" @search="handleSuperQuery" />
|
||||
</template>
|
||||
<template #action="{ record }">
|
||||
<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
|
||||
</template>
|
||||
</BasicTable>
|
||||
</div>
|
||||
</div>
|
||||
<MesXslWarehouseModal @register="registerModal" @success="handleSuccess" />
|
||||
<MesXslWarehouseSysCategoryModal @register="registerCategoryModal" @success="onCategorySuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslWarehouse" setup>
|
||||
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue';
|
||||
import { Card, Spin } from 'ant-design-vue';
|
||||
import { BasicTable, TableAction } from '/@/components/Table';
|
||||
import { BasicTree } from '/@/components/Tree';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import MesXslWarehouseModal from './components/MesXslWarehouseModal.vue';
|
||||
import MesXslWarehouseSysCategoryModal from './components/MesXslWarehouseSysCategoryModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema, WH_CATEGORY_CUSTOMER_CODE, WH_CATEGORY_SUPPLIER_CODE } from './MesXslWarehouse.data';
|
||||
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, updateStatus } from './MesXslWarehouse.api';
|
||||
import { loadTreeData as loadCategoryTreeRoot } from '/@/views/system/category/category.api';
|
||||
import {
|
||||
fetchWarehouseCategoryRoot,
|
||||
deleteWarehouseSysCategory,
|
||||
WAREHOUSE_CATEGORY_ROOT_CODE,
|
||||
} from './MesXslWarehouseSysCategory.api';
|
||||
import Icon from '/@/components/Icon';
|
||||
import type { KeyType } from '/@/components/Tree/src/types/tree';
|
||||
import type { Recordable } from '/@/types/global';
|
||||
|
||||
const { createMessage, createConfirm } = useMessage();
|
||||
|
||||
const TREE_ALL = 'ALL';
|
||||
|
||||
/** 侧栏宽度限制(px),与单位管理一致 */
|
||||
const SIDER_MIN = 200;
|
||||
const SIDER_MAX = 560;
|
||||
const SIDER_DEFAULT = 260;
|
||||
const SIDER_DRAG_THRESHOLD = 5;
|
||||
const SIDER_EXPAND_DRAG = 12;
|
||||
|
||||
const siderCollapsed = ref(false);
|
||||
const siderWidth = ref(SIDER_DEFAULT);
|
||||
const siderDragging = ref(false);
|
||||
const treeLoading = ref(false);
|
||||
|
||||
const siderAsideStyle = computed(() => ({
|
||||
width: siderCollapsed.value ? '0px' : `${siderWidth.value}px`,
|
||||
}));
|
||||
|
||||
let siderDragStartX = 0;
|
||||
let siderDragStartW = 0;
|
||||
let siderDragMaxDelta = 0;
|
||||
let siderDragCollapsedStart = false;
|
||||
let siderDragPointerId: number | null = null;
|
||||
let siderDragEl: HTMLElement | null = null;
|
||||
|
||||
function toggleSider() {
|
||||
siderCollapsed.value = !siderCollapsed.value;
|
||||
}
|
||||
|
||||
function clampSiderW(w: number) {
|
||||
return Math.min(SIDER_MAX, Math.max(SIDER_MIN, w));
|
||||
}
|
||||
|
||||
function nudgeSiderWidth(delta: number) {
|
||||
if (siderCollapsed.value) {
|
||||
if (delta > 0) {
|
||||
siderCollapsed.value = false;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
siderWidth.value = clampSiderW(siderWidth.value + delta);
|
||||
}
|
||||
|
||||
function onSiderResizerPointerMove(e: PointerEvent) {
|
||||
if (siderDragPointerId == null || e.pointerId !== siderDragPointerId) return;
|
||||
const dx = e.clientX - siderDragStartX;
|
||||
siderDragMaxDelta = Math.max(siderDragMaxDelta, Math.abs(dx));
|
||||
|
||||
if (siderDragCollapsedStart) {
|
||||
if (dx >= SIDER_EXPAND_DRAG) {
|
||||
siderCollapsed.value = false;
|
||||
siderWidth.value = clampSiderW(dx);
|
||||
siderDragStartX = e.clientX;
|
||||
siderDragStartW = siderWidth.value;
|
||||
siderDragCollapsedStart = false;
|
||||
}
|
||||
} else {
|
||||
siderWidth.value = clampSiderW(siderDragStartW + dx);
|
||||
}
|
||||
}
|
||||
|
||||
function endSiderDrag(e: PointerEvent) {
|
||||
if (siderDragPointerId == null || e.pointerId !== siderDragPointerId) return;
|
||||
if (siderDragEl) {
|
||||
try {
|
||||
siderDragEl.releasePointerCapture(siderDragPointerId);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
document.removeEventListener('pointermove', onSiderResizerPointerMove);
|
||||
document.removeEventListener('pointerup', endSiderDrag);
|
||||
document.removeEventListener('pointercancel', endSiderDrag);
|
||||
document.body.style.cursor = '';
|
||||
document.body.style.userSelect = '';
|
||||
siderDragging.value = false;
|
||||
siderDragPointerId = null;
|
||||
siderDragEl = null;
|
||||
|
||||
if (siderDragMaxDelta < SIDER_DRAG_THRESHOLD) {
|
||||
toggleSider();
|
||||
}
|
||||
}
|
||||
|
||||
function onSiderResizerPointerDown(e: PointerEvent) {
|
||||
if (e.button !== 0) return;
|
||||
e.preventDefault();
|
||||
siderDragEl = e.currentTarget as HTMLElement;
|
||||
siderDragPointerId = e.pointerId;
|
||||
siderDragStartX = e.clientX;
|
||||
siderDragStartW = siderCollapsed.value ? 0 : siderWidth.value;
|
||||
siderDragMaxDelta = 0;
|
||||
siderDragCollapsedStart = siderCollapsed.value;
|
||||
siderDragging.value = true;
|
||||
document.body.style.cursor = 'col-resize';
|
||||
document.body.style.userSelect = 'none';
|
||||
try {
|
||||
siderDragEl.setPointerCapture(e.pointerId);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
document.addEventListener('pointermove', onSiderResizerPointerMove);
|
||||
document.addEventListener('pointerup', endSiderDrag);
|
||||
document.addEventListener('pointercancel', endSiderDrag);
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('pointermove', onSiderResizerPointerMove);
|
||||
document.removeEventListener('pointerup', endSiderDrag);
|
||||
document.removeEventListener('pointercancel', endSiderDrag);
|
||||
document.body.style.cursor = '';
|
||||
document.body.style.userSelect = '';
|
||||
});
|
||||
|
||||
/** 分类字典异步树根(pcode=XSLMES_WH 下的子树:一楼库、二楼仓库…) */
|
||||
const rawWarehouseCategoryTree = ref<Recordable[]>([]);
|
||||
/** 根节点 id(编码 XSLMES_WH),新增「顶级子节点」时用 */
|
||||
const warehouseCategoryRootId = ref('');
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const selectedKeys = ref<KeyType[]>([TREE_ALL]);
|
||||
|
||||
const categorySelectedId = computed(() => {
|
||||
const k = selectedKeys.value[0];
|
||||
if (!k || k === TREE_ALL) return '';
|
||||
return String(k);
|
||||
});
|
||||
|
||||
function mapCategoryTreeNodes(nodes: Recordable[]): Recordable[] {
|
||||
return (nodes || []).map((n) => ({
|
||||
key: n.key,
|
||||
title: n.title,
|
||||
children: n.children?.length ? mapCategoryTreeNodes(n.children as Recordable[]) : undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
const categoryTreeData = computed(() => [
|
||||
{
|
||||
key: TREE_ALL,
|
||||
title: '全部分类',
|
||||
children: mapCategoryTreeNodes(rawWarehouseCategoryTree.value || []),
|
||||
},
|
||||
]);
|
||||
|
||||
function collectLeafKeysUnder(node: Recordable): string[] {
|
||||
const children = node.children as Recordable[] | undefined;
|
||||
if (!children?.length) {
|
||||
return [String(node.key)];
|
||||
}
|
||||
return children.flatMap((ch) => collectLeafKeysUnder(ch));
|
||||
}
|
||||
|
||||
function findNodeByKey(nodes: Recordable[], key: string): Recordable | null {
|
||||
for (const n of nodes) {
|
||||
if (String(n.key) === key) {
|
||||
return n;
|
||||
}
|
||||
const nested = n.children as Recordable[] | undefined;
|
||||
if (nested?.length) {
|
||||
const found = findNodeByKey(nested, key);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function loadCategoryTree() {
|
||||
treeLoading.value = true;
|
||||
try {
|
||||
const root = await fetchWarehouseCategoryRoot();
|
||||
warehouseCategoryRootId.value = root?.id != null ? String(root.id) : '';
|
||||
const res = await loadCategoryTreeRoot({ async: false, pcode: 'XSLMES_WH' });
|
||||
rawWarehouseCategoryTree.value = Array.isArray(res) ? res : [];
|
||||
if (!warehouseCategoryRootId.value || !rawWarehouseCategoryTree.value.length) {
|
||||
createMessage.warning('未加载到仓库分类树,请确认已执行库脚本并已在「分类字典」中维护根节点 XSLMES_WH。');
|
||||
}
|
||||
} catch {
|
||||
warehouseCategoryRootId.value = '';
|
||||
rawWarehouseCategoryTree.value = [];
|
||||
createMessage.warning('加载分类字典失败,请检查分类根编码 XSLMES_WH 是否存在。');
|
||||
} finally {
|
||||
treeLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
const [registerCategoryModal, { openModal: openCategoryModal }] = useModal();
|
||||
|
||||
function handleAddCategory() {
|
||||
const rootId = warehouseCategoryRootId.value;
|
||||
if (!rootId) {
|
||||
createMessage.warning('未找到仓库分类根节点,请确认分类字典中存在编码「XSLMES_WH」');
|
||||
return;
|
||||
}
|
||||
const sel = categorySelectedId.value;
|
||||
const parentId = sel || rootId;
|
||||
openCategoryModal(true, { isUpdate: false, parentId });
|
||||
}
|
||||
|
||||
function handleEditCategory() {
|
||||
const id = categorySelectedId.value;
|
||||
if (!id) {
|
||||
createMessage.warning('请先选择左侧分类');
|
||||
return;
|
||||
}
|
||||
openCategoryModal(true, { isUpdate: true, record: { id } });
|
||||
}
|
||||
|
||||
async function handleDeleteCategory() {
|
||||
const id = categorySelectedId.value;
|
||||
if (!id) {
|
||||
createMessage.warning('请先选择要删除的分类');
|
||||
return;
|
||||
}
|
||||
if (id === warehouseCategoryRootId.value) {
|
||||
createMessage.warning('根分类不可删除');
|
||||
return;
|
||||
}
|
||||
let code = '';
|
||||
try {
|
||||
const cat = await defHttp.get<Recordable>({ url: '/sys/category/queryById', params: { id } });
|
||||
code = cat?.code != null ? String(cat.code) : '';
|
||||
} catch {
|
||||
createMessage.error('无法读取分类信息');
|
||||
return;
|
||||
}
|
||||
if (code === WAREHOUSE_CATEGORY_ROOT_CODE) {
|
||||
createMessage.warning('根分类不可删除');
|
||||
return;
|
||||
}
|
||||
if (code === WH_CATEGORY_CUSTOMER_CODE || code === WH_CATEGORY_SUPPLIER_CODE) {
|
||||
createMessage.warning('「客户库」「供应商库」为业务保留分类,不建议删除');
|
||||
return;
|
||||
}
|
||||
createConfirm({
|
||||
iconType: 'warning',
|
||||
title: '确认删除',
|
||||
content: '将删除该节点及其下级分类;已选用这些分类的仓库数据不会自动变更,请确认无业务影响。',
|
||||
onOk: async () => {
|
||||
await deleteWarehouseSysCategory(id);
|
||||
await loadCategoryTree();
|
||||
selectedKeys.value = [TREE_ALL];
|
||||
delete queryParam.warehouseCategory;
|
||||
delete queryParam.warehouseCategory_MultiString;
|
||||
reload();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function onCategorySuccess() {
|
||||
loadCategoryTree();
|
||||
reload();
|
||||
}
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '仓库管理',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
autoSubmitOnEnter: true,
|
||||
showAdvancedButton: true,
|
||||
},
|
||||
actionColumn: {
|
||||
width: 300,
|
||||
fixed: 'right',
|
||||
},
|
||||
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);
|
||||
|
||||
onMounted(async () => {
|
||||
await loadCategoryTree();
|
||||
reload();
|
||||
});
|
||||
|
||||
function onTreeSelect(keys: KeyType[]) {
|
||||
selectedKeys.value = keys;
|
||||
const k = keys[0];
|
||||
delete queryParam.warehouseCategory;
|
||||
delete queryParam.warehouseCategory_MultiString;
|
||||
if (!k || k === TREE_ALL) {
|
||||
reload();
|
||||
return;
|
||||
}
|
||||
const node = findNodeByKey(rawWarehouseCategoryTree.value, String(k));
|
||||
if (!node) {
|
||||
reload();
|
||||
return;
|
||||
}
|
||||
const leafKeys = collectLeafKeysUnder(node);
|
||||
if (leafKeys.length === 1) {
|
||||
queryParam.warehouseCategory = leafKeys[0];
|
||||
} else if (leafKeys.length > 1) {
|
||||
queryParam.warehouseCategory_MultiString = leafKeys.join(',');
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
function handleSuperQuery(params) {
|
||||
Object.keys(params).forEach((k) => {
|
||||
queryParam[k] = params[k];
|
||||
});
|
||||
reload();
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
openModal(true, { isUpdate: false, showFooter: true, record: {} });
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function isRecordEnabled(record: Recordable) {
|
||||
return record.status === '0' || record.status === 0;
|
||||
}
|
||||
|
||||
async function handleToggleStatus(record: Recordable, status: string) {
|
||||
await updateStatus({ id: record.id, status }, handleSuccess);
|
||||
}
|
||||
|
||||
async function batchHandleDelete() {
|
||||
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
|
||||
}
|
||||
|
||||
function handleSuccess() {
|
||||
selectedRowKeys.value = [];
|
||||
reload();
|
||||
}
|
||||
|
||||
function getTableAction(record) {
|
||||
const enabled = isRecordEnabled(record);
|
||||
return [
|
||||
{
|
||||
label: '编辑',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: 'xslmes:mes_xsl_warehouse:edit',
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
ifShow: !enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '0'),
|
||||
auth: 'xslmes:mes_xsl_warehouse:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '停用',
|
||||
ifShow: enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '1'),
|
||||
auth: 'xslmes:mes_xsl_warehouse:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_warehouse:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.mes-xsl-warehouse-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: calc(100vh - 160px);
|
||||
|
||||
:deep(.ant-picker-range) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-layout {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: stretch;
|
||||
gap: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-sider-col {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
flex: 0 0 auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-sider {
|
||||
flex: 0 0 auto;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
transition: width 0.2s ease;
|
||||
|
||||
.mes-xsl-warehouse-sider-extra {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
gap: 0;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
&.is-dragging {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
&.is-collapsed {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-sider-card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
|
||||
|
||||
:deep(.ant-card-head) {
|
||||
min-height: 40px;
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
:deep(.ant-card-body) {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-resizer {
|
||||
flex: 0 0 8px;
|
||||
width: 8px;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
cursor: col-resize;
|
||||
touch-action: none;
|
||||
user-select: none;
|
||||
background: #fafafa;
|
||||
margin-right: 2px;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
&.is-dragging {
|
||||
background: #e6f4ff;
|
||||
}
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-resizer-knob {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 10px;
|
||||
height: 44px;
|
||||
pointer-events: none;
|
||||
background: #fff;
|
||||
border: 1px solid #e8e8e8;
|
||||
border-radius: 2px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-tri {
|
||||
display: block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-style: solid;
|
||||
border-width: 5px 6px 5px 0;
|
||||
border-color: transparent #595959 transparent transparent;
|
||||
margin-left: -1px;
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-tri--collapsed {
|
||||
border-width: 5px 0 5px 6px;
|
||||
border-color: transparent transparent transparent #595959;
|
||||
margin-left: 0;
|
||||
margin-right: -1px;
|
||||
}
|
||||
|
||||
.mes-xsl-warehouse-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import type { Recordable } from '/@/types/global';
|
||||
|
||||
/** 仓库分类字典根编码(与 Flyway / 后端一致) */
|
||||
export const WAREHOUSE_CATEGORY_ROOT_CODE = 'XSLMES_WH';
|
||||
|
||||
/** 按编码查询分类(用于取根节点 id) */
|
||||
export function fetchWarehouseCategoryRoot() {
|
||||
return defHttp.get<Recordable>({
|
||||
url: '/sys/category/loadOne',
|
||||
params: { field: 'code', val: WAREHOUSE_CATEGORY_ROOT_CODE },
|
||||
});
|
||||
}
|
||||
|
||||
export function saveWarehouseSysCategory(data: Recordable) {
|
||||
return defHttp.post({ url: '/sys/category/add', data });
|
||||
}
|
||||
|
||||
export function editWarehouseSysCategory(data: Recordable) {
|
||||
return defHttp.post({ url: '/sys/category/edit', data });
|
||||
}
|
||||
|
||||
export function deleteWarehouseSysCategory(id: string) {
|
||||
return defHttp.delete({ url: '/sys/category/delete', params: { id } }, { joinParamsToUrl: true });
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { FormSchema } from '/@/components/Table';
|
||||
|
||||
/** 分类字典维护表单(仅 MES 仓库分类子树) */
|
||||
export const warehouseSysCategoryFormSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '父级分类',
|
||||
field: 'pid',
|
||||
required: true,
|
||||
component: 'TreeSelect',
|
||||
componentProps: {
|
||||
fieldNames: { label: 'title', value: 'key' },
|
||||
treeData: [],
|
||||
showSearch: true,
|
||||
allowClear: false,
|
||||
treeDefaultExpandAll: true,
|
||||
dropdownStyle: { maxHeight: '50vh' },
|
||||
getPopupContainer: () => document.body,
|
||||
},
|
||||
dynamicDisabled: ({ values }) => !!values.id,
|
||||
},
|
||||
{
|
||||
label: '分类编码',
|
||||
field: 'code',
|
||||
component: 'Input',
|
||||
componentProps: { readonly: true },
|
||||
ifShow: ({ values }) => !!values.id,
|
||||
},
|
||||
{
|
||||
label: '分类名称',
|
||||
field: 'name',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入分类名称' },
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,472 @@
|
||||
<template>
|
||||
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="720" @ok="handleSubmit">
|
||||
|
||||
<BasicForm @register="registerForm" name="MesXslWarehouseForm">
|
||||
|
||||
<template #warehouseCategoryField="{ model, field }">
|
||||
|
||||
<JCategorySelect
|
||||
|
||||
v-model:value="model[field]"
|
||||
|
||||
pcode="XSLMES_WH"
|
||||
|
||||
placeholder="请选择仓库分类(系统-分类字典)"
|
||||
|
||||
:disabled="isDetail"
|
||||
|
||||
@change="(_v) => onWarehouseCategoryChange(model, _v)"
|
||||
|
||||
/>
|
||||
|
||||
</template>
|
||||
|
||||
<template #customerPicker="{ 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="openCustomerSelect">选择客户</a-button>
|
||||
|
||||
<a-button v-if="model.customerId && !isDetail" @click="clearCustomer(model)">清除</a-button>
|
||||
|
||||
</a-input-group>
|
||||
|
||||
</template>
|
||||
|
||||
<template #supplierPicker="{ 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="openSupplierSelect">选择供应商</a-button>
|
||||
|
||||
<a-button v-if="model.supplierId && !isDetail" @click="clearSupplier(model)">清除</a-button>
|
||||
|
||||
</a-input-group>
|
||||
|
||||
</template>
|
||||
|
||||
</BasicForm>
|
||||
|
||||
<MesXslCustomerSelectModal @register="registerCustomerModal" @select="onCustomerSelect" />
|
||||
|
||||
<MesXslSupplierSelectModal @register="registerSupplierModal" @select="onSupplierSelect" />
|
||||
|
||||
</BasicModal>
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
import { ref, computed, unref } from 'vue';
|
||||
|
||||
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
|
||||
|
||||
import { BasicForm, useForm, JCategorySelect } from '/@/components/Form';
|
||||
|
||||
import { formSchema, WH_CATEGORY_CUSTOMER_CODE, WH_CATEGORY_SUPPLIER_CODE } from '../MesXslWarehouse.data';
|
||||
|
||||
import { saveOrUpdate } from '../MesXslWarehouse.api';
|
||||
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
|
||||
import MesXslCustomerSelectModal from '/@/views/xslmes/mesXslVehicle/components/MesXslCustomerSelectModal.vue';
|
||||
|
||||
import MesXslSupplierSelectModal from '/@/views/xslmes/mesXslVehicle/components/MesXslSupplierSelectModal.vue';
|
||||
|
||||
|
||||
|
||||
const { createMessage } = useMessage();
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
|
||||
const isUpdate = ref(true);
|
||||
|
||||
const isDetail = ref(false);
|
||||
|
||||
|
||||
|
||||
/** 避免弹窗初始化分类控件回显时误清空客户/供应商 */
|
||||
|
||||
const lastWarehouseCategoryEmitted = ref<string>('');
|
||||
|
||||
/** 当前选中分类的 sys_category.code */
|
||||
|
||||
const resolvedCategoryCode = ref<string>('');
|
||||
|
||||
|
||||
|
||||
const [registerCustomerModal, { openModal: openCustomerModal }] = useModal();
|
||||
|
||||
const [registerSupplierModal, { openModal: openSupplierModal }] = useModal();
|
||||
|
||||
|
||||
|
||||
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField, getFieldsValue, updateSchema }] = useForm({
|
||||
|
||||
labelWidth: 120,
|
||||
|
||||
schemas: formSchema,
|
||||
|
||||
showActionButtonGroup: false,
|
||||
|
||||
baseColProps: { span: 24 },
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
async function applyPartnerFieldsVisibility(code: string) {
|
||||
|
||||
const showCust = code === WH_CATEGORY_CUSTOMER_CODE;
|
||||
|
||||
const showSup = code === WH_CATEGORY_SUPPLIER_CODE;
|
||||
|
||||
await updateSchema([
|
||||
|
||||
{ field: 'customerShortName', ifShow: showCust },
|
||||
|
||||
{ field: 'supplierShortName', ifShow: showSup },
|
||||
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 根据分类 id 拉取 code,并切换客户/供应商表单项显示 */
|
||||
|
||||
async function refreshCategoryMeta(categoryId?: string) {
|
||||
|
||||
const id = categoryId != null && categoryId !== '' ? String(categoryId) : '';
|
||||
|
||||
if (!id) {
|
||||
|
||||
resolvedCategoryCode.value = '';
|
||||
|
||||
await applyPartnerFieldsVisibility('');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const cat = await defHttp.get({ url: '/sys/category/queryById', params: { id } });
|
||||
|
||||
resolvedCategoryCode.value = cat?.code != null ? String(cat.code) : '';
|
||||
|
||||
} catch {
|
||||
|
||||
resolvedCategoryCode.value = '';
|
||||
|
||||
}
|
||||
|
||||
await applyPartnerFieldsVisibility(resolvedCategoryCode.value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)) {
|
||||
|
||||
const rec = data.record || {};
|
||||
|
||||
const wc = rec.warehouseCategory != null && rec.warehouseCategory !== '' ? String(rec.warehouseCategory) : '';
|
||||
|
||||
lastWarehouseCategoryEmitted.value = wc;
|
||||
|
||||
await setFieldsValue({ ...rec });
|
||||
|
||||
await refreshCategoryMeta(wc);
|
||||
|
||||
} else {
|
||||
|
||||
lastWarehouseCategoryEmitted.value = '';
|
||||
|
||||
resolvedCategoryCode.value = '';
|
||||
|
||||
await setFieldsValue({ status: '0' });
|
||||
|
||||
await applyPartnerFieldsVisibility('');
|
||||
|
||||
}
|
||||
|
||||
setProps({ disabled: !data?.showFooter });
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
const title = computed(() => (!unref(isUpdate) ? '新增仓库' : unref(isDetail) ? '仓库详情' : '编辑仓库'));
|
||||
|
||||
|
||||
|
||||
/** 切换仓库分类时清空另一侧关联,避免隐藏字段仍提交 */
|
||||
|
||||
async function onWarehouseCategoryChange(model: Recordable, val: unknown) {
|
||||
|
||||
const v = val != null && val !== '' ? String(val) : '';
|
||||
|
||||
if (v === '') {
|
||||
lastWarehouseCategoryEmitted.value = '';
|
||||
await refreshCategoryMeta('');
|
||||
model.customerId = undefined;
|
||||
model.customerShortName = '';
|
||||
model.supplierId = undefined;
|
||||
model.supplierShortName = '';
|
||||
return;
|
||||
}
|
||||
|
||||
if (v === lastWarehouseCategoryEmitted.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastWarehouseCategoryEmitted.value = v;
|
||||
|
||||
await refreshCategoryMeta(v);
|
||||
|
||||
const code = resolvedCategoryCode.value;
|
||||
|
||||
if (code === WH_CATEGORY_CUSTOMER_CODE) {
|
||||
|
||||
model.supplierId = undefined;
|
||||
|
||||
model.supplierShortName = '';
|
||||
|
||||
} else if (code === WH_CATEGORY_SUPPLIER_CODE) {
|
||||
|
||||
model.customerId = undefined;
|
||||
|
||||
model.customerShortName = '';
|
||||
|
||||
} else {
|
||||
|
||||
model.customerId = undefined;
|
||||
|
||||
model.customerShortName = '';
|
||||
|
||||
model.supplierId = undefined;
|
||||
|
||||
model.supplierShortName = '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function sanitizePayloadByCategory(values: Recordable) {
|
||||
|
||||
const code = resolvedCategoryCode.value;
|
||||
|
||||
if (code === WH_CATEGORY_CUSTOMER_CODE) {
|
||||
|
||||
values.supplierId = undefined;
|
||||
|
||||
values.supplierShortName = '';
|
||||
|
||||
} else if (code === WH_CATEGORY_SUPPLIER_CODE) {
|
||||
|
||||
values.customerId = undefined;
|
||||
|
||||
values.customerShortName = '';
|
||||
|
||||
} else {
|
||||
|
||||
values.customerId = undefined;
|
||||
|
||||
values.customerShortName = '';
|
||||
|
||||
values.supplierId = undefined;
|
||||
|
||||
values.supplierShortName = '';
|
||||
|
||||
}
|
||||
|
||||
return values;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function openCustomerSelect() {
|
||||
|
||||
if (resolvedCategoryCode.value !== WH_CATEGORY_CUSTOMER_CODE) {
|
||||
|
||||
createMessage.warning('请先选择仓库分类为「客户库」');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
const v = getFieldsValue() as Recordable;
|
||||
|
||||
openCustomerModal(true, {
|
||||
|
||||
multiple: false,
|
||||
|
||||
customerIds: v.customerId,
|
||||
|
||||
customerShortName: v.customerShortName,
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onCustomerSelect(payload: { customerIds: string; customerShortName: string }) {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
customerId: payload.customerIds || undefined,
|
||||
|
||||
customerShortName: payload.customerShortName || '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearCustomer(model: Recordable) {
|
||||
|
||||
model.customerId = undefined;
|
||||
|
||||
model.customerShortName = '';
|
||||
|
||||
setFieldsValue({ customerId: undefined, customerShortName: '' });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function openSupplierSelect() {
|
||||
|
||||
if (resolvedCategoryCode.value !== WH_CATEGORY_SUPPLIER_CODE) {
|
||||
|
||||
createMessage.warning('请先选择仓库分类为「供应商库」');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
const v = getFieldsValue() as Recordable;
|
||||
|
||||
openSupplierModal(true, {
|
||||
|
||||
supplierId: v.supplierId,
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onSupplierSelect(payload: { supplierId: string; supplierShortName: string }) {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
supplierId: payload.supplierId || undefined,
|
||||
|
||||
supplierShortName: payload.supplierShortName || '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearSupplier(model: Recordable) {
|
||||
|
||||
model.supplierId = undefined;
|
||||
|
||||
model.supplierShortName = '';
|
||||
|
||||
setFieldsValue({ supplierId: undefined, supplierShortName: '' });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function handleSubmit() {
|
||||
|
||||
try {
|
||||
|
||||
const values = await validate();
|
||||
|
||||
await refreshCategoryMeta(values.warehouseCategory != null ? String(values.warehouseCategory) : '');
|
||||
|
||||
const v = sanitizePayloadByCategory({ ...values });
|
||||
|
||||
const code = resolvedCategoryCode.value;
|
||||
|
||||
if (code === WH_CATEGORY_CUSTOMER_CODE && !v.customerId) {
|
||||
|
||||
createMessage.warning('客户库须选择客户');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (code === WH_CATEGORY_SUPPLIER_CODE && !v.supplierId) {
|
||||
|
||||
createMessage.warning('供应商库须选择供应商');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
setModalProps({ confirmLoading: true });
|
||||
|
||||
await saveOrUpdate(v, unref(isUpdate));
|
||||
|
||||
closeModal();
|
||||
|
||||
emit('success');
|
||||
|
||||
} catch (e: any) {
|
||||
|
||||
if (e?.errorFields) {
|
||||
|
||||
const firstField = e.errorFields[0];
|
||||
|
||||
if (firstField) {
|
||||
|
||||
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Promise.reject(e);
|
||||
|
||||
} finally {
|
||||
|
||||
setModalProps({ confirmLoading: false });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="560" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" name="MesXslWarehouseSysCategoryForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form';
|
||||
import { warehouseSysCategoryFormSchema } from '../MesXslWarehouseSysCategory.data';
|
||||
import {
|
||||
fetchWarehouseCategoryRoot,
|
||||
saveWarehouseSysCategory,
|
||||
editWarehouseSysCategory,
|
||||
} from '../MesXslWarehouseSysCategory.api';
|
||||
import { loadTreeData } from '/@/views/system/category/category.api';
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import type { Recordable } from '/@/types/global';
|
||||
|
||||
const { createMessage } = useMessage();
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const isUpdate = ref(false);
|
||||
|
||||
const [registerForm, { resetFields, setFieldsValue, validate, updateSchema, scrollToField }] = useForm({
|
||||
labelWidth: 100,
|
||||
schemas: warehouseSysCategoryFormSchema,
|
||||
showActionButtonGroup: false,
|
||||
baseColProps: { span: 24 },
|
||||
});
|
||||
|
||||
function mapTreeNodes(nodes: Recordable[]): Recordable[] {
|
||||
return (nodes || []).map((n) => ({
|
||||
key: n.key,
|
||||
title: n.title,
|
||||
children: n.children?.length ? mapTreeNodes(n.children as Recordable[]) : undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
async function buildPidTree(): Promise<Recordable[]> {
|
||||
const rootRecord = await fetchWarehouseCategoryRoot();
|
||||
if (!rootRecord?.id) {
|
||||
return [];
|
||||
}
|
||||
const children = await loadTreeData({ async: false, pcode: 'XSLMES_WH' });
|
||||
return [
|
||||
{
|
||||
key: rootRecord.id,
|
||||
title: rootRecord.name || 'MES仓库分类',
|
||||
children: mapTreeNodes(Array.isArray(children) ? children : []),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
await resetFields();
|
||||
setModalProps({ confirmLoading: false });
|
||||
isUpdate.value = !!data?.isUpdate;
|
||||
const tree = await buildPidTree();
|
||||
if (!tree.length) {
|
||||
createMessage.warning('未加载到分类树,请确认分类字典中存在根编码 XSLMES_WH');
|
||||
}
|
||||
await updateSchema([
|
||||
{
|
||||
field: 'pid',
|
||||
componentProps: {
|
||||
treeData: tree,
|
||||
fieldNames: { label: 'title', value: 'key' },
|
||||
showSearch: true,
|
||||
allowClear: false,
|
||||
treeDefaultExpandAll: true,
|
||||
dropdownStyle: { maxHeight: '50vh' },
|
||||
getPopupContainer: () => document.body,
|
||||
},
|
||||
},
|
||||
]);
|
||||
if (unref(isUpdate) && data?.record?.id) {
|
||||
const cat = await defHttp.get<Recordable>({ url: '/sys/category/queryById', params: { id: data.record.id } });
|
||||
await setFieldsValue({
|
||||
id: cat.id,
|
||||
pid: cat.pid,
|
||||
name: cat.name,
|
||||
code: cat.code,
|
||||
});
|
||||
} else {
|
||||
const pid = data?.parentId != null && data.parentId !== '' ? String(data.parentId) : '';
|
||||
await setFieldsValue({
|
||||
pid: pid || undefined,
|
||||
name: '',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const title = computed(() => (unref(isUpdate) ? '编辑仓库分类' : '新增仓库分类'));
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate();
|
||||
setModalProps({ confirmLoading: true });
|
||||
if (unref(isUpdate)) {
|
||||
const full = await defHttp.get<Recordable>({ url: '/sys/category/queryById', params: { id: values.id } });
|
||||
await editWarehouseSysCategory({ ...full, pid: values.pid, name: values.name });
|
||||
} else {
|
||||
await saveWarehouseSysCategory({ pid: values.pid, name: values.name });
|
||||
}
|
||||
closeModal();
|
||||
emit('success');
|
||||
} catch (e: any) {
|
||||
if (e?.errorFields) {
|
||||
const firstField = e.errorFields[0];
|
||||
if (firstField) {
|
||||
scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
}
|
||||
return Promise.reject(e);
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user