feat(frontend): add vehicle replacement pages and enhance delivery/return/prepare with inspection
- Create vehicle-replacement module (data.ts, index.vue, form.vue) with full CRUD, BPM approval actions, and conditional row actions - Enhance vehicle-prepare form with InspectionForm component (backwards compatible with old hardcoded checklist) - Enhance delivery-order with "还车" and "替换车" action buttons on completed orders, plus InspectionForm integration - Enhance return-order with BPM approval submit/withdraw actions and per-vehicle inspection start/view capability - Add inspectionRecordId to vehicle-prepare and delivery-order API types Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
247
apps/web-antd/src/views/asset/vehicle-replacement/data.ts
Normal file
247
apps/web-antd/src/views/asset/vehicle-replacement/data.ts
Normal file
@@ -0,0 +1,247 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
|
||||
export const REPLACEMENT_TYPE_OPTIONS = [
|
||||
{ label: '临时替换', value: 1 },
|
||||
{ label: '永久替换', value: 2 },
|
||||
];
|
||||
|
||||
export const REPLACEMENT_STATUS_OPTIONS = [
|
||||
{ label: '草稿', value: 0 },
|
||||
{ label: '审批中', value: 1 },
|
||||
{ label: '已通过', value: 2 },
|
||||
{ label: '执行中', value: 3 },
|
||||
{ label: '已完成', value: 4 },
|
||||
{ label: '已驳回', value: 5 },
|
||||
{ label: '已撤回', value: 6 },
|
||||
];
|
||||
|
||||
/** 搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'replacementCode',
|
||||
label: '替换单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入替换单号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'replacementType',
|
||||
label: '替换类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择替换类型',
|
||||
options: REPLACEMENT_TYPE_OPTIONS,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'customerName',
|
||||
label: '客户名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: REPLACEMENT_STATUS_OPTIONS,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 表格列配置 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'checkbox', width: 60, fixed: 'left' },
|
||||
{
|
||||
field: 'replacementCode',
|
||||
title: '替换单号',
|
||||
minWidth: 160,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'replacementType',
|
||||
title: '替换类型',
|
||||
minWidth: 100,
|
||||
formatter({ cellValue }: { cellValue: number }) {
|
||||
const option = REPLACEMENT_TYPE_OPTIONS.find(
|
||||
(item) => item.value === cellValue,
|
||||
);
|
||||
return option?.label ?? '';
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'contractCode',
|
||||
title: '合同编号',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'customerName',
|
||||
title: '客户名称',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'originalPlateNo',
|
||||
title: '原车牌号',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'newPlateNo',
|
||||
title: '新车牌号',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
formatter({ cellValue }: { cellValue: number }) {
|
||||
const option = REPLACEMENT_STATUS_OPTIONS.find(
|
||||
(item) => item.value === cellValue,
|
||||
);
|
||||
return option?.label ?? '';
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'expectedDate',
|
||||
title: '预计替换日期',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 280,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'replacementType',
|
||||
label: '替换类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择替换类型',
|
||||
options: REPLACEMENT_TYPE_OPTIONS,
|
||||
},
|
||||
rules: z.number({ message: '请选择替换类型' }),
|
||||
},
|
||||
{
|
||||
fieldName: 'contractId',
|
||||
label: '关联合同',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择关联合同',
|
||||
api: () =>
|
||||
import('#/api/asset/contract').then((m) =>
|
||||
m.getSimpleContractList(),
|
||||
),
|
||||
labelField: 'contractCode',
|
||||
valueField: 'id',
|
||||
showSearch: true,
|
||||
filterOption: (input: string, option: any) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'originalVehicleId',
|
||||
label: '原车辆ID',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入原车辆ID',
|
||||
class: 'w-full',
|
||||
},
|
||||
rules: z.number({ message: '请输入原车辆ID' }),
|
||||
},
|
||||
{
|
||||
fieldName: 'newVehicleId',
|
||||
label: '新车辆ID',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入新车辆ID',
|
||||
class: 'w-full',
|
||||
},
|
||||
rules: z.number({ message: '请输入新车辆ID' }),
|
||||
},
|
||||
{
|
||||
fieldName: 'deliveryOrderId',
|
||||
label: '交车单ID',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入交车单ID',
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'replacementReason',
|
||||
label: '替换原因',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入替换原因',
|
||||
rows: 3,
|
||||
},
|
||||
rules: z.string().min(1, { message: '请输入替换原因' }),
|
||||
},
|
||||
{
|
||||
fieldName: 'expectedDate',
|
||||
label: '预计替换日期',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '请选择预计替换日期',
|
||||
class: 'w-full',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'returnDate',
|
||||
label: '预计归还日期',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '请选择预计归还日期',
|
||||
class: 'w-full',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['replacementType'],
|
||||
show(values) {
|
||||
return values.replacementType === 1;
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
233
apps/web-antd/src/views/asset/vehicle-replacement/index.vue
Normal file
233
apps/web-antd/src/views/asset/vehicle-replacement/index.vue
Normal file
@@ -0,0 +1,233 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { AssetVehicleReplacementApi } from '#/api/asset/vehicle-replacement';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
confirmVehicleReplacementReturn,
|
||||
deleteVehicleReplacement,
|
||||
getVehicleReplacementPage,
|
||||
submitVehicleReplacementApproval,
|
||||
withdrawVehicleReplacementApproval,
|
||||
} from '#/api/asset/vehicle-replacement';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 新增替换车 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 查看替换车 */
|
||||
function handleView(row: AssetVehicleReplacementApi.VehicleReplacement) {
|
||||
formModalApi.setData({ ...row, _mode: 'view' }).open();
|
||||
}
|
||||
|
||||
/** 编辑替换车 */
|
||||
function handleEdit(row: AssetVehicleReplacementApi.VehicleReplacement) {
|
||||
formModalApi.setData({ ...row, _mode: 'edit' }).open();
|
||||
}
|
||||
|
||||
/** 删除替换车 */
|
||||
async function handleDelete(row: AssetVehicleReplacementApi.VehicleReplacement) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.replacementCode]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteVehicleReplacement(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.replacementCode]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交审批 */
|
||||
async function handleSubmitApproval(row: AssetVehicleReplacementApi.VehicleReplacement) {
|
||||
const hideLoading = message.loading({
|
||||
content: '提交审批中...',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await submitVehicleReplacementApproval(row.id!);
|
||||
message.success('提交审批成功');
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 撤回审批 */
|
||||
async function handleWithdrawApproval(row: AssetVehicleReplacementApi.VehicleReplacement) {
|
||||
await confirm('确认撤回审批吗?');
|
||||
const hideLoading = message.loading({
|
||||
content: '撤回审批中...',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await withdrawVehicleReplacementApproval(row.id!);
|
||||
message.success('撤回审批成功');
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 确认换回 */
|
||||
async function handleConfirmReturn(row: AssetVehicleReplacementApi.VehicleReplacement) {
|
||||
await confirm('确认换回原车吗?');
|
||||
const hideLoading = message.loading({
|
||||
content: '确认换回中...',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await confirmVehicleReplacementReturn(row.id!);
|
||||
message.success('确认换回成功');
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function handleRowCheckboxChange({
|
||||
records,
|
||||
}: {
|
||||
records: AssetVehicleReplacementApi.VehicleReplacement[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getVehicleReplacementPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<AssetVehicleReplacementApi.VehicleReplacement>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleRowCheckboxChange,
|
||||
checkboxChange: handleRowCheckboxChange,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="替换车列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['替换车']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['asset:vehicle-replacement:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.view'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
onClick: handleView.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['asset:vehicle-replacement:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
ifShow: row.status === 0 || row.status === 5 || row.status === 6,
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['asset:vehicle-replacement:delete'],
|
||||
ifShow: row.status === 0,
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [
|
||||
row.replacementCode,
|
||||
]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '提交审批',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.CHECK,
|
||||
auth: ['asset:vehicle-replacement:update'],
|
||||
ifShow: row.status === 0 || row.status === 5 || row.status === 6,
|
||||
onClick: handleSubmitApproval.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '撤回审批',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.CLOSE,
|
||||
auth: ['asset:vehicle-replacement:update'],
|
||||
ifShow: row.status === 1,
|
||||
onClick: handleWithdrawApproval.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '确认换回',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.CHECK,
|
||||
auth: ['asset:vehicle-replacement:update'],
|
||||
ifShow: row.status === 3 && row.replacementType === 1,
|
||||
onClick: handleConfirmReturn.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,138 @@
|
||||
<script lang="ts" setup>
|
||||
import type { AssetVehicleReplacementApi } from '#/api/asset/vehicle-replacement';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Card, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createVehicleReplacement,
|
||||
getVehicleReplacement,
|
||||
updateVehicleReplacement,
|
||||
} from '#/api/asset/vehicle-replacement';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
type FormMode = 'create' | 'edit' | 'view';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<AssetVehicleReplacementApi.VehicleReplacement>();
|
||||
const mode = ref<FormMode>('create');
|
||||
|
||||
const isReadOnly = computed(() => mode.value === 'view');
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (mode.value === 'view') {
|
||||
return '查看替换车';
|
||||
}
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['替换车'])
|
||||
: $t('ui.actionTitle.create', ['替换车']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 150,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isReadOnly.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
|
||||
const data =
|
||||
(await formApi.getValues()) as AssetVehicleReplacementApi.VehicleReplacement;
|
||||
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateVehicleReplacement(data)
|
||||
: createVehicleReplacement(data));
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
mode.value = 'create';
|
||||
return;
|
||||
}
|
||||
|
||||
const data = modalApi.getData<
|
||||
AssetVehicleReplacementApi.VehicleReplacement & { _mode?: FormMode }
|
||||
>();
|
||||
|
||||
// Determine mode
|
||||
if (data?._mode) {
|
||||
mode.value = data._mode;
|
||||
} else if (data?.id) {
|
||||
mode.value = 'edit';
|
||||
} else {
|
||||
mode.value = 'create';
|
||||
}
|
||||
|
||||
// Set readonly state on form
|
||||
await formApi.setState({ commonConfig: { componentProps: { disabled: isReadOnly.value } } });
|
||||
|
||||
if (data?.id) {
|
||||
// Edit or view mode: load data from API
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getVehicleReplacement(data.id);
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
} else if (data) {
|
||||
// Create mode: check for pre-fill data (contractId, vehicleId, deliveryOrderId)
|
||||
const prefillData: Record<string, any> = {};
|
||||
if (data.contractId) {
|
||||
prefillData.contractId = data.contractId;
|
||||
}
|
||||
if (data.originalVehicleId) {
|
||||
prefillData.originalVehicleId = data.originalVehicleId;
|
||||
}
|
||||
if (data.deliveryOrderId) {
|
||||
prefillData.deliveryOrderId = data.deliveryOrderId;
|
||||
}
|
||||
if (Object.keys(prefillData).length > 0) {
|
||||
await formApi.setValues(prefillData);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-3/4">
|
||||
<div class="mx-4">
|
||||
<Card :bordered="false">
|
||||
<Form />
|
||||
</Card>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
Reference in New Issue
Block a user