|
|
@@ -540,7 +540,10 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
salesCompanyBankAccount: '',
|
|
|
category: 1,
|
|
|
relatedList: [],
|
|
|
- productMap: {}
|
|
|
+ productMap: {},
|
|
|
+ // 冲红发票标记:1-是 / 0-否。init / splitInit / 详情接口返回后写回,保存时随 create/update 提交,
|
|
|
+ // 否则后端 validateRedReversalAmount 会按「非冲红」校验金额,把负数金额的冲红单拦成「非冲红发票金额不能小于0」
|
|
|
+ ifRedReversalInvoice: 0
|
|
|
};
|
|
|
export default {
|
|
|
mixins: [tabMixins],
|
|
|
@@ -786,6 +789,7 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
async init(row = {}, type, splitData = null) {
|
|
|
// 重置冲红标记,避免上次编辑状态污染本次
|
|
|
this.ifRedReversalInvoice = 0;
|
|
|
+ this.form.ifRedReversalInvoice = 0;
|
|
|
this.businessId = type == 'reissue' ? '' : row.id || '';
|
|
|
this.title =
|
|
|
type == 'add'
|
|
|
@@ -823,6 +827,9 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
Object.keys(data || {}).forEach((k) => {
|
|
|
this.$set(this.form, k, data[k]);
|
|
|
});
|
|
|
+ // 拆分初始化同样可能带冲红标记:同步到组件标记,保证提交体里有值
|
|
|
+ this.ifRedReversalInvoice = Number(this.form.ifRedReversalInvoice) || 0;
|
|
|
+ this.$set(this.form, 'ifRedReversalInvoice', this.ifRedReversalInvoice);
|
|
|
this.$nextTick(() => {
|
|
|
if (this.form.sourceType == 99) {
|
|
|
this.$refs.tableInfoNoOrderRef?.setValue(this.form);
|
|
|
@@ -1076,14 +1083,36 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
// }
|
|
|
|
|
|
this.form.sourceCode = tempNames.join(',');
|
|
|
-
|
|
|
- const res = await initInvoiceByStatementId(
|
|
|
- {
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 初始化发票数据可能被后端业务拦截(如:该已收/已付单据已开发票、存在在途发票申请、
|
|
|
+ * 来源是发票不允许开票等)。这里必须捕获:否则 Promise 拒绝会冒泡成未捕获异常弹窗,
|
|
|
+ * 用户只看到 "Error" 而看不到真正原因,且弹窗停留在半初始化状态。
|
|
|
+ */
|
|
|
+ let res;
|
|
|
+ try {
|
|
|
+ res = await initInvoiceByStatementId({
|
|
|
sourceIds: tempIds,
|
|
|
sourceType: this.form.sourceType,
|
|
|
type: this.form.type
|
|
|
- }
|
|
|
- )
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
+ const reason =
|
|
|
+ e?.message ||
|
|
|
+ e?.response?.data?.message ||
|
|
|
+ (typeof e === 'string' ? e : '') ||
|
|
|
+ '初始化发票数据失败,请稍后重试';
|
|
|
+ console.error('initInvoiceByStatementId failed:', e);
|
|
|
+ this.$message.error(reason);
|
|
|
+ // 关掉弹窗,避免用户在空表单上继续保存
|
|
|
+ this.cancel();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!res) {
|
|
|
+ this.$message.error('初始化发票数据失败:返回结果为空');
|
|
|
+ this.cancel();
|
|
|
+ return;
|
|
|
+ }
|
|
|
res.relatedList = [res.relatedVO];
|
|
|
res.relatedList = res.relatedList.map((item) => {
|
|
|
item.invoiceAmount = item.unInvoiceAmount;
|
|
|
@@ -1097,6 +1126,14 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
this.form.amount = amount;
|
|
|
this.form.expectInvoiceDate = res?.expectInvoiceDate;
|
|
|
this.form.invoiceNos = res?.invoiceNos;
|
|
|
+ /*
|
|
|
+ * 冲红发票标记:init 接口会按单据返回 1(冲红)/ 0(普通)。
|
|
|
+ * 必须写回组件标记(控制金额只读)与 form(随 create/update 提交),
|
|
|
+ * 否则后端 validateRedReversalAmount 拿到 null 会按「非冲红」校验,
|
|
|
+ * 把负数金额的冲红单拦成「非冲红发票金额不能小于0」。
|
|
|
+ */
|
|
|
+ this.ifRedReversalInvoice = Number(res?.ifRedReversalInvoice) || 0;
|
|
|
+ this.$set(this.form, 'ifRedReversalInvoice', this.ifRedReversalInvoice);
|
|
|
console.log('form~~~', this.form);
|
|
|
this.setCompanyBankAccount(res)
|
|
|
// this.form.detailList = res.detailList;
|
|
|
@@ -1192,9 +1229,11 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
//来源清单没有数据时给空数组,避免表格因空行报错
|
|
|
this.form.relatedList = this.form.relatedVO ? [this.form.relatedVO] : [];
|
|
|
this.form.type = Number(this.form.type);
|
|
|
- if(this.form.ifRedReversalInvoice){
|
|
|
- // 冲红发票标记:1 是 / 0 否。仅在 1 时禁止编辑金额相关字段
|
|
|
- this.ifRedReversalInvoice = Number(this.form.ifRedReversalInvoice);
|
|
|
+ // 冲红发票标记:1 是 / 0 否。0 也要覆盖(避免沿用列表行或上次的旧值);仅在 1 时禁止编辑金额
|
|
|
+ if (this.form.ifRedReversalInvoice !== undefined
|
|
|
+ && this.form.ifRedReversalInvoice !== null
|
|
|
+ && this.form.ifRedReversalInvoice !== '') {
|
|
|
+ this.ifRedReversalInvoice = Number(this.form.ifRedReversalInvoice) || 0;
|
|
|
}
|
|
|
this.$nextTick(() => {
|
|
|
// 根据来源类型设置数据源:99 用 tableInfo(setValue),非 99 用 tableInfoNew(putValue)
|
|
|
@@ -1409,6 +1448,11 @@ import tabMixins from '@/mixins/tableColumnsMixin';
|
|
|
? invoiceApplyCreateAPI
|
|
|
: invoiceApplyUpdateV2API;
|
|
|
this.form.relatedVO = this.form.relatedList[0];
|
|
|
+ /*
|
|
|
+ * 冲红标记以组件状态为准写回提交体:保证 create/update 一定携带 ifRedReversalInvoice(1/0),
|
|
|
+ * 不因某个入口未回填而传 null(后端会按「非冲红」校验金额,冲红单的负数金额将被拦截)。
|
|
|
+ */
|
|
|
+ this.$set(this.form, 'ifRedReversalInvoice', Number(this.ifRedReversalInvoice) || 0);
|
|
|
const id = await API(this.form);
|
|
|
if (this.form.sourceType == 2) {
|
|
|
const idArr = this.form.sourceId?.split(',') || [];
|