feat:【antd】【erp 系统】finance/payment 的迁移 1/4(列表 ok)
This commit is contained in:
179
apps/web-antd/src/views/erp/finance/payment/modules/form.vue
Normal file
179
apps/web-antd/src/views/erp/finance/payment/modules/form.vue
Normal 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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user