mirror of
https://gitee.com/qqtt-ah/ai-crm.git
synced 2026-11-24 18:29:20 +08:00
feat: 落地 CRM Phase1 报价闭环与 PI 导出、单证资料
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import type { CrmProfileUpdateDTO, CrmProfileVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export async function getCrmProfileApi() {
|
||||
return requestClient.get<CrmProfileVO.Info>('/crm/profile');
|
||||
}
|
||||
|
||||
export async function saveCrmProfileApi(data: CrmProfileUpdateDTO) {
|
||||
return requestClient.put<CrmProfileVO.Info>('/crm/profile', data);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,28 @@
|
||||
/** 单证资料 */
|
||||
export namespace CrmProfileVO {
|
||||
export interface Info {
|
||||
id?: number;
|
||||
companyId?: number;
|
||||
legalNameZh?: string;
|
||||
legalNameEn?: string;
|
||||
addressZh?: string;
|
||||
addressEn?: string;
|
||||
country?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
taxNo?: string;
|
||||
bankName?: string;
|
||||
bankAccount?: string;
|
||||
bankSwift?: string;
|
||||
bankAddress?: string;
|
||||
defaultCurrency?: string;
|
||||
defaultIncoterm?: string;
|
||||
remark?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export type CrmProfileUpdateDTO = Omit<
|
||||
CrmProfileVO.Info,
|
||||
'id' | 'companyId' | 'updateTime'
|
||||
>;
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { CrmQuoteDTO, CrmQuoteVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export async function getCrmQuotePageApi(
|
||||
params: PageQueryDTO<CrmQuoteDTO.Filters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<CrmQuoteVO.Info>>(
|
||||
'/crm/quote/list',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getCrmQuoteApi(id: number) {
|
||||
return requestClient.get<CrmQuoteVO.Info>(`/crm/quote/${id}`);
|
||||
}
|
||||
|
||||
export async function createCrmQuoteApi(data: CrmQuoteDTO.Create) {
|
||||
return requestClient.post<CrmQuoteVO.Info>('/crm/quote/create', data);
|
||||
}
|
||||
|
||||
export async function updateCrmQuoteApi(id: number, data: CrmQuoteDTO.Update) {
|
||||
return requestClient.put<CrmQuoteVO.Info>(`/crm/quote/update/${id}`, data);
|
||||
}
|
||||
|
||||
export async function deleteCrmQuoteApi(id: number) {
|
||||
return requestClient.delete(`/crm/quote/delete/${id}`);
|
||||
}
|
||||
|
||||
export async function changeCrmQuoteStatusApi(
|
||||
id: number,
|
||||
data: CrmQuoteDTO.ChangeStatus,
|
||||
) {
|
||||
return requestClient.post<CrmQuoteVO.Info>(`/crm/quote/${id}/status`, data);
|
||||
}
|
||||
|
||||
export async function exportCrmQuotePiApi(id: number) {
|
||||
return requestClient.post<CrmQuoteVO.Info>(`/crm/quote/${id}/export-pi`);
|
||||
}
|
||||
@@ -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,39 @@
|
||||
/** 报价 DTO */
|
||||
export namespace CrmQuoteDTO {
|
||||
export interface Item {
|
||||
productId?: number;
|
||||
productCode?: string;
|
||||
nameEn: string;
|
||||
nameZh?: string;
|
||||
spec?: string;
|
||||
unit?: string;
|
||||
qty: number;
|
||||
unitPrice: number;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface Create {
|
||||
customerId: number;
|
||||
quoteDate?: string;
|
||||
validUntil?: string;
|
||||
currency?: string;
|
||||
incoterm?: string;
|
||||
paymentTerms?: string;
|
||||
ownerUserId?: number;
|
||||
remark?: string;
|
||||
items: Item[];
|
||||
}
|
||||
|
||||
export type Update = Create;
|
||||
|
||||
export interface Filters {
|
||||
keyword?: string;
|
||||
status?: string;
|
||||
customerId?: number;
|
||||
onlyMine?: boolean;
|
||||
}
|
||||
|
||||
export interface ChangeStatus {
|
||||
status: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/** 报价 VO */
|
||||
export namespace CrmQuoteVO {
|
||||
export interface Item {
|
||||
id?: number;
|
||||
lineNo?: number;
|
||||
productId?: number;
|
||||
productCode?: string;
|
||||
nameEn: string;
|
||||
nameZh?: string;
|
||||
spec?: string;
|
||||
unit?: string;
|
||||
qty: number;
|
||||
unitPrice: number;
|
||||
amount?: number;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
id: number;
|
||||
companyId?: number;
|
||||
quoteNo: string;
|
||||
customerId: number;
|
||||
customerName?: string;
|
||||
quoteDate?: string;
|
||||
validUntil?: string;
|
||||
currency?: string;
|
||||
incoterm?: string;
|
||||
paymentTerms?: string;
|
||||
status: string;
|
||||
totalAmount?: number;
|
||||
ownerUserId?: number;
|
||||
remark?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
items?: Item[];
|
||||
latestPiFileId?: number;
|
||||
latestPiAccessUrl?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CrmProfileUpdateDTO } from '#/api/crm/profile';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Button, Card, Form, Input, message, Space } from 'ant-design-vue';
|
||||
|
||||
import { getCrmProfileApi, saveCrmProfileApi } from '#/api/crm/profile';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
|
||||
defineOptions({ name: 'CrmProfile' });
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const form = ref<CrmProfileUpdateDTO>({
|
||||
legalNameZh: '',
|
||||
legalNameEn: '',
|
||||
addressZh: '',
|
||||
addressEn: '',
|
||||
country: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
taxNo: '',
|
||||
bankName: '',
|
||||
bankAccount: '',
|
||||
bankSwift: '',
|
||||
bankAddress: '',
|
||||
defaultCurrency: 'USD',
|
||||
defaultIncoterm: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await getCrmProfileApi();
|
||||
form.value = {
|
||||
legalNameZh: data.legalNameZh ?? '',
|
||||
legalNameEn: data.legalNameEn ?? '',
|
||||
addressZh: data.addressZh ?? '',
|
||||
addressEn: data.addressEn ?? '',
|
||||
country: data.country ?? '',
|
||||
phone: data.phone ?? '',
|
||||
email: data.email ?? '',
|
||||
taxNo: data.taxNo ?? '',
|
||||
bankName: data.bankName ?? '',
|
||||
bankAccount: data.bankAccount ?? '',
|
||||
bankSwift: data.bankSwift ?? '',
|
||||
bankAddress: data.bankAddress ?? '',
|
||||
defaultCurrency: data.defaultCurrency ?? 'USD',
|
||||
defaultIncoterm: data.defaultIncoterm ?? '',
|
||||
remark: data.remark ?? '',
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
saving.value = true;
|
||||
try {
|
||||
await saveCrmProfileApi(form.value);
|
||||
message.success('已保存');
|
||||
await load();
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="单证资料" description="出口抬头,用于 PI/CI/PL 卖方信息">
|
||||
<Card :loading="loading" class="max-w-3xl">
|
||||
<Form :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }" :model="form">
|
||||
<Form.Item label="英文名称">
|
||||
<Input v-model:value="form.legalNameEn" placeholder="Seller English Name" />
|
||||
</Form.Item>
|
||||
<Form.Item label="中文名称">
|
||||
<Input v-model:value="form.legalNameZh" />
|
||||
</Form.Item>
|
||||
<Form.Item label="英文地址">
|
||||
<Input.TextArea v-model:value="form.addressEn" :rows="2" />
|
||||
</Form.Item>
|
||||
<Form.Item label="中文地址">
|
||||
<Input.TextArea v-model:value="form.addressZh" :rows="2" />
|
||||
</Form.Item>
|
||||
<Form.Item label="国家/地区">
|
||||
<Input v-model:value="form.country" />
|
||||
</Form.Item>
|
||||
<Form.Item label="电话">
|
||||
<Input v-model:value="form.phone" />
|
||||
</Form.Item>
|
||||
<Form.Item label="邮箱">
|
||||
<Input v-model:value="form.email" />
|
||||
</Form.Item>
|
||||
<Form.Item label="税号">
|
||||
<Input v-model:value="form.taxNo" />
|
||||
</Form.Item>
|
||||
<Form.Item label="开户行">
|
||||
<Input v-model:value="form.bankName" />
|
||||
</Form.Item>
|
||||
<Form.Item label="账号">
|
||||
<Input v-model:value="form.bankAccount" />
|
||||
</Form.Item>
|
||||
<Form.Item label="SWIFT">
|
||||
<Input v-model:value="form.bankSwift" />
|
||||
</Form.Item>
|
||||
<Form.Item label="银行地址">
|
||||
<Input v-model:value="form.bankAddress" />
|
||||
</Form.Item>
|
||||
<Form.Item label="默认币种">
|
||||
<Input v-model:value="form.defaultCurrency" placeholder="USD" />
|
||||
</Form.Item>
|
||||
<Form.Item label="默认贸易术语">
|
||||
<Input v-model:value="form.defaultIncoterm" placeholder="FOB" />
|
||||
</Form.Item>
|
||||
<Form.Item label="备注">
|
||||
<Input.TextArea v-model:value="form.remark" :rows="2" />
|
||||
</Form.Item>
|
||||
<Form.Item :wrapper-col="{ offset: 6, span: 16 }">
|
||||
<Space>
|
||||
<PermissionGate code="crm:profile:update">
|
||||
<Button type="primary" :loading="saving" @click="handleSave">
|
||||
保存
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<Button @click="load">刷新</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,339 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CrmCustomerVO } from '#/api/crm/customer';
|
||||
import type { CrmProductVO } from '#/api/crm/product';
|
||||
import type { CrmQuoteDTO, CrmQuoteVO } from '#/api/crm/quote';
|
||||
|
||||
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 {
|
||||
createCrmQuoteApi,
|
||||
getCrmQuoteApi,
|
||||
updateCrmQuoteApi,
|
||||
} from '#/api/crm/quote';
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[960px]',
|
||||
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 CrmQuoteDTO.Item {
|
||||
_key: string;
|
||||
}
|
||||
|
||||
const formData = ref({
|
||||
customerId: undefined as number | undefined,
|
||||
quoteDate: dayjs() as Dayjs,
|
||||
validUntil: undefined as Dayjs | undefined,
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
async function open(edit = false, id?: number) {
|
||||
await loadOptions();
|
||||
isEdit.value = edit;
|
||||
editingId.value = id;
|
||||
if (edit && id) {
|
||||
const detail = await getCrmQuoteApi(id);
|
||||
formData.value = {
|
||||
customerId: detail.customerId,
|
||||
quoteDate: detail.quoteDate ? dayjs(detail.quoteDate) : dayjs(),
|
||||
validUntil: detail.validUntil ? dayjs(detail.validUntil) : undefined,
|
||||
currency: detail.currency ?? 'USD',
|
||||
incoterm: detail.incoterm ?? '',
|
||||
paymentTerms: detail.paymentTerms ?? '',
|
||||
remark: detail.remark ?? '',
|
||||
};
|
||||
items.value = (detail.items ?? []).map((it) => ({
|
||||
_key: `${it.id ?? Date.now()}-${Math.random()}`,
|
||||
productId: it.productId,
|
||||
productCode: it.productCode,
|
||||
nameEn: it.nameEn,
|
||||
nameZh: it.nameZh,
|
||||
spec: it.spec,
|
||||
unit: it.unit ?? 'PCS',
|
||||
qty: Number(it.qty) || 0,
|
||||
unitPrice: Number(it.unitPrice) || 0,
|
||||
remark: it.remark,
|
||||
}));
|
||||
modalApi.setState({ title: `编辑报价 ${detail.quoteNo}` });
|
||||
} else {
|
||||
formData.value = {
|
||||
customerId: undefined,
|
||||
quoteDate: dayjs(),
|
||||
validUntil: undefined,
|
||||
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.unit = p.unit || 'PCS';
|
||||
row.unitPrice = Number(p.unitPrice) || 0;
|
||||
}
|
||||
|
||||
function buildPayload(): CrmQuoteDTO.Create {
|
||||
return {
|
||||
customerId: formData.value.customerId!,
|
||||
quoteDate: formData.value.quoteDate?.format('YYYY-MM-DD'),
|
||||
validUntil: formData.value.validUntil?.format('YYYY-MM-DD'),
|
||||
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,
|
||||
unit: row.unit,
|
||||
qty: Number(row.qty),
|
||||
unitPrice: Number(row.unitPrice),
|
||||
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 updateCrmQuoteApi(editingId.value, payload);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createCrmQuoteApi(payload);
|
||||
message.success('创建成功');
|
||||
}
|
||||
modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '产品', key: 'product', width: 160 },
|
||||
{ title: '英文品名', key: 'nameEn', width: 160 },
|
||||
{ title: '规格', key: 'spec', width: 120 },
|
||||
{ title: '单位', key: 'unit', width: 80 },
|
||||
{ title: '数量', key: 'qty', width: 100 },
|
||||
{ title: '单价', key: 'unitPrice', width: 110 },
|
||||
{ title: '金额', key: 'amount', width: 100 },
|
||||
{ title: '', key: 'action', width: 60 },
|
||||
];
|
||||
|
||||
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.quoteDate" class="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="有效期至">
|
||||
<DatePicker v-model:value="formData.validUntil" class="w-full" />
|
||||
</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: 900 }"
|
||||
>
|
||||
<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 === 'spec'">
|
||||
<Input v-model:value="record.spec" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'unit'">
|
||||
<Input v-model:value="record.unit" />
|
||||
</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 === 'amount'">
|
||||
{{ ((Number(record.qty) || 0) * (Number(record.unitPrice) || 0)).toFixed(2) }}
|
||||
</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,265 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { CrmQuoteDTO, CrmQuoteVO } from '#/api/crm/quote';
|
||||
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 {
|
||||
changeCrmQuoteStatusApi,
|
||||
deleteCrmQuoteApi,
|
||||
exportCrmQuotePiApi,
|
||||
getCrmQuotePageApi,
|
||||
} from '#/api/crm/quote';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
|
||||
import QuoteModal from './components/QuoteModal.vue';
|
||||
|
||||
defineOptions({ name: 'CrmQuote' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const loading = ref(false);
|
||||
const modalRef = ref<InstanceType<typeof QuoteModal>>();
|
||||
const searchForm = ref({
|
||||
keyword: '',
|
||||
status: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const statusMap: Record<string, { color: string; label: string }> = {
|
||||
draft: { color: 'default', label: '草稿' },
|
||||
sent: { color: 'processing', label: '已发送' },
|
||||
accepted: { color: 'success', label: '已接受' },
|
||||
rejected: { color: 'error', label: '已拒绝' },
|
||||
expired: { color: 'warning', label: '已过期' },
|
||||
};
|
||||
|
||||
const actionCodes = [
|
||||
'crm:quote:create',
|
||||
'crm:quote:update',
|
||||
'crm:quote:delete',
|
||||
'crm:quote:status',
|
||||
'crm:quote:export',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(actionCodes);
|
||||
|
||||
const baseColumns: VxeGridProps<CrmQuoteVO.Info>['columns'] = [
|
||||
{ type: 'seq', title: '序号', minWidth: 60 },
|
||||
{ field: 'quoteNo', title: '报价号', minWidth: 140 },
|
||||
{ field: 'customerName', title: '客户', minWidth: 160 },
|
||||
{ field: 'quoteDate', title: '报价日', minWidth: 110 },
|
||||
{ field: 'currency', title: '币种', minWidth: 80 },
|
||||
{ field: 'totalAmount', title: '合计', minWidth: 110 },
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{ field: 'createTime', title: '创建时间', minWidth: 160 },
|
||||
];
|
||||
|
||||
const actionColumn: NonNullable<
|
||||
VxeGridProps<CrmQuoteVO.Info>['columns']
|
||||
>[number] = {
|
||||
title: '操作',
|
||||
width: 280,
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const tableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(baseColumns ?? []), actionColumn]
|
||||
: (baseColumns ?? []),
|
||||
);
|
||||
|
||||
const gridOptions: VxeGridProps<CrmQuoteVO.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<CrmQuoteDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
keyword: searchForm.value.keyword || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getCrmQuotePageApi(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: CrmQuoteVO.Info) {
|
||||
await deleteCrmQuoteApi(row.id);
|
||||
message.success('已删除');
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function handleStatus(row: CrmQuoteVO.Info, status: string) {
|
||||
await changeCrmQuoteStatusApi(row.id, { status });
|
||||
message.success('状态已更新');
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
async function handleExportPi(row: CrmQuoteVO.Info) {
|
||||
const detail = await exportCrmQuotePiApi(row.id);
|
||||
message.success('PI 已生成');
|
||||
if (detail.latestPiAccessUrl) {
|
||||
window.open(detail.latestPiAccessUrl, '_blank');
|
||||
}
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
function statusActions(row: CrmQuoteVO.Info) {
|
||||
const s = row.status;
|
||||
const actions: Array<{ key: string; label: string }> = [];
|
||||
if (s === 'draft') {
|
||||
actions.push({ key: 'sent', label: '标记已发送' });
|
||||
actions.push({ key: 'rejected', label: '标记拒绝' });
|
||||
} else if (s === 'sent') {
|
||||
actions.push({ key: 'accepted', label: '标记已接受' });
|
||||
actions.push({ key: 'rejected', label: '标记拒绝' });
|
||||
actions.push({ key: 'expired', label: '标记过期' });
|
||||
actions.push({ key: 'draft', label: '退回草稿' });
|
||||
} else if (s === 'rejected' || s === 'expired') {
|
||||
actions.push({ key: 'draft', label: '重新打开为草稿' });
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid>
|
||||
<template #toolbar-tools>
|
||||
<PermissionGate code="crm:quote: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:quote:update">
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="row.status !== 'draft'"
|
||||
@click="modalRef?.open(true, row.id)"
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:quote:export">
|
||||
<Button type="link" size="small" @click="handleExportPi(row)">
|
||||
导出PI
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="crm:quote: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:quote:delete">
|
||||
<Popconfirm
|
||||
v-if="row.status === 'draft' || row.status === 'rejected'"
|
||||
title="确认删除该报价?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
<QuoteModal ref="modalRef" @success="gridApi.reload()" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user