调整收付款问题

This commit is contained in:
2026-09-01 11:52:22 +08:00
parent a9b4ab069b
commit f858eb2bcd
4 changed files with 97 additions and 50 deletions
@@ -1091,6 +1091,13 @@ export default {
}
}
},
validateAvailableInvoiceAmount() {
const availableAmountCents = Math.round(Number(this.availableInvoiceAmount || 0) * 100);
const invoiceAmountCents = Math.round(Number(this.invoiceAmount || 0) * 100);
if (invoiceAmountCents > availableAmountCents) {
throw new Error('本次开票金额不能超过可开票金额');
}
},
payload() {
return {
id: this.form.id,
@@ -1136,6 +1143,12 @@ export default {
return true;
},
async submitForm() {
try {
this.validateAvailableInvoiceAmount();
} catch (error) {
this.$message.warning(error.message);
return;
}
const saved = await this.saveDraft();
if (!saved) return;
await api.submit({ id: this.form.id });
+41 -31
View File
@@ -162,10 +162,10 @@
><el-form-item label="收款方"
><el-input v-model="form.payeeName" disabled /></el-form-item
></el-col>
<el-col :span="6"
><el-form-item label="收款账号" prop="receiptAccountId"
><span v-if="readonly">{{ form.bankAccount || '-' }}</span
><el-select
<el-col :span="6">
<el-form-item label="收款账号" prop="receiptAccountId">
<el-input v-if="readonly" v-model="form.bankAccount" disabled></el-input>
<el-select
v-else
v-model="form.receiptAccountId"
:disabled="!form.payeeName"
@@ -179,8 +179,11 @@
v-for="item in receiptAccountOptions"
:key="item.id"
:label="receiptAccountLabel(item)"
:value="item.id" /></el-select></el-form-item
></el-col>
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6"
><el-form-item label="开户银行"
><el-input v-model="form.bankName" disabled /></el-form-item
@@ -358,7 +361,9 @@
</div>
</section-card>
<div class="payment-form-page__actions">
<el-button @click="goBack">取消</el-button>
<el-button v-if="!readonly" type="primary" plain @click="syncPaymentRecords"
>同步</el-button
>
<el-button v-if="!readonly && canSave" type="primary" plain @click="saveDraft(false)"
>保存</el-button
>
@@ -368,6 +373,7 @@
@click="submitForm"
>提交</el-button
>
<el-button @click="goBack">返回</el-button>
</div>
</el-form>
<el-dialog
@@ -1180,27 +1186,38 @@ export default {
attachmentJson: invoice.attachmentJson || '',
}));
},
createMockPaymentRecords(settlementNo, amount = this.form.appliedAmount) {
const totalCents = Math.max(0, Math.round(Number(amount || 0) * 100));
const paidCents = [Math.round(totalCents * 0.2), Math.round(totalCents * 0.3)];
paidCents.push(totalCents - paidCents[0] - paidCents[1]);
const normalizedSettlementNo = String(settlementNo || 'SETTLEMENT').slice(0, 60);
this.paymentRecords = paidCents.map((value, index) => {
const paidDate = this.$dayjs().subtract(index, 'day').format('YYYY-MM-DD');
syncPaymentRecords() {
const appliedCents = Math.max(0, Math.round(Number(this.form.appliedAmount || 0) * 100));
if (!appliedCents) {
this.$message.warning('请先填写申请付款金额');
return;
}
const maxCount = Math.min(5, appliedCents);
const minCount = Math.min(2, maxCount);
const recordCount = Math.floor(Math.random() * (maxCount - minCount + 1)) + minCount;
const minimumTotal = recordCount;
const randomTotal = Math.round(appliedCents * (0.5 + Math.random() * 0.5));
let remainingCents = Math.max(minimumTotal, Math.min(appliedCents, randomTotal));
const timestamp = this.$dayjs().format('YYYYMMDDHHmmss');
this.paymentRecords = Array.from({ length: recordCount }, (_unusedItem, index) => {
const remainingCount = recordCount - index - 1;
const maxCurrentCents = remainingCents - remainingCount;
const paidCents =
remainingCount === 0 ? remainingCents : Math.floor(Math.random() * maxCurrentCents) + 1;
remainingCents -= paidCents;
const sequence = String(index + 1).padStart(2, '0');
const paidDate = this.$dayjs()
.subtract(Math.floor(Math.random() * 30), 'day')
.format('YYYY-MM-DD');
return {
paidAmount: Number((value / 100).toFixed(2)),
paidAmount: Number((paidCents / 100).toFixed(2)),
paidDate,
paymentNo: `MOCK-${normalizedSettlementNo}-${sequence}`,
paymentNo: `MOCK-PAY-${timestamp}-${sequence}`,
voucherJson: '',
kingdeeBillNo: `MOCK-KD${paidDate.replaceAll('-', '')}${sequence}`,
kingdeeBillNo: `MOCK-KD-${timestamp}-${sequence}`,
};
});
},
referencePaymentAmount(settlementAmount) {
return Number(
((Number(settlementAmount || 0) * Number(this.form.paymentRatio || 0)) / 100).toFixed(2)
);
this.$message.success(`同步成功,已生成${recordCount}条付款记录`);
},
applyTransferredPreSettlements(rows = []) {
if (!rows.length) return;
@@ -1246,7 +1263,7 @@ export default {
billType: '预结算单',
appliedAmount: Number(((settlementAmount * paymentRatio) / 100).toFixed(2)),
});
this.createMockPaymentRecords(this.form.preSettlementNo, this.form.appliedAmount);
this.paymentRecords = [];
this.$nextTick(() => {
this.amountSyncing = false;
this.$refs.formRef?.clearValidate();
@@ -1957,10 +1974,7 @@ export default {
detail?.invoices,
detail?.formalSettlementNo || row.formalSettlementNo
);
this.createMockPaymentRecords(
row.formalSettlementNo,
this.referencePaymentAmount(settlementAmount)
);
this.paymentRecords = [];
await Promise.all([
this.loadReceiptAccountOptions(),
this.loadAttachmentRuleData(detail?.id ? [detail] : []),
@@ -2019,10 +2033,6 @@ export default {
});
this.referenceVisible = false;
this.refreshReferenceValidation();
this.createMockPaymentRecords(
row.preSettlementNo,
this.referencePaymentAmount(settlementAmount)
);
const detail = this.unwrapData(detailResponse);
await Promise.all([
this.loadReceiptAccountOptions(),
@@ -1300,18 +1300,41 @@ export default {
};
this.appliedDetailQuery = { ...this.detailQuery };
},
async openAdjustDialog(row, readonly) {
if (!row.id || row.id === row.sourceDetailId) {
this.$message.warning('请先保存预结算单');
return;
async persistDetailForAdjustment(row) {
const sourceDetailId = row.sourceDetailId || row.id;
const isPersistedDetail =
row.id && sourceDetailId && String(row.id) !== String(sourceDetailId);
if (isPersistedDetail) return row;
await this.$refs.formRef?.validate();
this.loading = true;
try {
const { data } = await save(this.buildSavePayload());
this.form.id = data?.data || this.form.id;
await this.loadDetail();
const savedRow = this.details.find(
item => String(item.sourceDetailId || '') === String(sourceDetailId || '')
);
if (!savedRow) {
this.$message.warning('结算明细保存失败,请重试');
return null;
}
this.$emit('success', this.form.id);
return savedRow;
} finally {
this.loading = false;
}
},
async openAdjustDialog(row, readonly) {
const detailRow = await this.persistDetailForAdjustment(row);
if (!detailRow) return;
this.adjustDialog.visible = true;
this.adjustDialog.loading = true;
this.adjustDialog.readonly = readonly;
this.adjustDialog.detailId = row.id;
this.adjustDialog.detailId = detailRow.id;
this.adjustDialog.reason = '';
try {
const { data } = await getDetailFees(row.id);
const { data } = await getDetailFees(detailRow.id);
this.adjustRows = (data?.data || []).map(item => ({
...item,
feeItems: this.parseFeeItems(item.feeItemsJson),
@@ -1545,6 +1568,7 @@ export default {
&--page &__content {
max-height: none;
padding-bottom: 72px;
overflow: visible;
}