feat:【antd】【erp 系统】finance/receipt 的迁移 1/4(初始化)

This commit is contained in:
YunaiV
2025-10-05 11:04:27 +08:00
parent 9a17613823
commit 95ba94ee5e
6 changed files with 1516 additions and 21 deletions

View File

@@ -0,0 +1,599 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { erpPriceInputFormatter } from '@vben/utils';
import { getAccountSimpleList } from '#/api/erp/finance/account';
import { getCustomerSimpleList } from '#/api/erp/sale/customer';
import { getSimpleUserList } from '#/api/system/user';
import { getRangePickerDefaultProps } from '#/utils';
/** 表单的配置项 */
export function useFormSchema(formType: string): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'no',
label: '收款单号',
component: 'Input',
componentProps: {
placeholder: '系统自动生成',
disabled: true,
},
},
{
fieldName: 'receiptTime',
label: '收款时间',
component: 'DatePicker',
componentProps: {
disabled: formType === 'detail',
placeholder: '选择收款时间',
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'x',
},
rules: 'required',
},
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
componentProps: {
disabled: formType === 'detail',
placeholder: '请选择客户',
allowClear: true,
showSearch: true,
api: getCustomerSimpleList,
fieldNames: {
label: 'name',
value: 'id',
},
},
rules: 'required',
},
{
fieldName: 'financeUserId',
label: '财务人员',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择财务人员',
allowClear: true,
showSearch: true,
api: getSimpleUserList,
fieldNames: {
label: 'nickname',
value: 'id',
},
},
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
autoSize: { minRows: 1, maxRows: 1 },
disabled: formType === 'detail',
},
formItemClass: 'col-span-2',
},
{
fieldName: 'fileUrl',
label: '附件',
component: 'FileUpload',
componentProps: {
maxNumber: 1,
maxSize: 10,
accept: [
'pdf',
'doc',
'docx',
'xls',
'xlsx',
'txt',
'jpg',
'jpeg',
'png',
],
showDescription: formType !== 'detail',
disabled: formType === 'detail',
},
formItemClass: 'col-span-3',
},
{
fieldName: 'items',
label: '销售出库、退货单',
component: 'Input',
formItemClass: 'col-span-3',
},
{
fieldName: 'accountId',
label: '收款账户',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择收款账户',
allowClear: true,
showSearch: true,
api: getAccountSimpleList,
fieldNames: {
label: 'name',
value: 'id',
},
},
},
{
fieldName: 'totalPrice',
label: '合计收款',
component: 'InputNumber',
componentProps: {
placeholder: '合计收款',
precision: 2,
formatter: erpPriceInputFormatter,
disabled: true,
},
},
{
fieldName: 'discountPrice',
label: '优惠金额',
component: 'InputNumber',
componentProps: {
disabled: formType === 'detail',
placeholder: '请输入优惠金额',
precision: 2,
formatter: erpPriceInputFormatter,
},
},
{
fieldName: 'receiptPrice',
label: '实际收款',
component: 'InputNumber',
componentProps: {
placeholder: '实际收款',
precision: 2,
formatter: erpPriceInputFormatter,
disabled: true,
},
dependencies: {
triggerFields: ['totalPrice', 'discountPrice'],
componentProps: (values) => {
const totalPrice = values.totalPrice || 0;
const discountPrice = values.discountPrice || 0;
values.receiptPrice = totalPrice - discountPrice;
return {};
},
},
},
];
}
/** 表单的明细表格列 */
export function useFormItemColumns(
formData?: any[],
): VxeTableGridOptions['columns'] {
return [
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
{
field: 'bizNo',
title: '销售单据编号',
minWidth: 200,
},
{
field: 'totalPrice',
title: '应收金额',
minWidth: 100,
formatter: 'formatAmount2',
},
{
field: 'receiptedPrice',
title: '已收金额',
minWidth: 100,
formatter: 'formatAmount2',
},
{
field: 'receiptPrice',
title: '本次收款',
minWidth: 115,
fixed: 'right',
slots: { default: 'receiptPrice' },
},
{
field: 'remark',
title: '备注',
minWidth: 150,
slots: { default: 'remark' },
},
{
title: '操作',
width: 50,
fixed: 'right',
slots: { default: 'actions' },
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'no',
label: '收款单号',
component: 'Input',
componentProps: {
placeholder: '请输入收款单号',
allowClear: true,
},
},
{
fieldName: 'receiptTime',
label: '收款时间',
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
allowClear: true,
},
},
{
fieldName: 'customerId',
label: '客户',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择客户',
allowClear: true,
showSearch: true,
api: getCustomerSimpleList,
fieldNames: {
label: 'name',
value: 'id',
},
},
},
{
fieldName: 'creator',
label: '创建人',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择创建人',
allowClear: true,
showSearch: true,
api: getSimpleUserList,
fieldNames: {
label: 'nickname',
value: 'id',
},
},
},
{
fieldName: 'financeUserId',
label: '财务人员',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择财务人员',
allowClear: true,
showSearch: true,
api: getSimpleUserList,
fieldNames: {
label: 'nickname',
value: 'id',
},
},
},
{
fieldName: 'accountId',
label: '收款账户',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择收款账户',
allowClear: true,
showSearch: true,
api: getAccountSimpleList,
fieldNames: {
label: 'name',
value: 'id',
},
},
},
{
fieldName: 'status',
label: '状态',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
placeholder: '请选择状态',
allowClear: true,
},
},
{
fieldName: 'remark',
label: '备注',
component: 'Input',
componentProps: {
placeholder: '请输入备注',
allowClear: true,
},
},
{
fieldName: 'bizNo',
label: '销售单号',
component: 'Input',
componentProps: {
placeholder: '请输入销售单号',
allowClear: true,
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 50,
fixed: 'left',
},
{
field: 'no',
title: '收款单号',
width: 180,
fixed: 'left',
},
{
field: 'customerName',
title: '客户',
minWidth: 120,
},
{
field: 'receiptTime',
title: '收款时间',
width: 160,
formatter: 'formatDate',
},
{
field: 'creatorName',
title: '创建人',
minWidth: 120,
},
{
field: 'financeUserName',
title: '财务人员',
minWidth: 120,
},
{
field: 'accountName',
title: '收款账户',
minWidth: 120,
},
{
field: 'totalPrice',
title: '合计收款',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'discountPrice',
title: '优惠金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'receiptPrice',
title: '实际收款',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'status',
title: '状态',
minWidth: 90,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
},
},
{
title: '操作',
width: 220,
fixed: 'right',
slots: { default: 'actions' },
},
];
}
/** 销售出库单选择表单的配置项 */
export function useSaleOutGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'no',
label: '出库单号',
component: 'Input',
componentProps: {
placeholder: '请输入出库单号',
allowClear: true,
},
},
{
fieldName: 'customerId',
label: '客户',
component: 'Input',
componentProps: {
disabled: true,
placeholder: '已自动选择客户',
},
},
{
fieldName: 'receiptStatus',
label: '收款状态',
component: 'Select',
componentProps: {
options: [
{ label: '未收款', value: 0 },
{ label: '部分收款', value: 1 },
{ label: '全部收款', value: 2 },
],
placeholder: '请选择收款状态',
allowClear: true,
},
},
];
}
/** 销售出库单选择列表的字段 */
export function useSaleOutGridColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 50,
fixed: 'left',
},
{
field: 'no',
title: '出库单号',
width: 200,
fixed: 'left',
},
{
field: 'customerName',
title: '客户',
minWidth: 120,
},
{
field: 'outTime',
title: '出库时间',
width: 160,
formatter: 'formatDate',
},
{
field: 'totalPrice',
title: '应收金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'receiptPrice',
title: '已收金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'unReceiptPrice',
title: '未收金额',
formatter: ({ row }) => {
return erpPriceInputFormatter(row.totalPrice - row.receiptPrice || 0);
},
minWidth: 120,
},
{
field: 'status',
title: '状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
},
},
];
}
/** 销售退货单选择表单的配置项 */
export function useSaleReturnGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'no',
label: '退货单号',
component: 'Input',
componentProps: {
placeholder: '请输入退货单号',
allowClear: true,
},
},
{
fieldName: 'customerId',
label: '客户',
component: 'Input',
componentProps: {
disabled: true,
placeholder: '已自动选择客户',
},
},
{
fieldName: 'refundStatus',
label: '退款状态',
component: 'Select',
componentProps: {
options: [
{ label: '未退款', value: 0 },
{ label: '部分退款', value: 1 },
{ label: '全部退款', value: 2 },
],
placeholder: '请选择退款状态',
allowClear: true,
},
},
];
}
/** 销售退货单选择列表的字段 */
export function useSaleReturnGridColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 50,
fixed: 'left',
},
{
field: 'no',
title: '退货单号',
width: 200,
fixed: 'left',
},
{
field: 'customerName',
title: '客户',
minWidth: 120,
},
{
field: 'returnTime',
title: '退货时间',
width: 160,
formatter: 'formatDate',
},
{
field: 'totalPrice',
title: '应退金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'refundPrice',
title: '已退金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'unRefundPrice',
title: '未退金额',
formatter: ({ row }) => {
return erpPriceInputFormatter(row.totalPrice - row.refundPrice || 0);
},
minWidth: 120,
},
{
field: 'status',
title: '状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
},
},
];
}

View File

@@ -1,34 +1,225 @@
<script lang="ts" setup>
import { DocAlert, Page } from '@vben/common-ui';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpFinanceReceiptApi } from '#/api/erp/finance/receipt';
import { Button } from 'ant-design-vue';
import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteFinanceReceipt,
exportFinanceReceipt,
getFinanceReceiptPage,
updateFinanceReceiptStatus,
} from '#/api/erp/finance/receipt';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
/** ERP 收款单列表 */
defineOptions({ name: 'ErpFinanceReceipt' });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportFinanceReceipt(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '收款单.xls', source: data });
}
/** 新增收款单 */
function handleCreate() {
formModalApi.setData({ type: 'create' }).open();
}
/** 编辑收款单 */
function handleEdit(row: ErpFinanceReceiptApi.FinanceReceipt) {
formModalApi.setData({ type: 'edit', id: row.id }).open();
}
/** 删除收款单 */
async function handleDelete(ids: number[]) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
});
try {
await deleteFinanceReceipt(ids);
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
/** 审批/反审批操作 */
async function handleUpdateStatus(
row: ErpFinanceReceiptApi.FinanceReceipt,
status: number,
) {
const hideLoading = message.loading({
content: `确定${status === 20 ? '审批' : '反审批'}该收款单吗?`,
duration: 0,
});
try {
await updateFinanceReceiptStatus(row.id!, status);
message.success(`${status === 20 ? '审批' : '反审批'}成功`);
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: ErpFinanceReceiptApi.FinanceReceipt[];
}) {
checkedIds.value = records.map((item) => item.id!);
}
/** 查看详情 */
function handleDetail(row: ErpFinanceReceiptApi.FinanceReceipt) {
formModalApi.setData({ type: 'detail', id: row.id }).open();
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getFinanceReceiptPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<ErpFinanceReceiptApi.FinanceReceipt>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
<template>
<Page>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【财务】采购付款、销售收款"
url="https://doc.iocoder.cn/sale/finance-payment-receipt/"
/>
</template>
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
>
该功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/finance/receipt/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/finance/receipt/index
代码pull request 贡献给我们
</Button>
<FormModal @success="handleRefresh" />
<Grid table-title="收款单列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['收款单']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['erp:finance-receipt:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['erp:finance-receipt:export'],
onClick: handleExport,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['erp:finance-receipt:delete'],
popConfirm: {
title: `是否删除所选中数据?`,
confirm: handleDelete.bind(null, checkedIds),
},
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.detail'),
type: 'link',
icon: ACTION_ICON.VIEW,
auth: ['erp:finance-receipt:query'],
onClick: handleDetail.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['erp:finance-receipt:update'],
ifShow: () => row.status !== 20,
onClick: handleEdit.bind(null, row),
},
{
label: row.status === 10 ? '审批' : '反审批',
type: 'link',
auth: ['erp:finance-receipt:update-status'],
popConfirm: {
title: `确认${row.status === 10 ? '审批' : '反审批'}${row.no}吗?`,
confirm: handleUpdateStatus.bind(
null,
row,
row.status === 10 ? 20 : 10,
),
},
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
color: 'error',
auth: ['erp:finance-receipt:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
confirm: handleDelete.bind(null, [row.id!]),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,194 @@
<script lang="ts" setup>
import type { ErpFinanceReceiptApi } from '#/api/erp/finance/receipt';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { getAccountSimpleList } from '#/api/erp/finance/account';
import {
createFinanceReceipt,
getFinanceReceipt,
updateFinanceReceipt,
} from '#/api/erp/finance/receipt';
import { useFormSchema } from '../data';
import ItemForm from './item-form.vue';
const emit = defineEmits(['success']);
const formData = ref<
ErpFinanceReceiptApi.FinanceReceipt & {
fileUrl?: string;
}
>({
id: undefined,
no: undefined,
customerId: undefined,
accountId: undefined,
financeUserId: undefined,
receiptTime: undefined,
remark: undefined,
fileUrl: undefined,
totalPrice: 0,
discountPrice: 0,
receiptPrice: 0,
items: [],
});
const formType = ref(''); // 表单类型:'create' | 'edit' | 'detail'
const itemFormRef = ref<InstanceType<typeof ItemForm>>();
/* eslint-disable unicorn/no-nested-ternary */
const getTitle = computed(() =>
formType.value === 'create'
? $t('ui.actionTitle.create', ['收款单'])
: formType.value === 'edit'
? $t('ui.actionTitle.edit', ['收款单'])
: '收款单详情',
);
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
labelWidth: 120,
},
wrapperClass: 'grid-cols-3',
layout: 'vertical',
schema: useFormSchema(formType.value),
showDefaultActions: false,
handleValuesChange: (values, changedFields) => {
if (formData.value) {
if (changedFields.includes('customerId')) {
formData.value.customerId = values.customerId;
}
// 目的:同步到 item-form 组件,触发整体的价格计算
if (changedFields.includes('discountPrice')) {
formData.value.discountPrice = values.discountPrice;
formData.value.receiptPrice =
formData.value.totalPrice - values.discountPrice;
formApi.setValues({
receiptPrice: formData.value.receiptPrice,
});
}
}
},
});
/** 更新收款项 */
const handleUpdateItems = (
items: ErpFinanceReceiptApi.FinanceReceiptItem[],
) => {
formData.value.items = items;
formApi.setValues({
items,
});
};
/** 更新总金额 */
const handleUpdateTotalPrice = (totalPrice: number) => {
formData.value.totalPrice = totalPrice;
formApi.setValues({
totalPrice: formData.value.totalPrice,
});
};
/** 更新收款金额 */
const handleUpdateReceiptPrice = (receiptPrice: number) => {
formData.value.receiptPrice = receiptPrice;
formApi.setValues({
receiptPrice: formData.value.receiptPrice,
});
};
/** 创建或更新收款单 */
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
const itemFormInstance = Array.isArray(itemFormRef.value)
? itemFormRef.value[0]
: itemFormRef.value;
try {
itemFormInstance.validate();
} catch (error: any) {
message.error(error.message || '子表单验证失败');
return;
}
modalApi.lock();
// 提交表单
const data =
(await formApi.getValues()) as ErpFinanceReceiptApi.FinanceReceipt;
try {
await (formType.value === 'create'
? createFinanceReceipt(data)
: updateFinanceReceipt(data));
// 关闭并提示
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
// 加载数据
const data = modalApi.getData<{ id?: number; type: string }>();
formType.value = data.type;
formApi.setDisabled(formType.value === 'detail');
formApi.updateSchema(useFormSchema(formType.value));
if (!data || !data.id) {
// 新增时,默认选中账户
const accountList = await getAccountSimpleList();
const defaultAccount = accountList.find((item) => item.defaultStatus);
if (defaultAccount) {
await formApi.setValues({ accountId: defaultAccount.id });
}
return;
}
modalApi.lock();
try {
formData.value = await getFinanceReceipt(data.id);
// 设置到 values
await formApi.setValues(formData.value, false);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal
:title="getTitle"
class="w-3/4"
:show-confirm-button="formType !== 'detail'"
>
<Form class="mx-3">
<template #items>
<ItemForm
ref="itemFormRef"
:items="formData?.items ?? []"
:customer-id="formData?.customerId"
:disabled="formType === 'detail'"
:discount-price="formData?.discountPrice ?? 0"
@update:items="handleUpdateItems"
@update:total-price="handleUpdateTotalPrice"
@update:receipt-price="handleUpdateReceiptPrice"
/>
</template>
</Form>
</Modal>
</template>

View File

@@ -0,0 +1,295 @@
<script lang="ts" setup>
import type { ErpFinanceReceiptApi } from '#/api/erp/finance/receipt';
import type { ErpSaleOutApi } from '#/api/erp/sale/out';
import type { ErpSaleReturnApi } from '#/api/erp/sale/return';
import { computed, nextTick, ref, watch } from 'vue';
import { ErpBizType } from '@vben/constants';
import { erpPriceInputFormatter } from '@vben/utils';
import { Input, InputNumber, message } from 'ant-design-vue';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { useFormItemColumns } from '../data';
import SaleOutSelect from './sale-out-select.vue';
import SaleReturnSelect from './sale-return-select.vue';
interface Props {
items?: ErpFinanceReceiptApi.FinanceReceiptItem[];
customerId?: number;
disabled?: boolean;
discountPrice?: number;
}
const props = withDefaults(defineProps<Props>(), {
items: () => [],
customerId: undefined,
disabled: false,
discountPrice: 0,
});
const emit = defineEmits([
'update:items',
'update:total-price',
'update:receipt-price',
]);
const tableData = ref<ErpFinanceReceiptApi.FinanceReceiptItem[]>([]); // 表格数据
/** 获取表格合计数据 */
const summaries = computed(() => {
return {
totalPrice: tableData.value.reduce(
(sum, item) => sum + (item.totalPrice || 0),
0,
),
receiptedPrice: tableData.value.reduce(
(sum, item) => sum + (item.receiptedPrice || 0),
0,
),
receiptPrice: tableData.value.reduce(
(sum, item) => sum + (item.receiptPrice || 0),
0,
),
};
});
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useFormItemColumns(tableData.value),
data: tableData.value,
minHeight: 250,
autoResize: true,
border: true,
rowConfig: {
keyField: 'row_id',
isHover: true,
},
pagerConfig: {
enabled: false,
},
toolbarConfig: {
enabled: false,
},
},
});
/** 监听外部传入的列数据 */
watch(
() => props.items,
async (items) => {
if (!items) {
return;
}
tableData.value = [...items];
await nextTick(); // 特殊:保证 gridApi 已经初始化
await gridApi.grid.reloadData(tableData.value);
// 更新表格列配置
const columns = useFormItemColumns(tableData.value);
await gridApi.grid.reloadColumn(columns);
},
{
immediate: true,
},
);
/** 计算 totalPrice、receiptPrice 价格 */
watch(
() => [tableData.value, props.discountPrice],
() => {
if (!tableData.value || tableData.value.length === 0) {
return;
}
const totalPrice = tableData.value.reduce(
(prev, curr) => prev + (curr.totalPrice || 0),
0,
);
const receiptPrice = tableData.value.reduce(
(prev, curr) => prev + (curr.receiptPrice || 0),
0,
);
const finalReceiptPrice = receiptPrice - (props.discountPrice || 0);
// 通知父组件更新
emit('update:total-price', totalPrice);
emit('update:receipt-price', finalReceiptPrice);
},
{ deep: true },
);
/** 添加销售出库单 */
const saleOutSelectRef = ref();
const handleOpenSaleOut = () => {
if (!props.customerId) {
message.error('请选择客户');
return;
}
saleOutSelectRef.value?.open(props.customerId);
};
const handleAddSaleOut = (rows: ErpSaleOutApi.SaleOut[]) => {
rows.forEach((row) => {
const newItem: ErpFinanceReceiptApi.FinanceReceiptItem = {
bizId: row.id,
bizType: ErpBizType.SALE_OUT,
bizNo: row.no,
totalPrice: row.totalPrice,
receiptedPrice: row.receiptPrice,
receiptPrice: row.totalPrice - row.receiptPrice,
remark: undefined,
};
tableData.value.push(newItem);
});
emit('update:items', [...tableData.value]);
};
/** 添加销售退货单 */
const saleReturnSelectRef = ref();
const handleOpenSaleReturn = () => {
if (!props.customerId) {
message.error('请选择客户');
return;
}
saleReturnSelectRef.value?.open(props.customerId);
};
const handleAddSaleReturn = (rows: ErpSaleReturnApi.SaleReturn[]) => {
rows.forEach((row) => {
const newItem: ErpFinanceReceiptApi.FinanceReceiptItem = {
bizId: row.id,
bizType: ErpBizType.SALE_RETURN,
bizNo: row.no,
totalPrice: -row.totalPrice,
receiptedPrice: -row.refundPrice,
receiptPrice: -row.totalPrice + row.refundPrice,
remark: undefined,
};
tableData.value.push(newItem);
});
emit('update:items', [...tableData.value]);
};
/** 删除行 */
const handleDelete = async (row: any) => {
const index = tableData.value.findIndex(
(item) => item.bizId === row.bizId && item.bizType === row.bizType,
);
if (index !== -1) {
tableData.value.splice(index, 1);
}
// 通知父组件更新
emit('update:items', [...tableData.value]);
};
/** 处理行数据变更 */
const handleRowChange = (row: any) => {
const index = tableData.value.findIndex(
(item) => item.bizId === row.bizId && item.bizType === row.bizType,
);
if (index === -1) {
tableData.value.push(row);
} else {
tableData.value[index] = row;
}
emit('update:items', [...tableData.value]);
};
/** 表单校验 */
const validate = () => {
// 检查是否有明细
if (tableData.value.length === 0) {
throw new Error('请添加收款明细');
}
// 检查每行的收款金额
for (let i = 0; i < tableData.value.length; i++) {
const item = tableData.value[i];
if (!item.receiptPrice || item.receiptPrice <= 0) {
throw new Error(`${i + 1}本次收款必须大于0`);
}
}
};
defineExpose({ validate });
</script>
<template>
<Grid class="w-full">
<template #receiptPrice="{ row }">
<InputNumber
v-model:value="row.receiptPrice"
:precision="2"
:disabled="disabled"
:formatter="erpPriceInputFormatter"
placeholder="请输入本次收款"
@change="handleRowChange(row)"
/>
</template>
<template #remark="{ row }">
<Input
v-model:value="row.remark"
:disabled="disabled"
placeholder="请输入备注"
@change="handleRowChange(row)"
/>
</template>
<template #actions="{ row }">
<TableAction
v-if="!disabled"
:actions="[
{
label: '删除',
type: 'link',
danger: true,
popConfirm: {
title: '确认删除该收款明细吗?',
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
<template #bottom>
<div class="border-border bg-muted mt-2 rounded border p-2">
<div class="text-muted-foreground flex justify-between text-sm">
<span class="text-foreground font-medium">合计</span>
<div class="flex space-x-4">
<span>
合计收款{{ erpPriceInputFormatter(summaries.totalPrice) }}
</span>
<span>
已收金额{{ erpPriceInputFormatter(summaries.receiptedPrice) }}
</span>
<span>
本次收款
{{ erpPriceInputFormatter(summaries.receiptPrice) }}
</span>
</div>
</div>
</div>
<TableAction
v-if="!disabled"
class="mt-2 flex justify-center"
:actions="[
{
label: '添加销售出库单',
type: 'default',
onClick: handleOpenSaleOut,
},
{
label: '添加销售退货单',
type: 'default',
onClick: handleOpenSaleReturn,
},
]"
/>
</template>
</Grid>
<!-- 销售出库单选择组件 -->
<SaleOutSelect ref="saleOutSelectRef" @success="handleAddSaleOut" />
<!-- 销售退货单选择组件 -->
<SaleReturnSelect ref="saleReturnSelectRef" @success="handleAddSaleReturn" />
</template>

View File

@@ -0,0 +1,108 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpSaleOutApi } from '#/api/erp/sale/out';
import { ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getSaleOutPage } from '#/api/erp/sale/out';
import { useSaleOutGridColumns, useSaleOutGridFormSchema } from '../data';
const emit = defineEmits<{
success: [rows: ErpSaleOutApi.SaleOut[]];
}>();
const customerId = ref<number>(); // 客户ID
const open = ref<boolean>(false); // 弹窗是否打开
const selectedRows = ref<ErpSaleOutApi.SaleOut[]>([]); // 选中的行
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useSaleOutGridFormSchema(),
},
gridOptions: {
columns: useSaleOutGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getSaleOutPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
customerId: customerId.value,
receiptEnable: true, // 只查询可收款的
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
checkboxConfig: {
highlight: true,
range: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<ErpSaleOutApi.SaleOut>,
gridEvents: {
checkboxChange: ({
records,
}: {
records: ErpSaleOutApi.SaleOut[];
}) => {
selectedRows.value = records;
},
checkboxAll: ({ records }: { records: ErpSaleOutApi.SaleOut[] }) => {
selectedRows.value = records;
},
},
});
/** 打开弹窗 */
const openModal = (id: number) => {
// 重置数据
customerId.value = id;
open.value = true;
selectedRows.value = [];
// 查询列表
gridApi.formApi?.resetForm();
gridApi.formApi?.setValues({ customerId: id });
gridApi.query();
};
/** 确认选择销售出库单 */
const handleOk = () => {
if (selectedRows.value.length === 0) {
message.warning('请选择要添加的销售出库单');
return;
}
emit('success', selectedRows.value);
open.value = false;
};
defineExpose({ open: openModal });
</script>
<template>
<Modal
class="!w-[50vw]"
v-model:open="open"
title="选择销售出库单"
@ok="handleOk"
>
<Grid
class="max-h-[600px]"
table-title="销售出库单列表(仅展示可收款的单据)"
/>
</Modal>
</template>

View File

@@ -0,0 +1,108 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpSaleReturnApi } from '#/api/erp/sale/return';
import { ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getSaleReturnPage } from '#/api/erp/sale/return';
import { useSaleReturnGridColumns, useSaleReturnGridFormSchema } from '../data';
const emit = defineEmits<{
success: [rows: ErpSaleReturnApi.SaleReturn[]];
}>();
const customerId = ref<number>(); // 客户ID
const open = ref<boolean>(false); // 弹窗是否打开
const selectedRows = ref<ErpSaleReturnApi.SaleReturn[]>([]); // 选中的行
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useSaleReturnGridFormSchema(),
},
gridOptions: {
columns: useSaleReturnGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getSaleReturnPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
customerId: customerId.value,
refundEnable: true, // 只查询可退款的
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
checkboxConfig: {
highlight: true,
range: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<ErpSaleReturnApi.SaleReturn>,
gridEvents: {
checkboxChange: ({
records,
}: {
records: ErpSaleReturnApi.SaleReturn[];
}) => {
selectedRows.value = records;
},
checkboxAll: ({ records }: { records: ErpSaleReturnApi.SaleReturn[] }) => {
selectedRows.value = records;
},
},
});
/** 打开弹窗 */
const openModal = (id: number) => {
// 重置数据
customerId.value = id;
open.value = true;
selectedRows.value = [];
// 查询列表
gridApi.formApi?.resetForm();
gridApi.formApi?.setValues({ customerId: id });
gridApi.query();
};
/** 确认选择销售退货单 */
const handleOk = () => {
if (selectedRows.value.length === 0) {
message.warning('请选择要添加的销售退货单');
return;
}
emit('success', selectedRows.value);
open.value = false;
};
defineExpose({ open: openModal });
</script>
<template>
<Modal
class="!w-[50vw]"
v-model:open="open"
title="选择销售退货单"
@ok="handleOk"
>
<Grid
class="max-h-[600px]"
table-title="销售退货单列表(仅展示可退款的单据)"
/>
</Modal>
</template>