更新VSCode配置,启用Maven支持,设置Java 17环境,调整MybatisPlusSaasConfig以开启系统租户控制并添加新租户表。更新pom.xml以包含新模块jeecg-module-xslmes,优化Vue3环境配置以统一API路径,增强代理设置以支持完整的后端路径。修复useForm钩子中的字段重置逻辑,改进axios配置以处理相对URL的上下文路径问题。

This commit is contained in:
geht
2026-04-21 13:41:05 +08:00
parent 73426a7af3
commit 1b06e987dc
114 changed files with 8249 additions and 17 deletions

View File

@@ -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?.();
});
};

View File

@@ -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' },
};

View File

@@ -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>

View File

@@ -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=多选 checkboxfalse=单选 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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>