mirror of
https://gitee.com/qqtt-ah/ai-crm.git
synced 2026-11-24 13:49:20 +08:00
feat: 落地出货与 CI/PL,打通报价接受到单证闭环
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import type { CrmShipmentDTO, CrmShipmentVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export async function getCrmShipmentPageApi(
|
||||
params: PageQueryDTO<CrmShipmentDTO.Filters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<CrmShipmentVO.Info>>(
|
||||
'/crm/shipment/list',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getCrmShipmentApi(id: number) {
|
||||
return requestClient.get<CrmShipmentVO.Info>(`/crm/shipment/${id}`);
|
||||
}
|
||||
|
||||
export async function createCrmShipmentApi(data: CrmShipmentDTO.Create) {
|
||||
return requestClient.post<CrmShipmentVO.Info>('/crm/shipment/create', data);
|
||||
}
|
||||
|
||||
export async function createCrmShipmentFromQuoteApi(quoteId: number) {
|
||||
return requestClient.post<CrmShipmentVO.Info>(
|
||||
`/crm/shipment/from-quote/${quoteId}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateCrmShipmentApi(
|
||||
id: number,
|
||||
data: CrmShipmentDTO.Update,
|
||||
) {
|
||||
return requestClient.put<CrmShipmentVO.Info>(
|
||||
`/crm/shipment/update/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteCrmShipmentApi(id: number) {
|
||||
return requestClient.delete(`/crm/shipment/delete/${id}`);
|
||||
}
|
||||
|
||||
export async function changeCrmShipmentStatusApi(
|
||||
id: number,
|
||||
data: CrmShipmentDTO.ChangeStatus,
|
||||
) {
|
||||
return requestClient.post<CrmShipmentVO.Info>(
|
||||
`/crm/shipment/${id}/status`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function exportCrmShipmentCiApi(id: number) {
|
||||
return requestClient.post<CrmShipmentVO.Info>(`/crm/shipment/${id}/export-ci`);
|
||||
}
|
||||
|
||||
export async function exportCrmShipmentPlApi(id: number) {
|
||||
return requestClient.post<CrmShipmentVO.Info>(`/crm/shipment/${id}/export-pl`);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,51 @@
|
||||
/** 出货 DTO */
|
||||
export namespace CrmShipmentDTO {
|
||||
export interface Item {
|
||||
productId?: number;
|
||||
productCode?: string;
|
||||
nameEn: string;
|
||||
nameZh?: string;
|
||||
spec?: string;
|
||||
hsCode?: string;
|
||||
unit?: string;
|
||||
qty: number;
|
||||
unitPrice: number;
|
||||
packages?: number;
|
||||
qtyPerPackage?: number;
|
||||
grossWeightKg?: number;
|
||||
netWeightKg?: number;
|
||||
volumeCbm?: number;
|
||||
originCountry?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface Create {
|
||||
quoteId?: number;
|
||||
customerId: number;
|
||||
planShipDate?: string;
|
||||
actualShipDate?: string;
|
||||
destinationPort?: string;
|
||||
transportMode?: string;
|
||||
containerType?: string;
|
||||
currency?: string;
|
||||
incoterm?: string;
|
||||
paymentTerms?: string;
|
||||
ownerUserId?: number;
|
||||
remark?: string;
|
||||
items: Item[];
|
||||
}
|
||||
|
||||
export type Update = Omit<Create, 'quoteId'>;
|
||||
|
||||
export interface Filters {
|
||||
keyword?: string;
|
||||
status?: string;
|
||||
customerId?: number;
|
||||
quoteId?: number;
|
||||
onlyMine?: boolean;
|
||||
}
|
||||
|
||||
export interface ChangeStatus {
|
||||
status: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/** 出货 VO */
|
||||
export namespace CrmShipmentVO {
|
||||
export interface Item {
|
||||
id?: number;
|
||||
lineNo?: number;
|
||||
productId?: number;
|
||||
productCode?: string;
|
||||
nameEn: string;
|
||||
nameZh?: string;
|
||||
spec?: string;
|
||||
hsCode?: string;
|
||||
unit?: string;
|
||||
qty: number;
|
||||
unitPrice: number;
|
||||
amount?: number;
|
||||
packages?: number;
|
||||
qtyPerPackage?: number;
|
||||
grossWeightKg?: number;
|
||||
netWeightKg?: number;
|
||||
volumeCbm?: number;
|
||||
originCountry?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
id: number;
|
||||
companyId?: number;
|
||||
shipmentNo: string;
|
||||
quoteId?: number;
|
||||
quoteNo?: string;
|
||||
customerId: number;
|
||||
customerName?: string;
|
||||
planShipDate?: string;
|
||||
actualShipDate?: string;
|
||||
destinationPort?: string;
|
||||
transportMode?: string;
|
||||
containerType?: string;
|
||||
currency?: string;
|
||||
incoterm?: string;
|
||||
paymentTerms?: string;
|
||||
status: string;
|
||||
totalAmount?: number;
|
||||
totalPackages?: number;
|
||||
totalGrossKg?: number;
|
||||
totalNetKg?: number;
|
||||
totalCbm?: number;
|
||||
ownerUserId?: number;
|
||||
remark?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
items?: Item[];
|
||||
latestCiFileId?: number;
|
||||
latestCiAccessUrl?: string;
|
||||
latestPlFileId?: number;
|
||||
latestPlAccessUrl?: string;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { createCrmShipmentFromQuoteApi } from '#/api/crm/shipment';
|
||||
import {
|
||||
changeCrmQuoteStatusApi,
|
||||
deleteCrmQuoteApi,
|
||||
@@ -57,6 +58,7 @@ const actionCodes = [
|
||||
'crm:quote:delete',
|
||||
'crm:quote:status',
|
||||
'crm:quote:export',
|
||||
'crm:shipment:create',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(actionCodes);
|
||||
|
||||
@@ -80,7 +82,7 @@ const actionColumn: NonNullable<
|
||||
VxeGridProps<CrmQuoteVO.Info>['columns']
|
||||
>[number] = {
|
||||
title: '操作',
|
||||
width: 280,
|
||||
width: 340,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
@@ -177,6 +179,12 @@ async function handleExportPi(row: CrmQuoteVO.Info) {
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function handleCreateShipment(row: CrmQuoteVO.Info) {
|
||||
const ship = await createCrmShipmentFromQuoteApi(row.id);
|
||||
message.success(`已生成出货 ${ship.shipmentNo}`);
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
function statusActions(row: CrmQuoteVO.Info) {
|
||||
const s = row.status;
|
||||
const actions: Array<{ key: string; label: string }> = [];
|
||||
@@ -228,6 +236,16 @@ function statusActions(row: CrmQuoteVO.Info) {
|
||||
导出PI
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:shipment:create">
|
||||
<Button
|
||||
v-if="row.status === 'accepted'"
|
||||
type="link"
|
||||
size="small"
|
||||
@click="handleCreateShipment(row)"
|
||||
>
|
||||
生成出货
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:quote:status">
|
||||
<Dropdown v-if="statusActions(row).length">
|
||||
<Button type="link" size="small">状态</Button>
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CrmCustomerVO } from '#/api/crm/customer';
|
||||
import type { CrmProductVO } from '#/api/crm/product';
|
||||
import type { CrmShipmentDTO, CrmShipmentVO } from '#/api/crm/shipment';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
DatePicker,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs, { type Dayjs } from 'dayjs';
|
||||
|
||||
import { getCrmCustomerPageApi } from '#/api/crm/customer';
|
||||
import { getCrmProductPageApi } from '#/api/crm/product';
|
||||
import {
|
||||
createCrmShipmentApi,
|
||||
getCrmShipmentApi,
|
||||
updateCrmShipmentApi,
|
||||
} from '#/api/crm/shipment';
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[1100px]',
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
const editingId = ref<number>();
|
||||
const customers = ref<CrmCustomerVO.Info[]>([]);
|
||||
const products = ref<CrmProductVO.Info[]>([]);
|
||||
|
||||
interface LineRow extends CrmShipmentDTO.Item {
|
||||
_key: string;
|
||||
}
|
||||
|
||||
const formData = ref({
|
||||
customerId: undefined as number | undefined,
|
||||
planShipDate: dayjs() as Dayjs | undefined,
|
||||
actualShipDate: undefined as Dayjs | undefined,
|
||||
destinationPort: '',
|
||||
transportMode: '',
|
||||
containerType: '',
|
||||
currency: 'USD',
|
||||
incoterm: '',
|
||||
paymentTerms: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
const items = ref<LineRow[]>([]);
|
||||
|
||||
const totalAmount = computed(() =>
|
||||
items.value.reduce((sum, row) => {
|
||||
const qty = Number(row.qty) || 0;
|
||||
const price = Number(row.unitPrice) || 0;
|
||||
return sum + qty * price;
|
||||
}, 0),
|
||||
);
|
||||
|
||||
const rules = {
|
||||
customerId: [{ required: true, message: '请选择客户', trigger: 'change' }],
|
||||
};
|
||||
|
||||
async function loadOptions() {
|
||||
const [c, p] = await Promise.all([
|
||||
getCrmCustomerPageApi({ page: 1, pageSize: 200, filters: {} }),
|
||||
getCrmProductPageApi({
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
filters: { status: 1 },
|
||||
}),
|
||||
]);
|
||||
customers.value = c.records ?? [];
|
||||
products.value = p.records ?? [];
|
||||
}
|
||||
|
||||
function emptyLine(): LineRow {
|
||||
return {
|
||||
_key: `${Date.now()}-${Math.random()}`,
|
||||
nameEn: '',
|
||||
unit: 'PCS',
|
||||
qty: 1,
|
||||
unitPrice: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function mapItems(list: CrmShipmentVO.Item[] | undefined): LineRow[] {
|
||||
return (list ?? []).map((it) => ({
|
||||
_key: `${it.id ?? Date.now()}-${Math.random()}`,
|
||||
productId: it.productId,
|
||||
productCode: it.productCode,
|
||||
nameEn: it.nameEn,
|
||||
nameZh: it.nameZh,
|
||||
spec: it.spec,
|
||||
hsCode: it.hsCode,
|
||||
unit: it.unit ?? 'PCS',
|
||||
qty: Number(it.qty) || 0,
|
||||
unitPrice: Number(it.unitPrice) || 0,
|
||||
packages: it.packages,
|
||||
qtyPerPackage: it.qtyPerPackage,
|
||||
grossWeightKg: it.grossWeightKg,
|
||||
netWeightKg: it.netWeightKg,
|
||||
volumeCbm: it.volumeCbm,
|
||||
originCountry: it.originCountry,
|
||||
remark: it.remark,
|
||||
}));
|
||||
}
|
||||
|
||||
async function open(edit = false, id?: number) {
|
||||
await loadOptions();
|
||||
isEdit.value = edit;
|
||||
editingId.value = id;
|
||||
if (edit && id) {
|
||||
const detail = await getCrmShipmentApi(id);
|
||||
formData.value = {
|
||||
customerId: detail.customerId,
|
||||
planShipDate: detail.planShipDate ? dayjs(detail.planShipDate) : dayjs(),
|
||||
actualShipDate: detail.actualShipDate
|
||||
? dayjs(detail.actualShipDate)
|
||||
: undefined,
|
||||
destinationPort: detail.destinationPort ?? '',
|
||||
transportMode: detail.transportMode ?? '',
|
||||
containerType: detail.containerType ?? '',
|
||||
currency: detail.currency ?? 'USD',
|
||||
incoterm: detail.incoterm ?? '',
|
||||
paymentTerms: detail.paymentTerms ?? '',
|
||||
remark: detail.remark ?? '',
|
||||
};
|
||||
items.value = mapItems(detail.items);
|
||||
modalApi.setState({ title: `编辑出货 ${detail.shipmentNo}` });
|
||||
} else {
|
||||
formData.value = {
|
||||
customerId: undefined,
|
||||
planShipDate: dayjs(),
|
||||
actualShipDate: undefined,
|
||||
destinationPort: '',
|
||||
transportMode: '',
|
||||
containerType: '',
|
||||
currency: 'USD',
|
||||
incoterm: '',
|
||||
paymentTerms: '',
|
||||
remark: '',
|
||||
};
|
||||
items.value = [emptyLine()];
|
||||
modalApi.setState({ title: '新建出货' });
|
||||
}
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
function addLine() {
|
||||
items.value.push(emptyLine());
|
||||
}
|
||||
|
||||
function removeLine(key: string) {
|
||||
if (items.value.length <= 1) {
|
||||
message.warning('至少保留一行');
|
||||
return;
|
||||
}
|
||||
items.value = items.value.filter((x) => x._key !== key);
|
||||
}
|
||||
|
||||
function onPickProduct(row: LineRow, productId: number) {
|
||||
const p = products.value.find((x) => x.id === productId);
|
||||
if (!p) return;
|
||||
row.productId = p.id;
|
||||
row.productCode = p.code;
|
||||
row.nameEn = p.nameEn;
|
||||
row.nameZh = p.nameZh;
|
||||
row.spec = p.spec;
|
||||
row.hsCode = p.hsCode;
|
||||
row.unit = p.unit || 'PCS';
|
||||
row.unitPrice = Number(p.unitPrice) || 0;
|
||||
const qty = Number(row.qty) || 1;
|
||||
if (p.grossWeightKg != null) {
|
||||
row.grossWeightKg = Number(p.grossWeightKg) * qty;
|
||||
}
|
||||
if (p.netWeightKg != null) {
|
||||
row.netWeightKg = Number(p.netWeightKg) * qty;
|
||||
}
|
||||
if (p.volumeCbm != null) {
|
||||
row.volumeCbm = Number(p.volumeCbm) * qty;
|
||||
}
|
||||
}
|
||||
|
||||
function buildPayload(): CrmShipmentDTO.Create {
|
||||
return {
|
||||
customerId: formData.value.customerId!,
|
||||
planShipDate: formData.value.planShipDate?.format('YYYY-MM-DD'),
|
||||
actualShipDate: formData.value.actualShipDate?.format('YYYY-MM-DD'),
|
||||
destinationPort: formData.value.destinationPort || undefined,
|
||||
transportMode: formData.value.transportMode || undefined,
|
||||
containerType: formData.value.containerType || undefined,
|
||||
currency: formData.value.currency,
|
||||
incoterm: formData.value.incoterm || undefined,
|
||||
paymentTerms: formData.value.paymentTerms || undefined,
|
||||
remark: formData.value.remark || undefined,
|
||||
items: items.value.map((row) => ({
|
||||
productId: row.productId,
|
||||
productCode: row.productCode,
|
||||
nameEn: row.nameEn,
|
||||
nameZh: row.nameZh,
|
||||
spec: row.spec,
|
||||
hsCode: row.hsCode,
|
||||
unit: row.unit,
|
||||
qty: Number(row.qty),
|
||||
unitPrice: Number(row.unitPrice),
|
||||
packages: row.packages,
|
||||
qtyPerPackage: row.qtyPerPackage,
|
||||
grossWeightKg: row.grossWeightKg,
|
||||
netWeightKg: row.netWeightKg,
|
||||
volumeCbm: row.volumeCbm,
|
||||
originCountry: row.originCountry,
|
||||
remark: row.remark,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (items.value.some((x) => !x.nameEn?.trim())) {
|
||||
message.error('请填写每行英文品名');
|
||||
return;
|
||||
}
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
try {
|
||||
const payload = buildPayload();
|
||||
if (isEdit.value && editingId.value) {
|
||||
await updateCrmShipmentApi(editingId.value, payload);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createCrmShipmentApi(payload);
|
||||
message.success('创建成功');
|
||||
}
|
||||
modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '产品', key: 'product', width: 140 },
|
||||
{ title: '英文品名', key: 'nameEn', width: 140 },
|
||||
{ title: 'HS', key: 'hsCode', width: 90 },
|
||||
{ title: '数量', key: 'qty', width: 90 },
|
||||
{ title: '单价', key: 'unitPrice', width: 100 },
|
||||
{ title: '箱数', key: 'packages', width: 80 },
|
||||
{ title: '毛重', key: 'grossWeightKg', width: 90 },
|
||||
{ title: '净重', key: 'netWeightKg', width: 90 },
|
||||
{ title: 'CBM', key: 'volumeCbm', width: 90 },
|
||||
{ title: '', key: 'action', width: 50 },
|
||||
];
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:label-col="{ span: 4 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="客户" name="customerId">
|
||||
<Select
|
||||
v-model:value="formData.customerId"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:options="
|
||||
customers.map((c) => ({
|
||||
value: c.id,
|
||||
label: `${c.name}${c.country ? ` (${c.country})` : ''}`,
|
||||
}))
|
||||
"
|
||||
placeholder="选择客户"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="计划出货日">
|
||||
<DatePicker v-model:value="formData.planShipDate" class="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="实际出货日">
|
||||
<DatePicker v-model:value="formData.actualShipDate" class="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="目的港">
|
||||
<Input v-model:value="formData.destinationPort" />
|
||||
</Form.Item>
|
||||
<Form.Item label="运输方式">
|
||||
<Input
|
||||
v-model:value="formData.transportMode"
|
||||
placeholder="sea / air / express"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="柜型">
|
||||
<Input
|
||||
v-model:value="formData.containerType"
|
||||
placeholder="20GP / 40HQ"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="币种">
|
||||
<Input v-model:value="formData.currency" />
|
||||
</Form.Item>
|
||||
<Form.Item label="贸易术语">
|
||||
<Input v-model:value="formData.incoterm" placeholder="FOB / CIF" />
|
||||
</Form.Item>
|
||||
<Form.Item label="付款条款">
|
||||
<Input v-model:value="formData.paymentTerms" />
|
||||
</Form.Item>
|
||||
<Form.Item label="备注">
|
||||
<Input.TextArea v-model:value="formData.remark" :rows="2" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<div class="font-medium">明细 / 箱规</div>
|
||||
<Space>
|
||||
<span>合计:{{ totalAmount.toFixed(2) }} {{ formData.currency }}</span>
|
||||
<Button size="small" @click="addLine">加行</Button>
|
||||
</Space>
|
||||
</div>
|
||||
<Table
|
||||
size="small"
|
||||
:pagination="false"
|
||||
:columns="columns"
|
||||
:data-source="items"
|
||||
:row-key="(r: LineRow) => r._key"
|
||||
:scroll="{ x: 1000 }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'product'">
|
||||
<Select
|
||||
class="w-full"
|
||||
allow-clear
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:value="record.productId"
|
||||
:options="
|
||||
products.map((p) => ({
|
||||
value: p.id,
|
||||
label: `${p.code} ${p.nameEn}`,
|
||||
}))
|
||||
"
|
||||
@change="(v: any) => v && onPickProduct(record, v)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'nameEn'">
|
||||
<Input v-model:value="record.nameEn" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'hsCode'">
|
||||
<Input v-model:value="record.hsCode" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'qty'">
|
||||
<InputNumber v-model:value="record.qty" :min="0" class="w-full" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'unitPrice'">
|
||||
<InputNumber
|
||||
v-model:value="record.unitPrice"
|
||||
:min="0"
|
||||
:precision="4"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'packages'">
|
||||
<InputNumber
|
||||
v-model:value="record.packages"
|
||||
:min="0"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'grossWeightKg'">
|
||||
<InputNumber
|
||||
v-model:value="record.grossWeightKg"
|
||||
:min="0"
|
||||
:precision="3"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'netWeightKg'">
|
||||
<InputNumber
|
||||
v-model:value="record.netWeightKg"
|
||||
:min="0"
|
||||
:precision="3"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'volumeCbm'">
|
||||
<InputNumber
|
||||
v-model:value="record.volumeCbm"
|
||||
:min="0"
|
||||
:precision="4"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<Button
|
||||
type="link"
|
||||
danger
|
||||
size="small"
|
||||
@click="removeLine(record._key)"
|
||||
>
|
||||
删
|
||||
</Button>
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,284 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { CrmShipmentDTO, CrmShipmentVO } from '#/api/crm/shipment';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
Menu,
|
||||
message,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
changeCrmShipmentStatusApi,
|
||||
deleteCrmShipmentApi,
|
||||
exportCrmShipmentCiApi,
|
||||
exportCrmShipmentPlApi,
|
||||
getCrmShipmentPageApi,
|
||||
} from '#/api/crm/shipment';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
|
||||
import ShipmentModal from './components/ShipmentModal.vue';
|
||||
|
||||
defineOptions({ name: 'CrmShipment' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const loading = ref(false);
|
||||
const modalRef = ref<InstanceType<typeof ShipmentModal>>();
|
||||
const searchForm = ref({
|
||||
keyword: '',
|
||||
status: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const statusMap: Record<string, { color: string; label: string }> = {
|
||||
draft: { color: 'default', label: '草稿' },
|
||||
ready: { color: 'processing', label: '待出货' },
|
||||
shipped: { color: 'success', label: '已出货' },
|
||||
closed: { color: 'warning', label: '已关闭' },
|
||||
};
|
||||
|
||||
const actionCodes = [
|
||||
'crm:shipment:create',
|
||||
'crm:shipment:update',
|
||||
'crm:shipment:delete',
|
||||
'crm:shipment:status',
|
||||
'crm:shipment:export',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(actionCodes);
|
||||
|
||||
const baseColumns: VxeGridProps<CrmShipmentVO.Info>['columns'] = [
|
||||
{ type: 'seq', title: '序号', minWidth: 60 },
|
||||
{ field: 'shipmentNo', title: '出货号', minWidth: 140 },
|
||||
{ field: 'quoteNo', title: '来源报价', minWidth: 130 },
|
||||
{ field: 'customerName', title: '客户', minWidth: 150 },
|
||||
{ field: 'planShipDate', title: '计划日', minWidth: 110 },
|
||||
{ field: 'destinationPort', title: '目的港', minWidth: 120 },
|
||||
{ field: 'currency', title: '币种', minWidth: 70 },
|
||||
{ field: 'totalAmount', title: '合计', minWidth: 100 },
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 90,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{ field: 'createTime', title: '创建时间', minWidth: 160 },
|
||||
];
|
||||
|
||||
const actionColumn: NonNullable<
|
||||
VxeGridProps<CrmShipmentVO.Info>['columns']
|
||||
>[number] = {
|
||||
title: '操作',
|
||||
width: 320,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const tableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(baseColumns ?? []), actionColumn]
|
||||
: (baseColumns ?? []),
|
||||
);
|
||||
|
||||
const gridOptions: VxeGridProps<CrmShipmentVO.Info> = {
|
||||
columns: tableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { isHover: true },
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: { custom: true, refresh: true, zoom: true },
|
||||
pagerConfig: { enabled: true, pageSizes: [10, 20, 50, 100] },
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<CrmShipmentDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
keyword: searchForm.value.keyword || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getCrmShipmentPageApi(params);
|
||||
return { items: data.records, total: data.total };
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: {
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'keyword',
|
||||
label: '关键词',
|
||||
componentProps: { placeholder: '出货号/目的港/备注' },
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: Object.entries(statusMap).map(([value, v]) => ({
|
||||
value,
|
||||
label: v.label,
|
||||
})),
|
||||
},
|
||||
},
|
||||
],
|
||||
handleSubmit: async (values: Record<string, any>) => {
|
||||
searchForm.value.keyword = values.keyword ?? '';
|
||||
searchForm.value.status = values.status;
|
||||
gridApi.reload();
|
||||
},
|
||||
},
|
||||
});
|
||||
syncVxeGridColumns(gridApi, tableColumns);
|
||||
|
||||
async function handleDelete(row: CrmShipmentVO.Info) {
|
||||
await deleteCrmShipmentApi(row.id);
|
||||
message.success('已删除');
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function handleStatus(row: CrmShipmentVO.Info, status: string) {
|
||||
await changeCrmShipmentStatusApi(row.id, { status });
|
||||
message.success('状态已更新');
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function handleExportCi(row: CrmShipmentVO.Info) {
|
||||
const detail = await exportCrmShipmentCiApi(row.id);
|
||||
message.success('CI 已生成');
|
||||
if (detail.latestCiAccessUrl) {
|
||||
window.open(detail.latestCiAccessUrl, '_blank');
|
||||
}
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function handleExportPl(row: CrmShipmentVO.Info) {
|
||||
const detail = await exportCrmShipmentPlApi(row.id);
|
||||
message.success('PL 已生成');
|
||||
if (detail.latestPlAccessUrl) {
|
||||
window.open(detail.latestPlAccessUrl, '_blank');
|
||||
}
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
function canEdit(row: CrmShipmentVO.Info) {
|
||||
return row.status === 'draft' || row.status === 'ready';
|
||||
}
|
||||
|
||||
function statusActions(row: CrmShipmentVO.Info) {
|
||||
const s = row.status;
|
||||
const actions: Array<{ key: string; label: string }> = [];
|
||||
if (s === 'draft') {
|
||||
actions.push({ key: 'ready', label: '标记待出货' });
|
||||
actions.push({ key: 'closed', label: '关闭' });
|
||||
} else if (s === 'ready') {
|
||||
actions.push({ key: 'shipped', label: '标记已出货' });
|
||||
actions.push({ key: 'draft', label: '退回草稿' });
|
||||
actions.push({ key: 'closed', label: '关闭' });
|
||||
} else if (s === 'shipped') {
|
||||
actions.push({ key: 'closed', label: '关闭' });
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid>
|
||||
<template #toolbar-tools>
|
||||
<PermissionGate code="crm:shipment:create">
|
||||
<Button type="primary" @click="modalRef?.open(false)">
|
||||
<PlusIcon class="size-4" />
|
||||
新建出货
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<Tag :color="statusMap[row.status]?.color ?? 'default'">
|
||||
{{ statusMap[row.status]?.label ?? row.status }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space wrap>
|
||||
<PermissionGate code="crm:shipment:update">
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="!canEdit(row)"
|
||||
@click="modalRef?.open(true, row.id)"
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:shipment:export">
|
||||
<Button type="link" size="small" @click="handleExportCi(row)">
|
||||
CI
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:shipment:export">
|
||||
<Button type="link" size="small" @click="handleExportPl(row)">
|
||||
PL
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:shipment:status">
|
||||
<Dropdown v-if="statusActions(row).length">
|
||||
<Button type="link" size="small">状态</Button>
|
||||
<template #overlay>
|
||||
<Menu
|
||||
@click="
|
||||
({ key }: { key: string | number }) =>
|
||||
handleStatus(row, String(key))
|
||||
"
|
||||
>
|
||||
<Menu.Item
|
||||
v-for="a in statusActions(row)"
|
||||
:key="a.key"
|
||||
>
|
||||
{{ a.label }}
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
</template>
|
||||
</Dropdown>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:shipment:delete">
|
||||
<Popconfirm
|
||||
v-if="row.status === 'draft'"
|
||||
title="确认删除该出货?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
<ShipmentModal ref="modalRef" @success="gridApi.reload()" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user