feat:【antd】【erp 系统】finance/payment 的迁移 1/4(列表 ok)

This commit is contained in:
YunaiV
2025-10-05 09:28:53 +08:00
parent 02adb68581
commit 386919030d
6 changed files with 1511 additions and 21 deletions

View File

@@ -0,0 +1,409 @@
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 { getSupplierSimpleList } from '#/api/erp/purchase/supplier';
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: 'paymentTime',
label: '付款时间',
component: 'DatePicker',
componentProps: {
disabled: formType === 'detail',
placeholder: '选择付款时间',
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'x',
},
rules: 'required',
},
{
fieldName: 'supplierId',
label: '供应商',
component: 'ApiSelect',
componentProps: {
disabled: formType === 'detail',
placeholder: '请选择供应商',
allowClear: true,
showSearch: true,
api: getSupplierSimpleList,
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: 'paymentPrice',
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.paymentPrice = 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: 'paidPrice',
title: '已付金额',
minWidth: 100,
formatter: 'formatAmount2',
},
{
field: 'paymentPrice',
title: '本次付款',
minWidth: 115,
fixed: 'right',
slots: { default: 'paymentPrice' },
},
{
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: 'paymentTime',
label: '付款时间',
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
allowClear: true,
},
},
{
fieldName: 'supplierId',
label: '供应商',
component: 'ApiSelect',
componentProps: {
placeholder: '请选择供应商',
allowClear: true,
showSearch: true,
api: getSupplierSimpleList,
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: 'supplierName',
title: '供应商',
minWidth: 120,
},
{
field: 'paymentTime',
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: 'paymentPrice',
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' },
},
];
}

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 { ErpFinancePaymentApi } from '#/api/erp/finance/payment';
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 {
deleteFinancePayment,
exportFinancePayment,
getFinancePaymentPage,
updateFinancePaymentStatus,
} from '#/api/erp/finance/payment';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
/** ERP 付款单列表 */
defineOptions({ name: 'ErpFinancePayment' });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportFinancePayment(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '付款单.xls', source: data });
}
/** 新增付款单 */
function handleCreate() {
formModalApi.setData({ type: 'create' }).open();
}
/** 编辑付款单 */
function handleEdit(row: ErpFinancePaymentApi.FinancePayment) {
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 deleteFinancePayment(ids);
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
/** 审批/反审批操作 */
async function handleUpdateStatus(
row: ErpFinancePaymentApi.FinancePayment,
status: number,
) {
const hideLoading = message.loading({
content: `确定${status === 20 ? '审批' : '反审批'}该付款单吗?`,
duration: 0,
});
try {
await updateFinancePaymentStatus(row.id!, status);
message.success(`${status === 20 ? '审批' : '反审批'}成功`);
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: ErpFinancePaymentApi.FinancePayment[];
}) {
checkedIds.value = records.map((item) => item.id!);
}
/** 查看详情 */
function handleDetail(row: ErpFinancePaymentApi.FinancePayment) {
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 getFinancePaymentPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<ErpFinancePaymentApi.FinancePayment>,
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/payment/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/finance/payment/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-payment:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['erp:finance-payment:export'],
onClick: handleExport,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['erp:finance-payment: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-payment:query'],
onClick: handleDetail.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['erp:finance-payment:update'],
ifShow: () => row.status !== 20,
onClick: handleEdit.bind(null, row),
},
{
label: row.status === 10 ? '审批' : '反审批',
type: 'link',
auth: ['erp:finance-payment: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-payment:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
confirm: handleDelete.bind(null, [row.id!]),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,179 @@
<script lang="ts" setup>
import type { ErpFinancePaymentApi } from '#/api/erp/finance/payment';
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 {
createFinancePayment,
getFinancePayment,
updateFinancePayment,
} from '#/api/erp/finance/payment';
import { useFormSchema } from '../data';
import ItemForm from './item-form.vue';
const emit = defineEmits(['success']);
const formData = ref<
ErpFinancePaymentApi.FinancePayment & {
fileUrl?: string;
}
>({
id: undefined,
no: undefined,
supplierId: undefined,
accountId: undefined,
financeUserId: undefined,
paymentTime: undefined,
remark: undefined,
fileUrl: undefined,
totalPrice: 0,
discountPrice: 0,
paymentPrice: 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) => {
// 目的:同步到 item-form 组件,触发整体的价格计算
if (formData.value && changedFields.includes('discountPrice')) {
formData.value.discountPrice = values.discountPrice;
// 重新计算实际付款
formData.value.paymentPrice =
formData.value.totalPrice - values.discountPrice;
formApi.setValues({
paymentPrice: formData.value.paymentPrice,
});
}
},
});
/** 更新付款项 */
const handleUpdateItems = (
items: ErpFinancePaymentApi.FinancePaymentItem[],
) => {
formData.value.items = items;
// 重新计算合计付款
const totalPrice = items.reduce((prev, curr) => prev + curr.paymentPrice, 0);
formData.value.totalPrice = totalPrice;
formData.value.paymentPrice = totalPrice - formData.value.discountPrice;
formApi.setValues({
items,
totalPrice: formData.value.totalPrice,
paymentPrice: formData.value.paymentPrice,
});
};
/** 创建或更新付款单 */
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 ErpFinancePaymentApi.FinancePayment;
try {
await (formType.value === 'create'
? createFinancePayment(data)
: updateFinancePayment(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 getFinancePayment(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>
<div class="space-y-4">
<ItemForm
ref="itemFormRef"
:items="formData?.items ?? []"
:supplier-id="formData?.supplierId"
:disabled="formType === 'detail'"
@update:items="handleUpdateItems"
/>
</div>
</template>
</Form>
</Modal>
</template>

View File

@@ -0,0 +1,281 @@
<script lang="ts" setup>
import type { ErpFinancePaymentApi } from '#/api/erp/finance/payment';
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
import type { ErpPurchaseReturnApi } from '#/api/erp/purchase/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';
interface Props {
items?: ErpFinancePaymentApi.FinancePaymentItem[];
supplierId?: number;
disabled?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
items: () => [],
disabled: false,
});
const emit = defineEmits(['update:items']);
const tableData = ref<ErpFinancePaymentApi.FinancePaymentItem[]>([]); // 表格数据
/** 获取表格合计数据 */
const summaries = computed(() => {
return {
totalPrice: tableData.value.reduce(
(sum, item) => sum + (item.totalPrice || 0),
0,
),
paidPrice: tableData.value.reduce(
(sum, item) => sum + (item.paidPrice || 0),
0,
),
paymentPrice: tableData.value.reduce(
(sum, item) => sum + (item.paymentPrice || 0),
0,
),
};
});
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useFormItemColumns(tableData.value),
data: tableData.value,
minHeight: 200,
autoResize: true,
border: true,
showOverflow: true,
rowConfig: {
keyField: 'row_id',
isHover: true,
},
pagerConfig: {
enabled: false,
},
toolbarConfig: {
enabled: false,
},
editConfig: {
trigger: 'click',
mode: 'cell',
},
editRules: {
paymentPrice: [
{ required: true, message: '本次付款不能为空' },
{ type: 'number', min: 0, message: '本次付款不能小于0' },
],
},
},
});
/** 监听外部传入的列数据 */
watch(
() => props.items,
async (items) => {
if (!items) {
return;
}
items.forEach((item) => initRow(item));
tableData.value = [...items];
await nextTick(); // 特殊:保证 gridApi 已经初始化
await gridApi.grid.reloadData(tableData.value);
},
{ immediate: true, deep: true },
);
/** 初始化行数据 */
const initRow = (item: any) => {
if (!item.row_id) {
item.row_id = Date.now() + Math.random();
}
};
/** 添加采购入库单 */
const purchaseInSelectRef = ref();
const handleOpenPurchaseIn = () => {
if (!props.supplierId) {
message.error('请选择供应商');
return;
}
purchaseInSelectRef.value?.open(props.supplierId);
};
const handleAddPurchaseIn = (rows: ErpPurchaseInApi.PurchaseIn[]) => {
rows.forEach((row) => {
const newItem: ErpFinancePaymentApi.FinancePaymentItem = {
row_id: Date.now() + Math.random(),
bizId: row.id,
bizType: ErpBizType.PURCHASE_IN,
bizNo: row.no,
totalPrice: row.totalPrice,
paidPrice: row.paymentPrice,
paymentPrice: row.totalPrice - row.paymentPrice,
remark: '',
};
tableData.value.push(newItem);
});
emitUpdate();
};
/** 添加采购退货单 */
const saleReturnSelectRef = ref();
const handleOpenSaleReturn = () => {
if (!props.supplierId) {
message.error('请选择供应商');
return;
}
saleReturnSelectRef.value?.open(props.supplierId);
};
const handleAddSaleReturn = (rows: ErpPurchaseReturnApi.PurchaseReturn[]) => {
rows.forEach((row) => {
const newItem: ErpFinancePaymentApi.FinancePaymentItem = {
row_id: Date.now() + Math.random(),
bizId: row.id,
bizType: ErpBizType.PURCHASE_RETURN,
bizNo: row.no,
totalPrice: -row.totalPrice,
paidPrice: -row.refundPrice,
paymentPrice: -row.totalPrice + row.refundPrice,
remark: '',
};
tableData.value.push(newItem);
});
emitUpdate();
};
/** 删除行 */
const handleDelete = async (row: any) => {
const index = tableData.value.findIndex((item) => item.row_id === row.row_id);
if (index !== -1) {
tableData.value.splice(index, 1);
emitUpdate();
}
};
/** 发送更新事件 */
const emitUpdate = () => {
emit('update:items', [...tableData.value]);
};
/** 单元格编辑完成事件 */
const handleEditClosed = async ({ row, column }: any) => {
if (column.property === 'paymentPrice') {
// 重新计算价格
emitUpdate();
}
};
/** 表格事件 */
const gridEvents = {
editClosed: handleEditClosed,
cellClick: ({ column }: any) => {
if (column.title === '操作') {}
},
};
/** 校验表单 */
const validate = async () => {
const errors: string[] = [];
// 检查是否有明细
if (tableData.value.length === 0) {
errors.push('请添加付款明细');
return errors;
}
// 检查每行的付款金额
for (let i = 0; i < tableData.value.length; i++) {
const item = tableData.value[i];
if (!item.paymentPrice || item.paymentPrice <= 0) {
errors.push(`${i + 1}行的本次付款必须大于0`);
}
}
if (errors.length > 0) {
throw new Error(errors.join(''));
}
};
defineExpose({ validate });
</script>
<template>
<Grid class="w-full">
<template #paymentPrice="{ row }">
<InputNumber
v-model:value="row.paymentPrice"
:precision="2"
:disabled="disabled"
:formatter="erpPriceInputFormatter"
placeholder="请输入本次付款"
@change="emitUpdate"
/>
</template>
<template #remark="{ row }">
<Input
v-model:value="row.remark"
:disabled="disabled"
placeholder="请输入备注"
@change="emitUpdate"
/>
</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.paidPrice) }}</span>
<span>本次付款:
{{ erpPriceInputFormatter(summaries.paymentPrice) }}</span>
</div>
</div>
</div>
<!-- 添加按钮放在底部 -->
<div v-if="!disabled" class="mt-4 flex justify-center space-x-2">
<a-button type="primary" @click="handleOpenPurchaseIn">
+ 添加采购入库单
</a-button>
<a-button type="primary" @click="handleOpenSaleReturn">
+ 添加采购退货单
</a-button>
</div>
</template>
</Grid>
<!-- 采购入库单选择组件 -->
<PurchaseInSelect ref="purchaseInSelectRef" @success="handleAddPurchaseIn" />
<!-- 采购退货单选择组件 -->
<SaleReturnSelect ref="saleReturnSelectRef" @success="handleAddSaleReturn" />
</template>

View File

@@ -0,0 +1,213 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
import { ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getPurchaseInPage } from '#/api/erp/purchase/in';
const emit = defineEmits<{
success: [rows: ErpPurchaseInApi.PurchaseIn[]];
}>();
const supplierId = ref<number>(); // 供应商ID
const open = ref<boolean>(false); // 弹窗是否打开
const selectedRows = ref<ErpPurchaseInApi.PurchaseIn[]>([]); // 选中的行
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: [
{
fieldName: 'no',
label: '入库单号',
component: 'Input',
componentProps: {
placeholder: '请输入入库单号',
allowClear: true,
},
},
{
fieldName: 'supplierId',
label: '供应商',
component: 'Input',
componentProps: {
disabled: true,
placeholder: '已自动选择供应商',
},
},
{
fieldName: 'paymentStatus',
label: '付款状态',
component: 'Select',
componentProps: {
options: [
{ label: '未付款', value: 0 },
{ label: '部分付款', value: 1 },
{ label: '全部付款', value: 2 },
],
placeholder: '请选择付款状态',
allowClear: true,
},
},
],
},
gridOptions: {
columns: [
{
type: 'checkbox',
width: 50,
fixed: 'left',
},
{
field: 'no',
title: '入库单号',
width: 200,
fixed: 'left',
},
{
field: 'supplierName',
title: '供应商',
minWidth: 120,
},
{
field: 'inTime',
title: '入库时间',
width: 160,
formatter: 'formatDate',
},
{
field: 'totalPrice',
title: '应付金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'paymentPrice',
title: '已付金额',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'unPaymentPrice',
title: '未付金额',
formatter: ({ row }) => {
const unPaymentPrice = row.totalPrice - row.paymentPrice;
return `${unPaymentPrice?.toFixed(2) || '0.00'}`;
},
minWidth: 120,
},
{
field: 'status',
title: '状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: 'ERP_AUDIT_STATUS' },
},
},
],
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getPurchaseInPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
supplierId: supplierId.value,
paymentEnable: true, // 只查询可付款的
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
checkboxConfig: {
highlight: true,
range: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<ErpPurchaseInApi.PurchaseIn>,
gridEvents: {
checkboxChange: ({
records,
}: {
records: ErpPurchaseInApi.PurchaseIn[];
}) => {
selectedRows.value = records;
},
checkboxAll: ({ records }: { records: ErpPurchaseInApi.PurchaseIn[] }) => {
selectedRows.value = records;
},
},
});
/** 打开弹窗 */
const openModal = (id: number) => {
supplierId.value = id;
open.value = true;
selectedRows.value = [];
// 重置表单并设置供应商ID
gridApi.formApi?.resetForm();
gridApi.formApi?.setValues({ supplierId: id });
// 延迟查询,确保表单值已设置
setTimeout(() => {
gridApi.query();
}, 100);
};
/** 确认选择 */
const handleOk = () => {
if (selectedRows.value.length === 0) {
message.warning('请选择要添加的采购入库单');
return;
}
// 过滤已全部付款的单据
const validRows = selectedRows.value.filter((row) => {
const unPaymentPrice = row.totalPrice - row.paymentPrice;
return unPaymentPrice > 0;
});
if (validRows.length === 0) {
message.warning('所选的入库单已全部付款,无需再付款');
return;
}
if (validRows.length < selectedRows.value.length) {
message.warning(
`已过滤${selectedRows.value.length - validRows.length}个已全部付款的入库单`,
);
}
emit('success', validRows);
open.value = false;
};
defineExpose({ open: openModal });
</script>
<template>
<Modal
class="!w-[70vw]"
v-model:open="open"
title="选择采购入库单"
@ok="handleOk"
:width="1000"
>
<Grid
class="max-h-[500px]"
table-title="采购入库单列表(仅展示可付款的单据)"
/>
</Modal>
</template>

View File

@@ -0,0 +1,217 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpPurchaseReturnApi } from '#/api/erp/purchase/return';
import { ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getPurchaseReturnPage } from '#/api/erp/purchase/return';
const emit = defineEmits<{
success: [rows: ErpPurchaseReturnApi.PurchaseReturn[]];
}>();
const supplierId = ref<number>(); // 供应商ID
const open = ref<boolean>(false); // 弹窗是否打开
const selectedRows = ref<ErpPurchaseReturnApi.PurchaseReturn[]>([]); // 选中的行
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: [
{
fieldName: 'no',
label: '退货单号',
component: 'Input',
componentProps: {
placeholder: '请输入退货单号',
allowClear: true,
},
},
{
fieldName: 'supplierId',
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,
},
},
],
},
gridOptions: {
columns: [
{
type: 'checkbox',
width: 50,
fixed: 'left',
},
{
field: 'no',
title: '退货单号',
width: 200,
fixed: 'left',
},
{
field: 'supplierName',
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 }) => {
const unRefundPrice = row.totalPrice - row.refundPrice;
return `${unRefundPrice?.toFixed(2) || '0.00'}`;
},
minWidth: 120,
},
{
field: 'status',
title: '状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: 'ERP_AUDIT_STATUS' },
},
},
],
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getPurchaseReturnPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
supplierId: supplierId.value,
refundEnable: true, // 只查询可退款的
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
checkboxConfig: {
highlight: true,
range: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<ErpPurchaseReturnApi.PurchaseReturn>,
gridEvents: {
checkboxChange: ({
records,
}: {
records: ErpPurchaseReturnApi.PurchaseReturn[];
}) => {
selectedRows.value = records;
},
checkboxAll: ({
records,
}: {
records: ErpPurchaseReturnApi.PurchaseReturn[];
}) => {
selectedRows.value = records;
},
},
});
/** 打开弹窗 */
const openModal = (id: number) => {
supplierId.value = id;
open.value = true;
selectedRows.value = [];
// 重置表单并设置供应商ID
gridApi.formApi?.resetForm();
gridApi.formApi?.setValues({ supplierId: id });
// 延迟查询,确保表单值已设置
setTimeout(() => {
gridApi.query();
}, 100);
};
/** 确认选择 */
const handleOk = () => {
if (selectedRows.value.length === 0) {
message.warning('请选择要添加的采购退货单');
return;
}
// 过滤已全部退款的单据
const validRows = selectedRows.value.filter((row) => {
const unRefundPrice = row.totalPrice - row.refundPrice;
return unRefundPrice > 0;
});
if (validRows.length === 0) {
message.warning('所选的退货单已全部退款,无需再付款');
return;
}
if (validRows.length < selectedRows.value.length) {
message.warning(
`已过滤${selectedRows.value.length - validRows.length}个已全部退款的退货单`,
);
}
emit('success', validRows);
open.value = false;
};
defineExpose({ open: openModal });
</script>
<template>
<Modal
class="!w-[70vw]"
v-model:open="open"
title="选择采购退货单"
@ok="handleOk"
:width="1000"
>
<Grid
class="max-h-[500px]"
table-title="采购退货单列表(仅展示需退款的单据)"
/>
</Modal>
</template>