From dc8977cdbeb979df84d9b81a3be364223e8f2731 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 29 十月 2026 13:52:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_宁夏_万通新材料' into dev_宁夏_万通新材料
---
src/views/erp/finance/payment/modules/item-form.vue | 198 ++++++++++++++++++-------------------------------
1 files changed, 74 insertions(+), 124 deletions(-)
diff --git a/src/views/erp/finance/payment/modules/item-form.vue b/src/views/erp/finance/payment/modules/item-form.vue
index 3aadbe5..590c656 100644
--- a/src/views/erp/finance/payment/modules/item-form.vue
+++ b/src/views/erp/finance/payment/modules/item-form.vue
@@ -1,26 +1,30 @@
<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 { Input, InputNumber } from 'ant-design-vue';
-import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
+import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { useFormItemColumns } from '../data';
-import PurchaseInSelect from './purchase-in-select.vue';
-import SaleReturnSelect from './sale-return-select.vue';
+
+interface InvoiceForItem {
+ id?: number;
+ no?: string;
+ price?: number;
+ remainingInvoicePrice?: number;
+}
interface Props {
items?: ErpFinancePaymentApi.FinancePaymentItem[];
supplierId?: number;
disabled?: boolean;
discountPrice?: number;
+ invoice?: InvoiceForItem;
}
const props = withDefaults(defineProps<Props>(), {
@@ -28,6 +32,7 @@
supplierId: undefined,
disabled: false,
discountPrice: 0,
+ invoice: undefined,
});
const emit = defineEmits([
@@ -36,7 +41,21 @@
'update:paymentPrice',
]);
+/** 杈撳叆鏃朵笉琛ラ浂锛屽け鐒﹀悗浠嶆寜閲戦鏍煎紡淇濈暀涓や綅灏忔暟 */
+const paymentPriceFormatter = (
+ value: number | string | undefined,
+ info: { input: string; userTyping: boolean },
+) => {
+ return info.userTyping ? info.input : erpPriceInputFormatter(value);
+};
+
const tableData = ref<ErpFinancePaymentApi.FinancePaymentItem[]>([]); // 琛ㄦ牸鏁版嵁
+
+/** 鍥炴樉鐖剁粍浠朵紶鍏ョ殑鏄庣粏鏃惰烦杩囨�婚閲嶇畻锛岄伩鍏嶈鐩栫敤鎴锋墜鍔ㄤ慨鏀圭殑鍚堣浠樻 */
+const skipTotalCalc = ref(false);
+
+/** 宸叉牴鎹鏉ョエ鐢熸垚鐨勬槑缁嗭紝閬垮厤閲嶅鐢熸垚 */
+const generatedInvoiceId = ref<number | undefined>();
/** 鑾峰彇琛ㄦ牸鍚堣鏁版嵁 */
const summaries = computed(() => {
@@ -59,7 +78,7 @@
/** 琛ㄦ牸閰嶇疆 */
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
- columns: useFormItemColumns(props.disabled),
+ columns: useFormItemColumns(),
data: tableData.value,
minHeight: 250,
autoResize: true,
@@ -84,12 +103,48 @@
if (!items) {
return;
}
+ // 鐖剁粍浠跺洖鏄炬槑缁嗘椂鍙埛鏂拌〃鏍硷紝涓嶉噸绠楁�婚锛堝悎璁′粯娆惧厑璁告墜鍔ㄤ慨鏀癸級
+ skipTotalCalc.value = true;
tableData.value = [...items];
+ // 缂栬緫鍥炴樉鏃讹紝鏍囪宸叉牴鎹綋鍓嶆潵绁ㄧ敓鎴愯繃锛岄伩鍏嶉噸澶嶇敓鎴�
+ generatedInvoiceId.value = props.invoice?.id;
await nextTick(); // 鐗规畩锛氫繚璇� gridApi 宸茬粡鍒濆鍖�
await gridApi.grid.reloadData(tableData.value);
+ skipTotalCalc.value = false;
},
{
immediate: true,
+ },
+);
+
+/** 鍏宠仈鏉ョエ鍙樺寲鏃讹紝鑷姩鐢熸垚鍞竴鐨勪粯娆炬槑缁嗭紙浠樻鍩轰簬鏉ョエ锛� */
+watch(
+ () => props.invoice?.id,
+ async (newId) => {
+ if (!newId || !props.invoice) {
+ return;
+ }
+ if (generatedInvoiceId.value === newId) {
+ return;
+ }
+ generatedInvoiceId.value = newId;
+ const invoice = props.invoice;
+ const price = invoice.price ?? 0;
+ const remaining = invoice.remainingInvoicePrice ?? price;
+ tableData.value = [
+ {
+ bizId: invoice.id ?? 0,
+ bizType: ErpBizType.PURCHASE_INVOICE,
+ bizNo: invoice.no ?? '',
+ totalPrice: price,
+ paidPrice: price - remaining,
+ paymentPrice: remaining,
+ remark: '',
+ },
+ ];
+ await nextTick();
+ await gridApi.grid.reloadData(tableData.value);
+ emit('update:items', [...tableData.value]);
},
);
@@ -97,6 +152,9 @@
watch(
() => [tableData.value, props.discountPrice],
() => {
+ if (skipTotalCalc.value) {
+ return;
+ }
if (!tableData.value || tableData.value.length === 0) {
return;
}
@@ -116,74 +174,6 @@
{ deep: true },
);
-/** 娣诲姞閲囪喘鍏ュ簱鍗� */
-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 totalPrice = row.totalPrice ?? 0;
- const paidPrice = row.paymentPrice ?? 0;
- const newItem: ErpFinancePaymentApi.FinancePaymentItem = {
- bizId: row.id ?? 0,
- bizType: ErpBizType.PURCHASE_IN,
- bizNo: row.no ?? '',
- totalPrice,
- paidPrice,
- paymentPrice: totalPrice - paidPrice,
- remark: undefined,
- };
- tableData.value.push(newItem);
- });
- emit('update:items', [...tableData.value]);
-};
-
-/** 娣诲姞閲囪喘閫�璐у崟 */
-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 totalPrice = row.totalPrice ?? 0;
- const refundPrice = row.refundPrice ?? 0;
- const newItem: ErpFinancePaymentApi.FinancePaymentItem = {
- bizId: row.id ?? 0,
- bizType: ErpBizType.PURCHASE_RETURN,
- bizNo: row.no ?? '',
- totalPrice: -totalPrice,
- paidPrice: -refundPrice,
- paymentPrice: -totalPrice + 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(
@@ -199,11 +189,7 @@
/** 琛ㄥ崟鏍¢獙 */
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?.paymentPrice || item.paymentPrice <= 0) {
@@ -223,7 +209,7 @@
v-model:value="row.paymentPrice"
:precision="2"
:disabled="disabled"
- :formatter="erpPriceInputFormatter"
+ :formatter="paymentPriceFormatter"
placeholder="璇疯緭鍏ユ湰娆′粯娆�"
@change="handleRowChange(row)"
/>
@@ -236,21 +222,6 @@
@change="handleRowChange(row)"
/>
</template>
- <template #actions="{ row }">
- <TableAction
- :actions="[
- {
- label: '鍒犻櫎',
- type: 'link',
- danger: true,
- popConfirm: {
- title: '纭鍒犻櫎璇ヤ粯娆炬槑缁嗗悧锛�',
- confirm: handleDelete.bind(null, row),
- },
- },
- ]"
- />
- </template>
<template #bottom>
<div class="mt-2 rounded border border-border bg-muted p-2">
@@ -258,7 +229,7 @@
<span class="font-medium text-foreground">鍚堣锛�</span>
<div class="flex space-x-4">
<span>
- 鍚堣浠樻锛歿{ erpPriceInputFormatter(summaries.totalPrice) }}
+ 搴斾粯閲戦锛歿{ erpPriceInputFormatter(summaries.totalPrice) }}
</span>
<span>
宸蹭粯閲戦锛歿{ erpPriceInputFormatter(summaries.paidPrice) }}
@@ -270,34 +241,13 @@
</div>
</div>
</div>
- <TableAction
- v-if="!disabled"
- class="mt-2 flex justify-center"
- :actions="[
- {
- label: '娣诲姞閲囪喘鍏ュ簱鍗�',
- type: 'default',
- onClick: handleOpenPurchaseIn,
- },
- {
- label: '娣诲姞閲囪喘閫�璐у崟',
- type: 'default',
- onClick: handleOpenSaleReturn,
- },
- ]"
- />
+ <div
+ v-if="!invoice && !disabled"
+ class="mt-2 flex justify-center text-sm text-muted-foreground"
+ >
+ 閫夊~锛氶�夋嫨鍏宠仈鏉ョエ鍚庯紝绯荤粺灏嗚嚜鍔ㄧ敓鎴愪粯娆炬槑缁�
+ </div>
</template>
</Grid>
-
- <!-- 閲囪喘鍏ュ簱鍗曢�夋嫨缁勪欢 -->
- <PurchaseInSelect
- ref="purchaseInSelectRef"
- @success="handleAddPurchaseIn"
- />
- <!-- 閲囪喘閫�璐у崟閫夋嫨缁勪欢 -->
- <SaleReturnSelect
- ref="saleReturnSelectRef"
- @success="handleAddSaleReturn"
- />
</div>
</template>
--
Gitblit v1.9.3