更新VSCode配置,启用Maven支持,设置Java 17环境,调整MybatisPlusSaasConfig以开启系统租户控制并添加新租户表。更新pom.xml以包含新模块jeecg-module-xslmes,优化Vue3环境配置以统一API路径,增强代理设置以支持完整的后端路径。修复useForm钩子中的字段重置逻辑,改进axios配置以处理相对URL的上下文路径问题。
This commit is contained in:
@@ -72,9 +72,8 @@ export function useForm(props?: Props): UseFormReturnType {
|
||||
},
|
||||
|
||||
resetFields: async () => {
|
||||
getForm().then(async (form) => {
|
||||
await form.resetFields();
|
||||
});
|
||||
const form = await getForm();
|
||||
await form.resetFields();
|
||||
},
|
||||
|
||||
removeSchemaByFiled: async (field: string | string[]) => {
|
||||
|
||||
@@ -151,6 +151,36 @@ const transform: AxiosTransform = {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单体 / 集成部署:页面在 http://host/jeecg-boot/ 下时,若仅用「以 / 开头的相对 URL」,
|
||||
* 浏览器会解析到 http://host/jeecg-boot/... 或误解析到 http://host/xslmes/...(缺少 context-path),
|
||||
* 后端报 No static resource。使用完整 domainUrl 作 axios baseURL,url 只保留 servlet 内路径。
|
||||
*/
|
||||
if (
|
||||
!isStartWithHttp &&
|
||||
!globSetting.isQiankunMicro &&
|
||||
globSetting.domainUrl &&
|
||||
/^https?:\/\//.test(globSetting.domainUrl) &&
|
||||
config.url &&
|
||||
typeof config.url === 'string'
|
||||
) {
|
||||
try {
|
||||
const du = new URL(globSetting.domainUrl);
|
||||
const ctx = (du.pathname || '').replace(/\/$/, '');
|
||||
config.baseURL = globSetting.domainUrl.replace(/\/$/, '');
|
||||
let pathOnly = config.url as string;
|
||||
if (ctx && (pathOnly === ctx || pathOnly.startsWith(ctx + '/'))) {
|
||||
pathOnly = pathOnly.slice(ctx.length) || '/';
|
||||
}
|
||||
if (!pathOnly.startsWith('/')) {
|
||||
pathOnly = '/' + pathOnly;
|
||||
}
|
||||
config.url = pathOnly;
|
||||
} catch {
|
||||
/* 忽略 URL 解析异常 */
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslCustomer/list',
|
||||
queryById = '/xslmes/mesXslCustomer/queryById',
|
||||
save = '/xslmes/mesXslCustomer/add',
|
||||
edit = '/xslmes/mesXslCustomer/edit',
|
||||
updateStatus = '/xslmes/mesXslCustomer/updateStatus',
|
||||
deleteOne = '/xslmes/mesXslCustomer/delete',
|
||||
deleteBatch = '/xslmes/mesXslCustomer/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslCustomer/importExcel',
|
||||
exportXls = '/xslmes/mesXslCustomer/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 停用(与供应商管理 MesXslSupplier.api.updateStatus 一致) */
|
||||
export const updateStatus = (params: { id: string; status: string }, handleSuccess?: () => void) => {
|
||||
return defHttp.post({ url: Api.updateStatus, params }, { joinParamsToUrl: true }).then(() => {
|
||||
handleSuccess?.();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,105 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: 'ID', align: 'center', dataIndex: 'id', width: 280, ellipsis: true, defaultHidden: true },
|
||||
{ title: '客户编码', align: 'center', dataIndex: 'customerCode', width: 140 },
|
||||
{ title: '客户名称', align: 'center', dataIndex: 'customerName', width: 180 },
|
||||
{ title: '客户简称', align: 'center', dataIndex: 'customerShortName', width: 120 },
|
||||
{ title: '客户区域', align: 'center', dataIndex: 'customerRegion_dictText', width: 100 },
|
||||
{ title: 'ERP编码', align: 'center', dataIndex: 'erpCode', width: 140 },
|
||||
// 库表 status + 字典 xslmes_customer_status 翻译(后端 DictAspect 填充 status_dictText)
|
||||
{ title: '状态', align: 'center', dataIndex: 'status_dictText', width: 100 },
|
||||
{ title: '客户描述', align: 'center', dataIndex: 'customerDesc', width: 200, ellipsis: true },
|
||||
{ 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: 'customerCode', component: 'JInput', colProps: { span: 6 } },
|
||||
{ label: '客户名称', field: 'customerName', component: 'JInput', colProps: { span: 6 } },
|
||||
{ label: '客户简称', field: 'customerShortName', component: 'JInput', colProps: { span: 6 } },
|
||||
{
|
||||
label: '客户区域',
|
||||
field: 'customerRegion',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_customer_region' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_customer_status' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
];
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '客户编码',
|
||||
field: 'customerCode',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入客户编码' },
|
||||
},
|
||||
{
|
||||
label: '客户名称',
|
||||
field: 'customerName',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入客户名称' },
|
||||
},
|
||||
{
|
||||
label: '客户简称',
|
||||
field: 'customerShortName',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入客户简称' },
|
||||
},
|
||||
{
|
||||
label: '客户区域',
|
||||
field: 'customerRegion',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_customer_region', placeholder: '请选择客户区域' },
|
||||
},
|
||||
{
|
||||
label: 'ERP编码',
|
||||
field: 'erpCode',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入ERP编码' },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_customer_status', placeholder: '请选择状态' },
|
||||
// 默认启用仅在新增弹窗内通过 setFieldsValue 写入,避免编辑时 schema 默认值覆盖接口里的 status
|
||||
},
|
||||
{
|
||||
label: '客户描述',
|
||||
field: 'customerDesc',
|
||||
component: 'InputTextArea',
|
||||
componentProps: { rows: 3, placeholder: '请输入客户描述' },
|
||||
},
|
||||
{
|
||||
label: '租户ID',
|
||||
field: 'tenantId',
|
||||
component: 'InputNumber',
|
||||
componentProps: { placeholder: '租户ID,可空' },
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
customerCode: { title: '客户编码', order: 0, view: 'text' },
|
||||
customerName: { title: '客户名称', order: 1, view: 'text' },
|
||||
customerShortName: { title: '客户简称', order: 2, view: 'text' },
|
||||
customerRegion: { title: '客户区域', order: 3, view: 'list', dictCode: 'xslmes_customer_region' },
|
||||
status: { title: '状态', order: 4, view: 'list', dictCode: 'xslmes_customer_status' },
|
||||
};
|
||||
@@ -0,0 +1,159 @@
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_customer:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_customer:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
|
||||
<j-upload-button type="primary" v-auth="'xslmes:mes_xsl_customer: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_customer: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>
|
||||
<MesXslCustomerModal @register="registerModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslCustomer" setup>
|
||||
import { reactive } from 'vue';
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import MesXslCustomerModal from './components/MesXslCustomerModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema } from './MesXslCustomer.data';
|
||||
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, updateStatus } from './MesXslCustomer.api';
|
||||
import Icon from '/@/components/Icon';
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '客户管理',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
autoSubmitOnEnter: true,
|
||||
showAdvancedButton: true,
|
||||
},
|
||||
actionColumn: {
|
||||
width: 280,
|
||||
fixed: 'right',
|
||||
},
|
||||
beforeFetch: (params) => {
|
||||
return 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 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);
|
||||
}
|
||||
|
||||
/** 与供应商管理一致:status===0 或 0 为启用 */
|
||||
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_customer:edit',
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
ifShow: !enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '0'),
|
||||
auth: 'xslmes:mes_xsl_customer:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '停用',
|
||||
ifShow: enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '1'),
|
||||
auth: 'xslmes:mes_xsl_customer:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_customer:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-picker-range) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,91 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" name="MesXslCustomerForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||
import { formSchema } from '../MesXslCustomer.data';
|
||||
import { saveOrUpdate, queryById } from '../MesXslCustomer.api';
|
||||
|
||||
/** 字典下拉 value 与接口一致为字符串,避免 number/string 与选项不一致导致回显成第一项「启用」 */
|
||||
function normalizeCustomerFormValues(record: Recordable) {
|
||||
const o = { ...record };
|
||||
if (o.status !== undefined && o.status !== null && o.status !== '') {
|
||||
o.status = String(o.status);
|
||||
}
|
||||
if (o.customerRegion !== undefined && o.customerRegion !== null && o.customerRegion !== '') {
|
||||
o.customerRegion = String(o.customerRegion);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const isUpdate = ref(true);
|
||||
const isDetail = ref(false);
|
||||
|
||||
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas: formSchema,
|
||||
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 (unref(isUpdate)) {
|
||||
let row = data?.record;
|
||||
// 以详情接口为准,避免列表行字段缺失或与字典组件 value 类型不一致(列表仍显示 status_dictText)
|
||||
if (row?.id) {
|
||||
try {
|
||||
const res = await queryById({ id: String(row.id) });
|
||||
const full = (res as any)?.id != null ? res : (res as any)?.result ?? res;
|
||||
if (full && (full as any).id) {
|
||||
row = full as Recordable;
|
||||
}
|
||||
} catch {
|
||||
// 仍使用列表行
|
||||
}
|
||||
}
|
||||
await setFieldsValue(normalizeCustomerFormValues(row || {}));
|
||||
} else {
|
||||
// 新增默认启用(与后端 MesXslCustomerBizStatus.ENABLED 一致,0=启用)
|
||||
await setFieldsValue({ status: '0' });
|
||||
}
|
||||
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, 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>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,56 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslInstrument/list',
|
||||
save = '/xslmes/mesXslInstrument/add',
|
||||
edit = '/xslmes/mesXslInstrument/edit',
|
||||
updateStatus = '/xslmes/mesXslInstrument/updateStatus',
|
||||
deleteOne = '/xslmes/mesXslInstrument/delete',
|
||||
deleteBatch = '/xslmes/mesXslInstrument/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslInstrument/importExcel',
|
||||
exportXls = '/xslmes/mesXslInstrument/exportXls',
|
||||
queryById = '/xslmes/mesXslInstrument/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 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 启用 */
|
||||
export const updateStatus = (params: { id: string; status: string }, handleSuccess?: () => void) => {
|
||||
return defHttp.post({ url: Api.updateStatus, params }, { joinParamsToUrl: true }).then(() => {
|
||||
handleSuccess?.();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: 'ID', align: 'center', dataIndex: 'id', width: 280, ellipsis: true, defaultHidden: true },
|
||||
{ title: '编号/条码', align: 'center', dataIndex: 'barcode', width: 160 },
|
||||
{ title: '规格型号', align: 'center', dataIndex: 'specModel_dictText', width: 140, ellipsis: true },
|
||||
{ title: '状态', align: 'center', dataIndex: 'status_dictText', width: 90 },
|
||||
{ title: '备注', align: 'center', dataIndex: 'remark', width: 200, ellipsis: true },
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '编号/条码', field: 'barcode', component: 'JInput', colProps: { span: 6 } },
|
||||
{
|
||||
label: '规格型号',
|
||||
field: 'specModel',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_instrument_spec' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_instrument_status' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
];
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '编号/条码',
|
||||
field: 'barcode',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入编号或条码' },
|
||||
},
|
||||
{
|
||||
label: '规格型号',
|
||||
field: 'specModel',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_instrument_spec', placeholder: '请选择规格型号' },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_instrument_status', placeholder: '请选择状态' },
|
||||
defaultValue: '0',
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
field: 'remark',
|
||||
component: 'InputTextArea',
|
||||
componentProps: { placeholder: '请输入备注', rows: 3 },
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
barcode: { title: '编号/条码', order: 0, view: 'text' },
|
||||
specModel: { title: '规格型号', order: 1, view: 'list', dictCode: 'xslmes_instrument_spec' },
|
||||
status: { title: '状态', order: 2, view: 'list', dictCode: 'xslmes_instrument_status' },
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_instrument:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_instrument:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
|
||||
<j-upload-button type="primary" v-auth="'xslmes:mes_xsl_instrument: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_instrument: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>
|
||||
<MesXslInstrumentModal @register="registerModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslInstrument" setup>
|
||||
import { reactive } from 'vue';
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import MesXslInstrumentModal from './components/MesXslInstrumentModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema } from './MesXslInstrument.data';
|
||||
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, updateStatus } from './MesXslInstrument.api';
|
||||
import Icon from '/@/components/Icon';
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '器具管理',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
autoSubmitOnEnter: true,
|
||||
showAdvancedButton: true,
|
||||
},
|
||||
actionColumn: {
|
||||
width: 280,
|
||||
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);
|
||||
|
||||
function handleSuperQuery(params) {
|
||||
Object.keys(params).forEach((k) => {
|
||||
queryParam[k] = params[k];
|
||||
});
|
||||
reload();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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_instrument:edit',
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
ifShow: !enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '0'),
|
||||
auth: 'xslmes:mes_xsl_instrument:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '停用',
|
||||
ifShow: enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '1'),
|
||||
auth: 'xslmes:mes_xsl_instrument:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_instrument:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-picker-range) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="720" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" name="MesXslInstrumentForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||
import { formSchema } from '../MesXslInstrument.data';
|
||||
import { saveOrUpdate } from '../MesXslInstrument.api';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const isUpdate = ref(true);
|
||||
const isDetail = ref(false);
|
||||
|
||||
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas: formSchema,
|
||||
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 (unref(isUpdate)) {
|
||||
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, 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>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,56 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslSupplier/list',
|
||||
save = '/xslmes/mesXslSupplier/add',
|
||||
edit = '/xslmes/mesXslSupplier/edit',
|
||||
updateStatus = '/xslmes/mesXslSupplier/updateStatus',
|
||||
deleteOne = '/xslmes/mesXslSupplier/delete',
|
||||
deleteBatch = '/xslmes/mesXslSupplier/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslSupplier/importExcel',
|
||||
exportXls = '/xslmes/mesXslSupplier/exportXls',
|
||||
queryById = '/xslmes/mesXslSupplier/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 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 启用 */
|
||||
export const updateStatus = (params: { id: string; status: string }, handleSuccess?: () => void) => {
|
||||
return defHttp.post({ url: Api.updateStatus, params }, { joinParamsToUrl: true }).then(() => {
|
||||
handleSuccess?.();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: 'ID', align: 'center', dataIndex: 'id', width: 280, ellipsis: true, defaultHidden: true },
|
||||
{ title: '编码', align: 'center', dataIndex: 'supplierCode', width: 120 },
|
||||
{ title: '名称', align: 'center', dataIndex: 'supplierName', width: 160 },
|
||||
{ title: '简称', align: 'center', dataIndex: 'supplierShortName', width: 120 },
|
||||
{ title: 'ERP编码', align: 'center', dataIndex: 'erpCode', width: 120 },
|
||||
{ title: '备注', align: 'center', dataIndex: 'remark', width: 180, ellipsis: true },
|
||||
{ title: '状态', align: 'center', dataIndex: 'status_dictText', width: 90 },
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '编码', field: 'supplierCode', component: 'JInput', colProps: { span: 6 } },
|
||||
{ label: '名称', field: 'supplierName', component: 'JInput', colProps: { span: 6 } },
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_supplier_status' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
];
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '编码',
|
||||
field: 'supplierCode',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入编码' },
|
||||
},
|
||||
{
|
||||
label: '名称',
|
||||
field: 'supplierName',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入名称' },
|
||||
},
|
||||
{
|
||||
label: '简称',
|
||||
field: 'supplierShortName',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入简称' },
|
||||
},
|
||||
{
|
||||
label: 'ERP编码',
|
||||
field: 'erpCode',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入ERP编码' },
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
field: 'remark',
|
||||
component: 'InputTextArea',
|
||||
componentProps: { placeholder: '请输入备注', rows: 3 },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_supplier_status', placeholder: '请选择状态' },
|
||||
defaultValue: '0',
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
supplierCode: { title: '编码', order: 0, view: 'text' },
|
||||
supplierName: { title: '名称', order: 1, view: 'text' },
|
||||
supplierShortName: { title: '简称', order: 2, view: 'text' },
|
||||
status: { title: '状态', order: 3, view: 'list', dictCode: 'xslmes_supplier_status' },
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_supplier:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_supplier:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
|
||||
<j-upload-button type="primary" v-auth="'xslmes:mes_xsl_supplier: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_supplier: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>
|
||||
<MesXslSupplierModal @register="registerModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslSupplier" setup>
|
||||
import { reactive } from 'vue';
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import MesXslSupplierModal from './components/MesXslSupplierModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema } from './MesXslSupplier.data';
|
||||
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, updateStatus } from './MesXslSupplier.api';
|
||||
import Icon from '/@/components/Icon';
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '供应商管理',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
autoSubmitOnEnter: true,
|
||||
showAdvancedButton: true,
|
||||
},
|
||||
actionColumn: {
|
||||
width: 280,
|
||||
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);
|
||||
|
||||
function handleSuperQuery(params) {
|
||||
Object.keys(params).forEach((k) => {
|
||||
queryParam[k] = params[k];
|
||||
});
|
||||
reload();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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_supplier:edit',
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
ifShow: !enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '0'),
|
||||
auth: 'xslmes:mes_xsl_supplier:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '停用',
|
||||
ifShow: enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '1'),
|
||||
auth: 'xslmes:mes_xsl_supplier:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_supplier:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-picker-range) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="720" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" name="MesXslSupplierForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||
import { formSchema } from '../MesXslSupplier.data';
|
||||
import { saveOrUpdate } from '../MesXslSupplier.api';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const isUpdate = ref(true);
|
||||
const isDetail = ref(false);
|
||||
|
||||
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas: formSchema,
|
||||
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 (unref(isUpdate)) {
|
||||
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, 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>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
56
jeecgboot-vue3/src/views/xslmes/mesXslUnit/MesXslUnit.api.ts
Normal file
56
jeecgboot-vue3/src/views/xslmes/mesXslUnit/MesXslUnit.api.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslUnit/list',
|
||||
save = '/xslmes/mesXslUnit/add',
|
||||
edit = '/xslmes/mesXslUnit/edit',
|
||||
updateStatus = '/xslmes/mesXslUnit/updateStatus',
|
||||
deleteOne = '/xslmes/mesXslUnit/delete',
|
||||
deleteBatch = '/xslmes/mesXslUnit/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslUnit/importExcel',
|
||||
exportXls = '/xslmes/mesXslUnit/exportXls',
|
||||
queryById = '/xslmes/mesXslUnit/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 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 启用 */
|
||||
export const updateStatus = (params: { id: string; status: string }, handleSuccess?: () => void) => {
|
||||
return defHttp.post({ url: Api.updateStatus, params }, { joinParamsToUrl: true }).then(() => {
|
||||
handleSuccess?.();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: 'ID', align: 'center', dataIndex: 'id', width: 280, ellipsis: true, defaultHidden: true },
|
||||
{ title: '编码', align: 'center', dataIndex: 'unitCode', width: 120 },
|
||||
{ title: '名称', align: 'center', dataIndex: 'unitName', width: 140 },
|
||||
{ title: 'ERP编码', align: 'center', dataIndex: 'erpCode', width: 120 },
|
||||
{ title: '所属分类', align: 'center', dataIndex: 'categoryId_dictText', width: 140, ellipsis: true },
|
||||
{ title: '描述', align: 'center', dataIndex: 'unitDesc', width: 200, ellipsis: true },
|
||||
{ title: '状态', align: 'center', dataIndex: 'status_dictText', width: 90 },
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '编码', field: 'unitCode', component: 'JInput', colProps: { span: 6 } },
|
||||
{ label: '名称', field: 'unitName', component: 'JInput', 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: 'unitCode',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入编码' },
|
||||
},
|
||||
{
|
||||
label: '名称',
|
||||
field: 'unitName',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入名称' },
|
||||
},
|
||||
{
|
||||
label: 'ERP编码',
|
||||
field: 'erpCode',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入ERP编码' },
|
||||
},
|
||||
{
|
||||
label: '所属分类',
|
||||
field: 'categoryId',
|
||||
required: true,
|
||||
component: 'JCategorySelect',
|
||||
componentProps: {
|
||||
pcode: 'XSLMES_UNIT',
|
||||
placeholder: '请选择所属分类(分类字典)',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '描述',
|
||||
field: 'unitDesc',
|
||||
component: 'InputTextArea',
|
||||
componentProps: { rows: 3, placeholder: '请输入描述' },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_unit_status', placeholder: '请选择状态' },
|
||||
defaultValue: '0',
|
||||
},
|
||||
{
|
||||
label: '租户ID',
|
||||
field: 'tenantId',
|
||||
component: 'InputNumber',
|
||||
componentProps: { placeholder: '租户ID,可空' },
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
unitCode: { title: '编码', order: 0, view: 'text' },
|
||||
unitName: { title: '名称', order: 1, view: 'text' },
|
||||
status: { title: '状态', order: 2, view: 'list', dictCode: 'xslmes_unit_status' },
|
||||
};
|
||||
618
jeecgboot-vue3/src/views/xslmes/mesXslUnit/MesXslUnitList.vue
Normal file
618
jeecgboot-vue3/src/views/xslmes/mesXslUnit/MesXslUnitList.vue
Normal file
@@ -0,0 +1,618 @@
|
||||
<template>
|
||||
<div class="mes-xsl-unit-page">
|
||||
<div class="mes-xsl-unit-layout">
|
||||
<div class="mes-xsl-unit-sider-col">
|
||||
<aside
|
||||
:class="['mes-xsl-unit-sider', { 'is-collapsed': siderCollapsed, 'is-dragging': siderDragging }]"
|
||||
:style="siderAsideStyle"
|
||||
>
|
||||
<Card class="mes-xsl-unit-sider-card" size="small" title="单位分类" :bordered="true">
|
||||
<template #extra>
|
||||
<a-space v-show="!siderCollapsed" size="small" class="mes-xsl-unit-sider-extra">
|
||||
<a-button type="link" size="small" v-auth="'xslmes:mes_xsl_unit_category:add'" @click="handleAddCategory">新增</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
v-auth="'xslmes:mes_xsl_unit_category:edit'"
|
||||
:disabled="!categorySelectedId"
|
||||
@click="handleEditCategory"
|
||||
>
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
danger
|
||||
v-auth="'xslmes:mes_xsl_unit_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-unit-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-unit-resizer-knob" aria-hidden="true">
|
||||
<span class="mes-xsl-unit-tri" :class="{ 'mes-xsl-unit-tri--collapsed': siderCollapsed }" />
|
||||
</span>
|
||||
</a-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mes-xsl-unit-main">
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_unit:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_unit:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
|
||||
<j-upload-button type="primary" v-auth="'xslmes:mes_xsl_unit: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_unit: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>
|
||||
<MesXslUnitModal @register="registerModal" @success="handleSuccess" />
|
||||
<MesXslUnitSysCategoryModal @register="registerCategoryModal" @success="onCategorySuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslUnit" setup>
|
||||
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue';
|
||||
import { Card, Spin } from 'ant-design-vue';
|
||||
import { BasicTable, useTable, 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 MesXslUnitModal from './components/MesXslUnitModal.vue';
|
||||
import MesXslUnitSysCategoryModal from './components/MesXslUnitSysCategoryModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema } from './MesXslUnit.data';
|
||||
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, updateStatus } from './MesXslUnit.api';
|
||||
import { loadTreeData as loadUnitCategoryTreeRoot } from '/@/views/system/category/category.api';
|
||||
import { fetchUnitCategoryRoot, deleteUnitSysCategory, UNIT_CATEGORY_ROOT_CODE } from './MesXslUnitSysCategory.api';
|
||||
import Icon from '/@/components/Icon';
|
||||
import type { KeyType } from '/@/components/Tree/src/types/tree';
|
||||
import type { Recordable } from '/@/types/global';
|
||||
|
||||
const { createConfirm, createMessage } = useMessage();
|
||||
const TREE_ALL = 'ALL';
|
||||
|
||||
/** 侧栏宽度限制(px) */
|
||||
const SIDER_MIN = 200;
|
||||
const SIDER_MAX = 560;
|
||||
const SIDER_DEFAULT = 260;
|
||||
/** 判定为拖拽而非点击的位移阈值(px) */
|
||||
const SIDER_DRAG_THRESHOLD = 5;
|
||||
/** 收起状态下向右拖拽超过此值开始展开 */
|
||||
const SIDER_EXPAND_DRAG = 12;
|
||||
|
||||
/** 左侧分类树是否收起(为表格腾出横向空间) */
|
||||
const siderCollapsed = ref(false);
|
||||
/** 展开时的侧栏宽度 */
|
||||
const siderWidth = ref(SIDER_DEFAULT);
|
||||
const siderDragging = ref(false);
|
||||
|
||||
const siderAsideStyle = computed(() => ({
|
||||
width: siderCollapsed.value ? '0px' : `${siderWidth.value}px`,
|
||||
}));
|
||||
|
||||
/** 拖拽过程状态(不使用 ref 避免频繁渲染指针位移计算) */
|
||||
let siderDragStartX = 0;
|
||||
let siderDragStartW = 0;
|
||||
let siderDragMaxDelta = 0;
|
||||
let siderDragCollapsedStart = false;
|
||||
let siderDragPointerId: number | null = null;
|
||||
let siderDragEl: HTMLElement | null = null;
|
||||
|
||||
function toggleSider() {
|
||||
if (siderCollapsed.value) {
|
||||
siderCollapsed.value = false;
|
||||
} else {
|
||||
siderCollapsed.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
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 = '';
|
||||
});
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const treeLoading = ref(false);
|
||||
const rawUnitCategoryTree = ref<Recordable[]>([]);
|
||||
const unitCategoryRootId = ref('');
|
||||
const selectedKeys = ref<KeyType[]>([TREE_ALL]);
|
||||
|
||||
function mapUnitCategoryTreeNodes(nodes: Recordable[]): Recordable[] {
|
||||
return (nodes || []).map((n) => ({
|
||||
key: n.key,
|
||||
title: n.title,
|
||||
children: n.children?.length ? mapUnitCategoryTreeNodes(n.children as Recordable[]) : undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
const categoryTreeData = computed(() => [
|
||||
{
|
||||
key: TREE_ALL,
|
||||
title: '全部分类',
|
||||
children: mapUnitCategoryTreeNodes(rawUnitCategoryTree.value || []),
|
||||
},
|
||||
]);
|
||||
|
||||
const categorySelectedId = computed(() => {
|
||||
const k = selectedKeys.value[0];
|
||||
if (!k || k === TREE_ALL) return '';
|
||||
return String(k);
|
||||
});
|
||||
|
||||
async function loadCategoryTree() {
|
||||
treeLoading.value = true;
|
||||
try {
|
||||
const root = await fetchUnitCategoryRoot();
|
||||
unitCategoryRootId.value = root?.id != null ? String(root.id) : '';
|
||||
const res = await loadUnitCategoryTreeRoot({ async: false, pcode: 'XSLMES_UNIT' });
|
||||
rawUnitCategoryTree.value = Array.isArray(res) ? res : [];
|
||||
if (!unitCategoryRootId.value || !rawUnitCategoryTree.value.length) {
|
||||
createMessage.warning('未加载到单位分类树,请确认已执行库脚本且分类字典根编码为 XSLMES_UNIT。');
|
||||
}
|
||||
} catch {
|
||||
unitCategoryRootId.value = '';
|
||||
rawUnitCategoryTree.value = [];
|
||||
createMessage.warning('加载单位分类失败,请检查分类根编码 XSLMES_UNIT 是否存在。');
|
||||
} finally {
|
||||
treeLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
const [registerCategoryModal, { openModal: openCategoryModal }] = useModal();
|
||||
|
||||
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];
|
||||
if (!k || k === TREE_ALL) {
|
||||
delete queryParam.treeCategoryId;
|
||||
} else {
|
||||
queryParam.treeCategoryId = String(k);
|
||||
}
|
||||
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 handleAddCategory() {
|
||||
const rootId = unitCategoryRootId.value;
|
||||
if (!rootId) {
|
||||
createMessage.warning('未找到单位分类根节点,请确认分类字典中存在编码「XSLMES_UNIT」');
|
||||
return;
|
||||
}
|
||||
const sel = categorySelectedId.value;
|
||||
openCategoryModal(true, {
|
||||
isUpdate: false,
|
||||
parentId: sel || rootId,
|
||||
});
|
||||
}
|
||||
|
||||
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 === unitCategoryRootId.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 === UNIT_CATEGORY_ROOT_CODE) {
|
||||
createMessage.warning('根分类不可删除');
|
||||
return;
|
||||
}
|
||||
createConfirm({
|
||||
iconType: 'warning',
|
||||
title: '确认删除',
|
||||
content: '将删除该节点及其下级分类;请确认分类下无单位且无业务依赖。',
|
||||
onOk: async () => {
|
||||
await deleteUnitSysCategory(id);
|
||||
await loadCategoryTree();
|
||||
selectedKeys.value = [TREE_ALL];
|
||||
delete queryParam.treeCategoryId;
|
||||
reload();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function onCategorySuccess() {
|
||||
loadCategoryTree();
|
||||
reload();
|
||||
}
|
||||
|
||||
function getTableAction(record) {
|
||||
const enabled = isRecordEnabled(record);
|
||||
return [
|
||||
{
|
||||
label: '编辑',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: 'xslmes:mes_xsl_unit:edit',
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
ifShow: !enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '0'),
|
||||
auth: 'xslmes:mes_xsl_unit:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '停用',
|
||||
ifShow: enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '1'),
|
||||
auth: 'xslmes:mes_xsl_unit:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_unit:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.mes-xsl-unit-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
/* 与内容区可视高度对齐,使左侧分类与右侧表格同高 */
|
||||
min-height: calc(100vh - 160px);
|
||||
|
||||
:deep(.ant-picker-range) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.mes-xsl-unit-layout {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: stretch;
|
||||
gap: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.mes-xsl-unit-sider-col {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
flex: 0 0 auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.mes-xsl-unit-sider {
|
||||
flex: 0 0 auto;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
transition: width 0.2s ease;
|
||||
|
||||
&.is-dragging {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
&.is-collapsed {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.mes-xsl-unit-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-unit-sider-extra {
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
/* 侧栏右缘可拖拽分隔条 + 三角把手 */
|
||||
.mes-xsl-unit-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-unit-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-unit-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-unit-tri--collapsed {
|
||||
border-width: 5px 0 5px 6px;
|
||||
border-color: transparent transparent transparent #595959;
|
||||
margin-left: 0;
|
||||
margin-right: -1px;
|
||||
}
|
||||
|
||||
.mes-xsl-unit-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import type { Recordable } from '/@/types/global';
|
||||
|
||||
/** 单位分类字典根编码(与 Flyway / 后端一致) */
|
||||
export const UNIT_CATEGORY_ROOT_CODE = 'XSLMES_UNIT';
|
||||
|
||||
export function fetchUnitCategoryRoot() {
|
||||
return defHttp.get<Recordable>({
|
||||
url: '/sys/category/loadOne',
|
||||
params: { field: 'code', val: UNIT_CATEGORY_ROOT_CODE },
|
||||
});
|
||||
}
|
||||
|
||||
export function saveUnitSysCategory(data: Recordable) {
|
||||
return defHttp.post({ url: '/sys/category/add', data });
|
||||
}
|
||||
|
||||
export function editUnitSysCategory(data: Recordable) {
|
||||
return defHttp.post({ url: '/sys/category/edit', data });
|
||||
}
|
||||
|
||||
export function deleteUnitSysCategory(id: string) {
|
||||
return defHttp.delete({ url: '/sys/category/delete', params: { id } }, { joinParamsToUrl: true });
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { FormSchema } from '/@/components/Table';
|
||||
|
||||
/** 单位分类(分类字典)维护表单 */
|
||||
export const unitSysCategoryFormSchema: 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,63 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" name="MesXslUnitForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||
import { formSchema } from '../MesXslUnit.data';
|
||||
import { saveOrUpdate } from '../MesXslUnit.api';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const isUpdate = ref(true);
|
||||
const isDetail = ref(false);
|
||||
|
||||
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas: formSchema,
|
||||
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 (unref(isUpdate)) {
|
||||
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, 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>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,117 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="560" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" name="MesXslUnitSysCategoryForm" />
|
||||
</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 { unitSysCategoryFormSchema } from '../MesXslUnitSysCategory.data';
|
||||
import { fetchUnitCategoryRoot, saveUnitSysCategory, editUnitSysCategory } from '../MesXslUnitSysCategory.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: unitSysCategoryFormSchema,
|
||||
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 fetchUnitCategoryRoot();
|
||||
if (!rootRecord?.id) {
|
||||
return [];
|
||||
}
|
||||
const children = await loadTreeData({ async: false, pcode: 'XSLMES_UNIT' });
|
||||
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_UNIT');
|
||||
}
|
||||
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 editUnitSysCategory({ ...full, pid: values.pid, name: values.name });
|
||||
} else {
|
||||
await saveUnitSysCategory({ 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>
|
||||
@@ -0,0 +1,53 @@
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const { createConfirm } = useMessage();
|
||||
|
||||
enum Api {
|
||||
list = '/xslmes/mesXslVehicle/list',
|
||||
save = '/xslmes/mesXslVehicle/add',
|
||||
edit = '/xslmes/mesXslVehicle/edit',
|
||||
updateStatus = '/xslmes/mesXslVehicle/updateStatus',
|
||||
deleteOne = '/xslmes/mesXslVehicle/delete',
|
||||
deleteBatch = '/xslmes/mesXslVehicle/deleteBatch',
|
||||
importExcel = '/xslmes/mesXslVehicle/importExcel',
|
||||
exportXls = '/xslmes/mesXslVehicle/exportXls',
|
||||
}
|
||||
|
||||
export const getExportUrl = Api.exportXls;
|
||||
export const getImportUrl = Api.importExcel;
|
||||
|
||||
export const list = (params) => defHttp.get({ url: Api.list, 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 启用 */
|
||||
export const updateStatus = (params: { id: string; status: string }, handleSuccess?: () => void) => {
|
||||
return defHttp.post({ url: Api.updateStatus, params }, { joinParamsToUrl: true }).then(() => {
|
||||
handleSuccess?.();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
import { BasicColumn, FormSchema } from '/@/components/Table';
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{ title: 'ID', align: 'center', dataIndex: 'id', width: 280, ellipsis: true, defaultHidden: true },
|
||||
{ title: '车牌号', align: 'center', dataIndex: 'plateNumber', width: 120 },
|
||||
{ title: '车辆归属', align: 'center', dataIndex: 'vehicleBelong_dictText', width: 100 },
|
||||
{ title: '车辆皮重(KG)', align: 'center', dataIndex: 'tareWeightKg', width: 110 },
|
||||
{ title: '装载量', align: 'center', dataIndex: 'loadCapacity', width: 100 },
|
||||
{ title: '单位ID', align: 'center', dataIndex: 'unitId', width: 200, ellipsis: true, defaultHidden: true },
|
||||
{ title: '单位', align: 'center', dataIndex: 'loadUnit', width: 100 },
|
||||
{ title: '客户简称', align: 'center', dataIndex: 'customerShortName', width: 160, ellipsis: true },
|
||||
{ title: '客户ID', align: 'center', dataIndex: 'customerIds', width: 180, ellipsis: true, defaultHidden: true },
|
||||
{ title: '供应商ID', align: 'center', dataIndex: 'supplierId', width: 200, ellipsis: true, defaultHidden: true },
|
||||
{ title: '供应商简称', align: 'center', dataIndex: 'supplierShortName', width: 140, ellipsis: true },
|
||||
{ title: '司机', align: 'center', dataIndex: 'driverName', width: 90 },
|
||||
{ title: '联系电话', align: 'center', dataIndex: 'driverPhone', width: 120 },
|
||||
{ title: '车长', align: 'center', dataIndex: 'vehicleLength', width: 80 },
|
||||
{ title: '车宽', align: 'center', dataIndex: 'vehicleWidth', width: 80 },
|
||||
{ title: '车高', align: 'center', dataIndex: 'vehicleHeight', width: 80 },
|
||||
{ title: '状态', align: 'center', dataIndex: 'status_dictText', width: 90 },
|
||||
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{ label: '车牌号', field: 'plateNumber', component: 'JInput', colProps: { span: 6 } },
|
||||
{
|
||||
label: '车辆归属',
|
||||
field: 'vehicleBelong',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_vehicle_belong' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_vehicle_status' },
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
];
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{ label: '', field: 'id', component: 'Input', show: false },
|
||||
{
|
||||
label: '车牌号',
|
||||
field: 'plateNumber',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入车牌号' },
|
||||
},
|
||||
{
|
||||
label: '车辆归属',
|
||||
field: 'vehicleBelong',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
slot: 'vehicleBelongPicker',
|
||||
},
|
||||
{
|
||||
label: '车辆皮重(KG)',
|
||||
field: 'tareWeightKg',
|
||||
component: 'InputNumber',
|
||||
componentProps: { min: 0, placeholder: '车辆皮重', style: { width: '100%' } },
|
||||
},
|
||||
{
|
||||
label: '装载量',
|
||||
field: 'loadCapacity',
|
||||
component: 'InputNumber',
|
||||
componentProps: { min: 0, placeholder: '装载量', style: { width: '100%' } },
|
||||
},
|
||||
{ label: '单位ID', field: 'unitId', component: 'Input', show: false },
|
||||
{
|
||||
label: '单位',
|
||||
field: 'loadUnit',
|
||||
component: 'Input',
|
||||
slot: 'unitPicker',
|
||||
},
|
||||
{ label: '客户ID', field: 'customerIds', component: 'Input', show: false },
|
||||
{
|
||||
label: '客户简称',
|
||||
field: 'customerShortName',
|
||||
component: 'Input',
|
||||
slot: 'customerPicker',
|
||||
ifShow: ({ values }) => values.vehicleBelong === '1',
|
||||
},
|
||||
{ label: '供应商ID', field: 'supplierId', component: 'Input', show: false },
|
||||
{ label: '供应商名称', field: 'supplierName', component: 'Input', show: false },
|
||||
{
|
||||
label: '供应商简称',
|
||||
field: 'supplierShortName',
|
||||
component: 'Input',
|
||||
slot: 'supplierPicker',
|
||||
ifShow: ({ values }) => values.vehicleBelong === '2',
|
||||
},
|
||||
{
|
||||
label: '车长',
|
||||
field: 'vehicleLength',
|
||||
component: 'InputNumber',
|
||||
componentProps: { min: 0, placeholder: '车长', style: { width: '100%' } },
|
||||
},
|
||||
{
|
||||
label: '车宽',
|
||||
field: 'vehicleWidth',
|
||||
component: 'InputNumber',
|
||||
componentProps: { min: 0, placeholder: '车宽', style: { width: '100%' } },
|
||||
},
|
||||
{
|
||||
label: '车高',
|
||||
field: 'vehicleHeight',
|
||||
component: 'InputNumber',
|
||||
componentProps: { min: 0, placeholder: '车高', style: { width: '100%' } },
|
||||
},
|
||||
{
|
||||
label: '司机',
|
||||
field: 'driverName',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入司机姓名' },
|
||||
},
|
||||
{
|
||||
label: '联系电话',
|
||||
field: 'driverPhone',
|
||||
component: 'Input',
|
||||
componentProps: { placeholder: '请输入联系电话' },
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: { dictCode: 'xslmes_vehicle_status', placeholder: '请选择状态' },
|
||||
defaultValue: '0',
|
||||
},
|
||||
];
|
||||
|
||||
export const superQuerySchema = {
|
||||
plateNumber: { title: '车牌号', order: 0, view: 'text' },
|
||||
vehicleBelong: { title: '车辆归属', order: 1, view: 'list', dictCode: 'xslmes_vehicle_belong' },
|
||||
status: { title: '状态', order: 2, view: 'list', dictCode: 'xslmes_vehicle_status' },
|
||||
};
|
||||
@@ -0,0 +1,159 @@
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection">
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_vehicle:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
|
||||
<a-button type="primary" v-auth="'xslmes:mes_xsl_vehicle:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
|
||||
<j-upload-button type="primary" v-auth="'xslmes:mes_xsl_vehicle: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_vehicle: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>
|
||||
<MesXslVehicleModal @register="registerModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="xslmes-mesXslVehicle" setup>
|
||||
import { reactive } from 'vue';
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||
import { useModal } from '/@/components/Modal';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import MesXslVehicleModal from './components/MesXslVehicleModal.vue';
|
||||
import { columns, searchFormSchema, superQuerySchema } from './MesXslVehicle.data';
|
||||
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, updateStatus } from './MesXslVehicle.api';
|
||||
import Icon from '/@/components/Icon';
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const [registerModal, { openModal }] = useModal();
|
||||
|
||||
const { tableContext, onExportXls, onImportXls } = useListPage({
|
||||
tableProps: {
|
||||
title: '车辆管理',
|
||||
api: list,
|
||||
columns,
|
||||
canResize: true,
|
||||
formConfig: {
|
||||
schemas: searchFormSchema,
|
||||
autoSubmitOnEnter: true,
|
||||
showAdvancedButton: true,
|
||||
},
|
||||
actionColumn: {
|
||||
width: 280,
|
||||
fixed: 'right',
|
||||
},
|
||||
beforeFetch: (params) => {
|
||||
return 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 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);
|
||||
}
|
||||
|
||||
/** 启用:字典值 1 */
|
||||
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_vehicle:edit',
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
ifShow: !enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '0'),
|
||||
auth: 'xslmes:mes_xsl_vehicle:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '停用',
|
||||
ifShow: enabled,
|
||||
onClick: handleToggleStatus.bind(null, record, '1'),
|
||||
auth: 'xslmes:mes_xsl_vehicle:updateStatus',
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
auth: 'xslmes:mes_xsl_vehicle:delete',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function getDropDownAction(record) {
|
||||
return [{ label: '详情', onClick: handleDetail.bind(null, record) }];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-picker-range) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,194 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" title="选择客户" :width="960" @register="registerModal" @ok="handleOk">
|
||||
<BasicTable @register="registerTable" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicTable, useTable } from '/@/components/Table';
|
||||
import { list as customerList, queryById as queryCustomerById } from '/@/views/xslmes/mesXslCustomer/MesXslCustomer.api';
|
||||
|
||||
const emit = defineEmits(['register', 'select']);
|
||||
|
||||
/** 跨页勾选时缓存 id -> 简称(多选) */
|
||||
const idToLabel = reactive<Record<string, string>>({});
|
||||
|
||||
/** 单选时当前行(与供应商选择弹窗一致) */
|
||||
const selectedRow = ref<Recordable | null>(null);
|
||||
|
||||
/** true=多选 checkbox;false=单选 radio(车辆场景默认单选,打开时传入 multiple: false) */
|
||||
const multipleRef = ref(true);
|
||||
|
||||
function handleSelectionChange(keys: string[], rows: Recordable[]) {
|
||||
if (!multipleRef.value) {
|
||||
selectedRow.value = rows?.[0] ?? null;
|
||||
if (selectedRow.value) {
|
||||
const r = selectedRow.value;
|
||||
const shortName = (r.customerShortName && String(r.customerShortName).trim()) || '';
|
||||
idToLabel[r.id] = shortName || r.customerName || '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
rows.forEach((r) => {
|
||||
const shortName = (r.customerShortName && String(r.customerShortName).trim()) || '';
|
||||
idToLabel[r.id] = shortName || r.customerName || '';
|
||||
});
|
||||
Object.keys(idToLabel).forEach((id) => {
|
||||
if (!keys.includes(id)) {
|
||||
delete idToLabel[id];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const [registerTable, { reload, setProps, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] =
|
||||
useTable({
|
||||
api: customerList,
|
||||
// 车辆等场景仅关联「启用」客户(字典 status=0)
|
||||
beforeFetch: (params) => Object.assign(params, { status: '0' }),
|
||||
columns: [
|
||||
{ title: '客户编码', dataIndex: 'customerCode', width: 120 },
|
||||
{ title: '客户名称', dataIndex: 'customerName', width: 160 },
|
||||
{ title: '客户简称', dataIndex: 'customerShortName', width: 120 },
|
||||
],
|
||||
rowKey: 'id',
|
||||
useSearchForm: true,
|
||||
formConfig: {
|
||||
labelWidth: 80,
|
||||
schemas: [
|
||||
{ label: '客户名称', field: 'customerName', component: 'Input', colProps: { span: 8 } },
|
||||
{ label: '客户简称', field: 'customerShortName', component: 'Input', colProps: { span: 8 } },
|
||||
],
|
||||
},
|
||||
pagination: { pageSize: 10 },
|
||||
canResize: false,
|
||||
showIndexColumn: false,
|
||||
immediate: true,
|
||||
rowSelection: {
|
||||
type: 'checkbox',
|
||||
columnWidth: 48,
|
||||
onChange: handleSelectionChange,
|
||||
},
|
||||
clickToRowSelect: false,
|
||||
});
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
Object.keys(idToLabel).forEach((k) => delete idToLabel[k]);
|
||||
selectedRow.value = null;
|
||||
clearSelectedRowKeys?.();
|
||||
|
||||
// multiple === false → 单选;未传或 true → 多选
|
||||
multipleRef.value = data?.multiple !== false;
|
||||
|
||||
setProps({
|
||||
rowSelection: {
|
||||
type: multipleRef.value ? 'checkbox' : 'radio',
|
||||
columnWidth: 48,
|
||||
onChange: handleSelectionChange,
|
||||
},
|
||||
clickToRowSelect: !multipleRef.value,
|
||||
});
|
||||
|
||||
setModalProps({ confirmLoading: false });
|
||||
const idsStr = data?.customerIds as string | undefined;
|
||||
const nameStr = data?.customerShortName as string | undefined;
|
||||
if (idsStr) {
|
||||
const ids = String(idsStr)
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
const names = (nameStr || '').split(',');
|
||||
ids.forEach((id, i) => {
|
||||
idToLabel[id] = names[i]?.trim() || '';
|
||||
});
|
||||
// 单选只回显第一条
|
||||
const keysToSet = multipleRef.value ? ids : ids.length ? [ids[0]] : [];
|
||||
if (keysToSet.length) {
|
||||
setSelectedRowKeys?.(keysToSet);
|
||||
}
|
||||
if (!multipleRef.value && keysToSet.length) {
|
||||
try {
|
||||
const raw = await queryCustomerById({ id: keysToSet[0] });
|
||||
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
if (row) {
|
||||
selectedRow.value = row;
|
||||
}
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
for (const id of ids) {
|
||||
if (idToLabel[id]) continue;
|
||||
try {
|
||||
const raw = await queryCustomerById({ id });
|
||||
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
if (row) {
|
||||
const shortName = (row.customerShortName && String(row.customerShortName).trim()) || '';
|
||||
idToLabel[id] = shortName || row.customerName || '';
|
||||
}
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
reload();
|
||||
});
|
||||
|
||||
async function handleOk() {
|
||||
if (!multipleRef.value) {
|
||||
const keys = (getSelectRowKeys?.() || []) as string[];
|
||||
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
|
||||
if (!row && keys.length) {
|
||||
try {
|
||||
const raw = await queryCustomerById({ id: keys[0] });
|
||||
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
if (!row?.id) {
|
||||
emit('select', { customerIds: '', customerShortName: '' });
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
const shortName =
|
||||
(row.customerShortName && String(row.customerShortName).trim()) || row.customerName || '';
|
||||
emit('select', { customerIds: row.id, customerShortName: shortName });
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
const keys = (getSelectRowKeys?.() || []) as string[];
|
||||
if (!keys.length) {
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
setModalProps({ confirmLoading: true });
|
||||
try {
|
||||
const parts: string[] = [];
|
||||
for (const id of keys) {
|
||||
let label = idToLabel[id];
|
||||
if (!label) {
|
||||
try {
|
||||
const raw = await queryCustomerById({ id });
|
||||
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
if (row) {
|
||||
const shortName = (row.customerShortName && String(row.customerShortName).trim()) || '';
|
||||
label = shortName || row.customerName || '';
|
||||
idToLabel[id] = label;
|
||||
}
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
parts.push(label || '');
|
||||
}
|
||||
const customerShortName = parts.join(',');
|
||||
emit('select', { customerIds: keys.join(','), customerShortName });
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
closeModal();
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" title="选择供应商" :width="900" @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 as supplierList, queryById as querySupplierById } from '/@/views/xslmes/mesXslSupplier/MesXslSupplier.api';
|
||||
|
||||
const emit = defineEmits(['register', 'select']);
|
||||
|
||||
const selectedRow = ref<Recordable | null>(null);
|
||||
|
||||
/** 接口可能返回 camelCase 或 snake_case;简称仅取简称字段,不回退到全称 */
|
||||
function pickSupplierShort(row: Recordable): string {
|
||||
const v = row.supplierShortName ?? row.supplier_short_name;
|
||||
return v != null && String(v).trim() !== '' ? String(v).trim() : '';
|
||||
}
|
||||
|
||||
function pickSupplierName(row: Recordable): string {
|
||||
const v = row.supplierName ?? row.supplier_name;
|
||||
return v != null ? String(v) : '';
|
||||
}
|
||||
|
||||
const [registerTable, { reload, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] = useTable({
|
||||
api: supplierList,
|
||||
columns: [
|
||||
{ title: '编码', dataIndex: 'supplierCode', width: 120 },
|
||||
{ title: '名称', dataIndex: 'supplierName', width: 140 },
|
||||
{ title: '简称', dataIndex: 'supplierShortName', width: 100 },
|
||||
{ title: 'ERP编码', dataIndex: 'erpCode', width: 100 },
|
||||
{ title: '状态', dataIndex: 'status_dictText', width: 90 },
|
||||
],
|
||||
rowKey: 'id',
|
||||
useSearchForm: true,
|
||||
formConfig: {
|
||||
labelWidth: 80,
|
||||
schemas: [
|
||||
{ label: '编码', field: 'supplierCode', component: 'Input', colProps: { span: 8 } },
|
||||
{ label: '名称', field: 'supplierName', component: 'Input', colProps: { span: 8 } },
|
||||
{ label: '简称', field: 'supplierShortName', component: 'Input', colProps: { span: 8 } },
|
||||
],
|
||||
},
|
||||
pagination: { pageSize: 10 },
|
||||
canResize: false,
|
||||
showIndexColumn: false,
|
||||
immediate: true,
|
||||
rowSelection: {
|
||||
type: 'radio',
|
||||
columnWidth: 48,
|
||||
onChange: (_keys, rows) => {
|
||||
selectedRow.value = rows?.[0] ?? null;
|
||||
},
|
||||
},
|
||||
clickToRowSelect: true,
|
||||
});
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
selectedRow.value = null;
|
||||
clearSelectedRowKeys?.();
|
||||
setModalProps({ confirmLoading: false });
|
||||
const sid = data?.supplierId as string | undefined;
|
||||
if (sid) {
|
||||
setSelectedRowKeys?.([sid]);
|
||||
try {
|
||||
const raw = await querySupplierById({ id: sid });
|
||||
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 querySupplierById({ id: keys[0] });
|
||||
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
if (!row?.id) {
|
||||
emit('select', { supplierId: '', supplierName: '', supplierShortName: '' });
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
emit('select', {
|
||||
supplierId: row.id,
|
||||
supplierName: pickSupplierName(row),
|
||||
supplierShortName: pickSupplierShort(row),
|
||||
});
|
||||
closeModal();
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,88 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" title="选择单位" :width="900" @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 as unitList, queryById as queryUnitById } from '/@/views/xslmes/mesXslUnit/MesXslUnit.api';
|
||||
|
||||
const emit = defineEmits(['register', 'select']);
|
||||
|
||||
/** 单选时缓存当前行,便于回显后未再次点击也能确定 */
|
||||
const selectedRow = ref<Recordable | null>(null);
|
||||
|
||||
const [registerTable, { reload, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] = useTable({
|
||||
api: unitList,
|
||||
columns: [
|
||||
{ title: '编码', dataIndex: 'unitCode', width: 120 },
|
||||
{ title: '名称', dataIndex: 'unitName', width: 140 },
|
||||
{ title: 'ERP编码', dataIndex: 'erpCode', width: 120 },
|
||||
{ title: '状态', dataIndex: 'status_dictText', width: 90 },
|
||||
],
|
||||
rowKey: 'id',
|
||||
useSearchForm: true,
|
||||
formConfig: {
|
||||
labelWidth: 80,
|
||||
schemas: [
|
||||
{ label: '编码', field: 'unitCode', component: 'Input', colProps: { span: 8 } },
|
||||
{ label: '名称', field: 'unitName', component: 'Input', colProps: { span: 8 } },
|
||||
],
|
||||
},
|
||||
pagination: { pageSize: 10 },
|
||||
canResize: false,
|
||||
showIndexColumn: false,
|
||||
immediate: true,
|
||||
rowSelection: {
|
||||
type: 'radio',
|
||||
columnWidth: 48,
|
||||
onChange: (_keys, rows) => {
|
||||
selectedRow.value = rows?.[0] ?? null;
|
||||
},
|
||||
},
|
||||
clickToRowSelect: true,
|
||||
});
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
selectedRow.value = null;
|
||||
clearSelectedRowKeys?.();
|
||||
setModalProps({ confirmLoading: false });
|
||||
const uid = data?.unitId as string | undefined;
|
||||
if (uid) {
|
||||
setSelectedRowKeys?.([uid]);
|
||||
try {
|
||||
const raw = await queryUnitById({ id: uid });
|
||||
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 queryUnitById({ id: keys[0] });
|
||||
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
if (!row?.id) {
|
||||
emit('select', { unitId: '', unitName: '' });
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
emit('select', { unitId: row.id, unitName: row.unitName || '' });
|
||||
closeModal();
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,496 @@
|
||||
<template>
|
||||
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="900" @ok="handleSubmit">
|
||||
|
||||
<BasicForm @register="registerForm" name="MesXslVehicleForm">
|
||||
|
||||
<template #vehicleBelongPicker="{ model, field }">
|
||||
<JDictSelectTag
|
||||
v-model:value="model[field]"
|
||||
dictCode="xslmes_vehicle_belong"
|
||||
placeholder="请先选择车辆归属"
|
||||
:disabled="isDetail"
|
||||
@update:value="(v) => onVehicleBelongChange(model, v)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #unitPicker="{ 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" @click="openUnitSelect">选择单位</a-button>
|
||||
|
||||
<a-button v-if="model.unitId" @click="clearUnit">清除</a-button>
|
||||
|
||||
</a-input-group>
|
||||
|
||||
</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" @click="openCustomerSelect">选择客户</a-button>
|
||||
|
||||
<a-button v-if="model.customerIds" @click="clearCustomer">清除</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" @click="openSupplierSelect">选择供应商</a-button>
|
||||
|
||||
<a-button v-if="model.supplierId" @click="clearSupplier">清除</a-button>
|
||||
|
||||
</a-input-group>
|
||||
|
||||
</template>
|
||||
|
||||
</BasicForm>
|
||||
|
||||
<MesXslUnitSelectModal @register="registerUnitModal" @select="onUnitSelect" />
|
||||
|
||||
<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 } from '/@/components/Form/index';
|
||||
|
||||
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
|
||||
|
||||
import { formSchema } from '../MesXslVehicle.data';
|
||||
|
||||
import { saveOrUpdate } from '../MesXslVehicle.api';
|
||||
|
||||
import { queryById as querySupplierById } from '/@/views/xslmes/mesXslSupplier/MesXslSupplier.api';
|
||||
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
import MesXslCustomerSelectModal from './MesXslCustomerSelectModal.vue';
|
||||
|
||||
import MesXslUnitSelectModal from './MesXslUnitSelectModal.vue';
|
||||
|
||||
import MesXslSupplierSelectModal from './MesXslSupplierSelectModal.vue';
|
||||
|
||||
|
||||
|
||||
const { createMessage } = useMessage();
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
|
||||
const isUpdate = ref(true);
|
||||
|
||||
const isDetail = ref(false);
|
||||
|
||||
/** 避免弹窗初始化/字典回显时触发 update:value 误清空已有关联数据 */
|
||||
const lastVehicleBelongEmitted = ref<string>('');
|
||||
|
||||
|
||||
|
||||
const [registerCustomerModal, { openModal: openCustomerModal }] = useModal();
|
||||
|
||||
const [registerUnitModal, { openModal: openUnitModal }] = useModal();
|
||||
|
||||
const [registerSupplierModal, { openModal: openSupplierModal }] = useModal();
|
||||
|
||||
|
||||
|
||||
const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField, getFieldsValue }] = useForm({
|
||||
|
||||
labelWidth: 120,
|
||||
|
||||
schemas: formSchema,
|
||||
|
||||
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 (unref(isUpdate)) {
|
||||
|
||||
await setFieldsValue({ ...data.record });
|
||||
|
||||
const rec = data.record as Recordable | undefined;
|
||||
|
||||
lastVehicleBelongEmitted.value = rec?.vehicleBelong != null && rec?.vehicleBelong !== '' ? String(rec.vehicleBelong) : '';
|
||||
|
||||
// 归属为供应商时:从供应商主数据同步简称(避免库中存了全称或旧数据,与列表接口字段命名不一致)
|
||||
|
||||
if (rec?.vehicleBelong === '2' && rec?.supplierId) {
|
||||
|
||||
try {
|
||||
|
||||
const raw = await querySupplierById({ id: rec.supplierId });
|
||||
|
||||
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
|
||||
|
||||
if (row) {
|
||||
|
||||
const short =
|
||||
(row.supplierShortName ?? row.supplier_short_name) != null &&
|
||||
String(row.supplierShortName ?? row.supplier_short_name).trim() !== ''
|
||||
? String(row.supplierShortName ?? row.supplier_short_name).trim()
|
||||
: '';
|
||||
|
||||
const full = row.supplierName ?? row.supplier_name ?? '';
|
||||
|
||||
await setFieldsValue({
|
||||
|
||||
supplierShortName: short,
|
||||
|
||||
supplierName: full != null ? String(full) : '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
} catch {
|
||||
|
||||
// 忽略同步失败,保留表单原有值
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
lastVehicleBelongEmitted.value = '';
|
||||
|
||||
}
|
||||
|
||||
setProps({ disabled: !data?.showFooter });
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
const title = computed(() => (!unref(isUpdate) ? '新增' : unref(isDetail) ? '详情' : '编辑'));
|
||||
|
||||
|
||||
|
||||
function openUnitSelect() {
|
||||
|
||||
const v = getFieldsValue() as Recordable;
|
||||
|
||||
openUnitModal(true, {
|
||||
|
||||
unitId: v.unitId,
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onUnitSelect(payload: { unitId: string; unitName: string }) {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
unitId: payload.unitId || undefined,
|
||||
|
||||
loadUnit: payload.unitName || '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearUnit() {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
unitId: undefined,
|
||||
|
||||
loadUnit: '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/** 切换归属时立即清空另一侧客户/供应商数据,避免仅隐藏仍提交旧值 */
|
||||
function onVehicleBelongChange(model: Recordable, val: unknown) {
|
||||
const v = val != null && val !== '' ? String(val) : '';
|
||||
// 忽略空值回显,避免编辑加载过程中误清空
|
||||
if (v === '') {
|
||||
return;
|
||||
}
|
||||
if (v === lastVehicleBelongEmitted.value) {
|
||||
return;
|
||||
}
|
||||
lastVehicleBelongEmitted.value = v;
|
||||
if (v === '1') {
|
||||
model.supplierId = undefined;
|
||||
model.supplierName = '';
|
||||
model.supplierShortName = '';
|
||||
} else if (v === '2') {
|
||||
model.customerIds = '';
|
||||
model.customerShortName = '';
|
||||
} else {
|
||||
model.customerIds = '';
|
||||
model.customerShortName = '';
|
||||
model.supplierId = undefined;
|
||||
model.supplierName = '';
|
||||
model.supplierShortName = '';
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交前按归属再清一次,防止绕过 UI */
|
||||
function sanitizePayloadByBelong(values: Recordable) {
|
||||
const b = values.vehicleBelong != null && values.vehicleBelong !== '' ? String(values.vehicleBelong) : '';
|
||||
if (b === '1') {
|
||||
values.supplierId = undefined;
|
||||
values.supplierName = '';
|
||||
values.supplierShortName = '';
|
||||
} else if (b === '2') {
|
||||
values.customerIds = '';
|
||||
values.customerShortName = '';
|
||||
} else {
|
||||
values.customerIds = '';
|
||||
values.customerShortName = '';
|
||||
values.supplierId = undefined;
|
||||
values.supplierName = '';
|
||||
values.supplierShortName = '';
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function openCustomerSelect() {
|
||||
|
||||
const v = getFieldsValue() as Recordable;
|
||||
|
||||
if (!v.vehicleBelong) {
|
||||
|
||||
createMessage.warning('请先选择车辆归属');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (v.vehicleBelong !== '1') {
|
||||
|
||||
createMessage.warning('仅当车辆归属为「客户」时可选择客户');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
openCustomerModal(true, {
|
||||
|
||||
customerIds: v.customerIds,
|
||||
|
||||
customerShortName: v.customerShortName,
|
||||
|
||||
multiple: false,
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onCustomerSelect(payload: { customerIds: string; customerShortName: string }) {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
customerIds: payload.customerIds,
|
||||
|
||||
customerShortName: payload.customerShortName,
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearCustomer() {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
customerIds: '',
|
||||
|
||||
customerShortName: '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function openSupplierSelect() {
|
||||
|
||||
const v = getFieldsValue() as Recordable;
|
||||
|
||||
if (!v.vehicleBelong) {
|
||||
|
||||
createMessage.warning('请先选择车辆归属');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (v.vehicleBelong !== '2') {
|
||||
|
||||
createMessage.warning('仅当车辆归属为「供应商」时可选择供应商');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
openSupplierModal(true, {
|
||||
|
||||
supplierId: v.supplierId,
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onSupplierSelect(payload: { supplierId: string; supplierName: string; supplierShortName: string }) {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
supplierId: payload.supplierId || undefined,
|
||||
|
||||
supplierName: payload.supplierName || '',
|
||||
|
||||
supplierShortName: payload.supplierShortName || '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearSupplier() {
|
||||
|
||||
setFieldsValue({
|
||||
|
||||
supplierId: undefined,
|
||||
|
||||
supplierName: '',
|
||||
|
||||
supplierShortName: '',
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function handleSubmit() {
|
||||
|
||||
try {
|
||||
|
||||
const values = await validate();
|
||||
|
||||
if (!values.vehicleBelong) {
|
||||
|
||||
createMessage.warning('请先选择车辆归属');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (values.vehicleBelong === '1' && !values.customerIds) {
|
||||
|
||||
createMessage.warning('归属为客户时必须选择客户');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (values.vehicleBelong === '2' && !values.supplierId) {
|
||||
|
||||
createMessage.warning('归属为供应商时必须选择供应商');
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
sanitizePayloadByBelong(values);
|
||||
|
||||
setModalProps({ confirmLoading: true });
|
||||
|
||||
await saveOrUpdate(values, 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>
|
||||
|
||||
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
:deep(.ant-input-number) {
|
||||
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -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