|
@@ -1,82 +1,5 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div>
|
|
<div>
|
|
|
- <!-- <el-tabs type="border-card">
|
|
|
|
|
- <el-tab-pane :label="item.key" v-for="(item, idx) in tableForm.detailList" :key="idx">
|
|
|
|
|
- <el-form :ref="'form' + idx" :model="tableForm">
|
|
|
|
|
- <ele-pro-table
|
|
|
|
|
- ref="table"
|
|
|
|
|
- :needPage="false"
|
|
|
|
|
- :columns="columns"
|
|
|
|
|
- :datasource="item.details"
|
|
|
|
|
- row-key="id"
|
|
|
|
|
- class="time-form"
|
|
|
|
|
- >
|
|
|
|
|
- <template v-slot:toolbar>
|
|
|
|
|
- <span>本次开票合计:{{ item.amountTotalPrice }}</span>
|
|
|
|
|
- </template>
|
|
|
|
|
-
|
|
|
|
|
- <template v-slot:invoiceAmount="scope">
|
|
|
|
|
- <el-form-item
|
|
|
|
|
- style="width: 100%;"
|
|
|
|
|
- :prop="'detailList.' + idx + '.details.' + scope.$index + '.invoiceAmount'"
|
|
|
|
|
- :rules="[
|
|
|
|
|
- {
|
|
|
|
|
- required: true,
|
|
|
|
|
- message: '请输入开票金额',
|
|
|
|
|
- trigger: 'blur'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- validator: (rule, value, callback) => {
|
|
|
|
|
- if (value === undefined || value === null || value === '') {
|
|
|
|
|
- callback('请输入开票金额');
|
|
|
|
|
- } else if (parseFloat(value) < 0 || parseFloat(value) > item.amountTotalPrice) {
|
|
|
|
|
- callback('开票金额不能小于0且小于等于本次开票合计');
|
|
|
|
|
- } else {
|
|
|
|
|
- callback();
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- trigger: 'blur'
|
|
|
|
|
- }
|
|
|
|
|
- ]"
|
|
|
|
|
- >
|
|
|
|
|
- <span v-if="dialogType === 'view'">{{ scope.row.invoiceAmount }}</span>
|
|
|
|
|
- <el-input v-else v-model="scope.row.invoiceAmount" type="number" @input="(val) => invoiceAmountChange(val, scope.row, idx, scope.$index)"></el-input>
|
|
|
|
|
- </el-form-item>
|
|
|
|
|
- </template>
|
|
|
|
|
-
|
|
|
|
|
- <template v-slot:taxRate="scope">
|
|
|
|
|
- <el-form-item
|
|
|
|
|
- style="width: 100%;"
|
|
|
|
|
- :prop="'detailList.' + idx + '.details.' + scope.$index + '.taxRate'"
|
|
|
|
|
- :rules="[
|
|
|
|
|
- {
|
|
|
|
|
- required: true,
|
|
|
|
|
- message: '请输入税率',
|
|
|
|
|
- trigger: 'blur'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- validator: (rule, value, callback) => {
|
|
|
|
|
- if (value === undefined || value === null || value === '') {
|
|
|
|
|
- callback('请输入税率');
|
|
|
|
|
- } else if (parseFloat(value) < 0) {
|
|
|
|
|
- callback('税率不能小于0');
|
|
|
|
|
- } else {
|
|
|
|
|
- callback();
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- trigger: 'blur'
|
|
|
|
|
- }
|
|
|
|
|
- ]"
|
|
|
|
|
- >
|
|
|
|
|
- <span v-if="dialogType === 'view'">{{ scope.row.taxRate }}</span>
|
|
|
|
|
- <el-input v-else v-model="scope.row.taxRate" type="number" @input="getNotaxSinglePrice(scope.row, idx, scope.$index)" style="width: 80%;"></el-input>%
|
|
|
|
|
- </el-form-item>
|
|
|
|
|
- </template>
|
|
|
|
|
-
|
|
|
|
|
- </ele-pro-table>
|
|
|
|
|
- </el-form>
|
|
|
|
|
- </el-tab-pane>
|
|
|
|
|
- </el-tabs> -->
|
|
|
|
|
<el-form :ref="'form'" :model="tableForm">
|
|
<el-form :ref="'form'" :model="tableForm">
|
|
|
<ele-pro-table
|
|
<ele-pro-table
|
|
|
ref="table"
|
|
ref="table"
|
|
@@ -150,6 +73,7 @@
|
|
|
|
|
|
|
|
</ele-pro-table>
|
|
</ele-pro-table>
|
|
|
</el-form>
|
|
</el-form>
|
|
|
|
|
+
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
<script>
|
|
<script>
|
|
@@ -157,15 +81,6 @@
|
|
|
name: 'tableInfo',
|
|
name: 'tableInfo',
|
|
|
components: {},
|
|
components: {},
|
|
|
props: {
|
|
props: {
|
|
|
- form: {
|
|
|
|
|
- type: Object,
|
|
|
|
|
- default: () => {
|
|
|
|
|
- return {
|
|
|
|
|
- productMap: [],
|
|
|
|
|
- receiptPayments: []
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
dialogType: {
|
|
dialogType: {
|
|
|
type: String,
|
|
type: String,
|
|
|
default: ''
|
|
default: ''
|
|
@@ -195,7 +110,12 @@
|
|
|
align: 'center',
|
|
align: 'center',
|
|
|
fixed: 'left'
|
|
fixed: 'left'
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ width: 100,
|
|
|
|
|
+ prop: 'key',
|
|
|
|
|
+ label: '编码',
|
|
|
|
|
+ align: 'center'
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
width: 100,
|
|
width: 100,
|
|
|
prop: 'typeName',
|
|
prop: 'typeName',
|
|
@@ -265,7 +185,7 @@
|
|
|
minWidth: 150,
|
|
minWidth: 150,
|
|
|
prop: 'invoiceAmount',
|
|
prop: 'invoiceAmount',
|
|
|
label: '本次开票金额',
|
|
label: '本次开票金额',
|
|
|
- // slot: 'invoiceAmount',
|
|
|
|
|
|
|
+ slot: 'invoiceAmount',
|
|
|
align: 'center'
|
|
align: 'center'
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
@@ -274,17 +194,23 @@
|
|
|
label: '已开票金额',
|
|
label: '已开票金额',
|
|
|
align: 'center'
|
|
align: 'center'
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ minWidth: 150,
|
|
|
|
|
+ prop: 'unInvoiceAmount',
|
|
|
|
|
+ label: '未开票金额',
|
|
|
|
|
+ align: 'center'
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
minWidth: 150,
|
|
minWidth: 150,
|
|
|
prop: 'taxRate',
|
|
prop: 'taxRate',
|
|
|
label: '税率',
|
|
label: '税率',
|
|
|
align: 'center',
|
|
align: 'center',
|
|
|
- // slot: 'taxRate',
|
|
|
|
|
- formatter: (_row, _column, cellValue) => {
|
|
|
|
|
- return _row.taxRate
|
|
|
|
|
- ? _row.taxRate+'%'
|
|
|
|
|
- : '';
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ slot: 'taxRate',
|
|
|
|
|
+ // formatter: (_row, _column, cellValue) => {
|
|
|
|
|
+ // return _row.taxRate
|
|
|
|
|
+ // ? _row.taxRate+'%'
|
|
|
|
|
+ // : '';
|
|
|
|
|
+ // },
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
minWidth: 100,
|
|
minWidth: 100,
|
|
@@ -361,7 +287,19 @@
|
|
|
{
|
|
{
|
|
|
key: '',
|
|
key: '',
|
|
|
amountTotalPrice: 0,
|
|
amountTotalPrice: 0,
|
|
|
- details: []
|
|
|
|
|
|
|
+ details: [{
|
|
|
|
|
+ invoicedAmount: '',
|
|
|
|
|
+ invoiceAmount: '',
|
|
|
|
|
+ taxRate: '',
|
|
|
|
|
+ noTaxSinglePrice: '',
|
|
|
|
|
+ totalCount: '',
|
|
|
|
|
+ quoteWay: '',
|
|
|
|
|
+ singlePrice: '',
|
|
|
|
|
+ totalPrice: '',
|
|
|
|
|
+ discountRatio: 100,
|
|
|
|
|
+ discountSinglePrice: '',
|
|
|
|
|
+ discountAmount: '',
|
|
|
|
|
+ }]
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
productMap: [],
|
|
productMap: [],
|
|
@@ -387,29 +325,18 @@
|
|
|
],
|
|
],
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
|
|
+ computed: {
|
|
|
|
|
+ totalAmountTotalPrice() {
|
|
|
|
|
+ return this.tableForm.detailList.reduce((total, item) => {
|
|
|
|
|
+ return total + (parseFloat(item.invoiceAmount) || 0);
|
|
|
|
|
+ }, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
mounted() {
|
|
mounted() {
|
|
|
// this.tableForm = this.form;
|
|
// this.tableForm = this.form;
|
|
|
},
|
|
},
|
|
|
- watch: {
|
|
|
|
|
- form: {
|
|
|
|
|
- handler(val) {
|
|
|
|
|
- console.log('tableInfoNew form', val);
|
|
|
|
|
- const data = JSON.parse(JSON.stringify(val));
|
|
|
|
|
- data.detailList = data.productMap ? this.convertToArrayFormat(data) : [
|
|
|
|
|
- {
|
|
|
|
|
- key: '',
|
|
|
|
|
- amountTotalPrice: 0,
|
|
|
|
|
- details: []
|
|
|
|
|
- }
|
|
|
|
|
- ];
|
|
|
|
|
- console.log('tableInfoNew detailList', data.detailList);
|
|
|
|
|
- this.tableForm = data;
|
|
|
|
|
- },
|
|
|
|
|
- deep: true
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
methods: {
|
|
methods: {
|
|
|
- convertToArrayFormat(data) {
|
|
|
|
|
|
|
+ convertToArrayFormat(data, type) {
|
|
|
const result = [];
|
|
const result = [];
|
|
|
Object.keys(data.productMap).forEach(key => {
|
|
Object.keys(data.productMap).forEach(key => {
|
|
|
console.log('key!!!', key);
|
|
console.log('key!!!', key);
|
|
@@ -425,151 +352,170 @@
|
|
|
amountTotalPrice: amountTotalPrice,
|
|
amountTotalPrice: amountTotalPrice,
|
|
|
defaultAmountTotalPrice: defaultAmountTotalPrice,
|
|
defaultAmountTotalPrice: defaultAmountTotalPrice,
|
|
|
...detail,
|
|
...detail,
|
|
|
- invoiceAmount: '',
|
|
|
|
|
|
|
+ invoiceAmount: detail.invoiceAmount || 0,
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ if(type == 'setValue') {
|
|
|
|
|
+ // Allocate defaultAmountTotalPrice to invoiceAmount for each key group
|
|
|
|
|
+ const uniqueKeys = [...new Set(result.map(item => item.key))];
|
|
|
|
|
+ uniqueKeys.forEach(key => {
|
|
|
|
|
+ const sameKeyItems = result.filter(item => item.key === key);
|
|
|
|
|
+ if (sameKeyItems.length > 0) {
|
|
|
|
|
+ const defaultAmountTotalPrice = parseFloat(sameKeyItems[0].defaultAmountTotalPrice) || 0;
|
|
|
|
|
+ let remainingTotal = defaultAmountTotalPrice;
|
|
|
|
|
+
|
|
|
|
|
+ sameKeyItems.forEach(item => {
|
|
|
|
|
+ if (remainingTotal <= 0) {
|
|
|
|
|
+ item.invoiceAmount = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const unInvoiceAmount = parseFloat(item.unInvoiceAmount) || 0;
|
|
|
|
|
+ const allocateAmount = Math.min(remainingTotal, unInvoiceAmount);
|
|
|
|
|
+ item.invoiceAmount = allocateAmount.toFixed(2);
|
|
|
|
|
+ remainingTotal -= allocateAmount;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- // Allocate defaultAmountTotalPrice to invoiceAmount for each key group
|
|
|
|
|
- const uniqueKeys = [...new Set(result.map(item => item.key))];
|
|
|
|
|
- uniqueKeys.forEach(key => {
|
|
|
|
|
- const sameKeyItems = result.filter(item => item.key === key);
|
|
|
|
|
- if (sameKeyItems.length > 0) {
|
|
|
|
|
- const defaultAmountTotalPrice = parseFloat(sameKeyItems[0].defaultAmountTotalPrice) || 0;
|
|
|
|
|
- let remainingTotal = defaultAmountTotalPrice;
|
|
|
|
|
-
|
|
|
|
|
- sameKeyItems.forEach(item => {
|
|
|
|
|
- if (remainingTotal <= 0) {
|
|
|
|
|
- item.invoiceAmount = 0;
|
|
|
|
|
- } else {
|
|
|
|
|
- const unInvoiceAmount = parseFloat(item.unInvoiceAmount) || 0;
|
|
|
|
|
- const allocateAmount = Math.min(remainingTotal, unInvoiceAmount);
|
|
|
|
|
- item.invoiceAmount = allocateAmount.toFixed(2);
|
|
|
|
|
- remainingTotal -= allocateAmount;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
},
|
|
},
|
|
|
// 校验发票金额
|
|
// 校验发票金额
|
|
|
- invoiceAmountChange(val, item, idx, index) {
|
|
|
|
|
- if(index !=null) {
|
|
|
|
|
- let newData = this.tableForm.detailList[idx].details;
|
|
|
|
|
- let sum =0;
|
|
|
|
|
- newData.forEach((r) => {
|
|
|
|
|
- if (r.ratio) {
|
|
|
|
|
- sum += Number(r.ratio);
|
|
|
|
|
|
|
+ invoiceAmountChange(val, item, index) {
|
|
|
|
|
+ console.log('invoiceAmountChange', val, item, index);
|
|
|
|
|
+ console.log('this.tableForm.detailList', this.tableForm.detailList);
|
|
|
|
|
+ if (index != null) {
|
|
|
|
|
+ const key = item.key;
|
|
|
|
|
+ const sameKeyItems = this.tableForm.detailList.filter(d => d.key === key);
|
|
|
|
|
+ console.log('sameKeyItems', sameKeyItems);
|
|
|
|
|
+ let sum = 0;
|
|
|
|
|
+ sameKeyItems.forEach((r) => {
|
|
|
|
|
+ if (r.invoiceAmount) {
|
|
|
|
|
+ sum += Number(r.invoiceAmount);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- if(sum > this.tableForm.detailList[idx].amountTotalPrice) {
|
|
|
|
|
|
|
+ if (val && +val > +item.unInvoiceAmount) {
|
|
|
|
|
+ this.$message.error('物品开票金额不能大于未开票金额');
|
|
|
|
|
+ this.$set(item, 'invoiceAmount', '');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sum > item.defaultAmountTotalPrice) {
|
|
|
this.$message.error('物品开票金额不能大于本次开票合计');
|
|
this.$message.error('物品开票金额不能大于本次开票合计');
|
|
|
- this.$set(this.tableForm.detailList[idx].details[index], 'invoiceAmount', '');
|
|
|
|
|
|
|
+ this.$set(item, 'invoiceAmount', '');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ this.$set(item, 'invoiceAmount', val);
|
|
|
|
|
+ const amountTotalPrice = this.fromPrecision(sum);
|
|
|
|
|
+ const targetItems = this.tableForm.detailList.filter(d => d.key === key);
|
|
|
|
|
+ targetItems.forEach(targetItem => {
|
|
|
|
|
+ this.$set(targetItem, 'amountTotalPrice', amountTotalPrice);
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log('sum', sum, item.invoiceAmount);
|
|
|
|
|
+ this.$emit('invoiceAmountChange', item, sum);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
//计算不含税单价
|
|
//计算不含税单价
|
|
|
getNotaxSinglePrice(item, idx, index) {
|
|
getNotaxSinglePrice(item, idx, index) {
|
|
|
if (item.singlePrice && item.taxRate) {
|
|
if (item.singlePrice && item.taxRate) {
|
|
|
this.$set(
|
|
this.$set(
|
|
|
- this.tableForm.detailList[idx].details[index],
|
|
|
|
|
|
|
+ item,
|
|
|
'noTaxSinglePrice',
|
|
'noTaxSinglePrice',
|
|
|
parseFloat(
|
|
parseFloat(
|
|
|
(item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
|
|
(item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
} else {
|
|
} else {
|
|
|
- this.$set(this.tableForm.detailList[idx].details[index], 'noTaxSinglePrice', '');
|
|
|
|
|
|
|
+ this.$set(item, 'noTaxSinglePrice', '');
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- //获取选择的对账单数据
|
|
|
|
|
- async getAccountData(params) {
|
|
|
|
|
- if (params.children.orderType == 6) {
|
|
|
|
|
- this.tableForm.productMap = params.children.productMap;
|
|
|
|
|
- this.tableForm.productMap.forEach((item, index) => {
|
|
|
|
|
- item.sourceCode = params.children.orderNo;
|
|
|
|
|
- item.sourceId = params.children.id;
|
|
|
|
|
- item.sourceType = params.type == 1 ? 2 : 3;
|
|
|
|
|
- item.type = 12;
|
|
|
|
|
- item.singlePrice = item.discountSinglePrice;
|
|
|
|
|
- item.totalPrice = item.discountTotalPrice;
|
|
|
|
|
- item.typeName = '销售赔付';
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- this.tableForm.productMap = [];
|
|
|
|
|
- params.children.subList.forEach((item, index) => {
|
|
|
|
|
- item.productMap.forEach((i, n) => {
|
|
|
|
|
- i.sourceCode = item.statementSubOrderCode;
|
|
|
|
|
- i.sourceId = params.children.id;
|
|
|
|
|
- i.sourceType = params.type == 1 ? 2 : 3;
|
|
|
|
|
- i.type = item.subType;
|
|
|
|
|
- console.log(item.subType);
|
|
|
|
|
- i.typeName = this.typeList.find(
|
|
|
|
|
- (i) => i.value == item.subType
|
|
|
|
|
- ).label;
|
|
|
|
|
- // i.singlePrice = item.discountSinglePrice
|
|
|
|
|
- i.totalPrice = i.discountTotalPrice;
|
|
|
|
|
- });
|
|
|
|
|
- this.tableForm.productMap.push(...item.productMap);
|
|
|
|
|
- });
|
|
|
|
|
- this.$refs.table.reload();
|
|
|
|
|
- }
|
|
|
|
|
- this.$emit(
|
|
|
|
|
- 'setPrice',
|
|
|
|
|
- params.children.amountTotalPrice - this.invoiceAmount
|
|
|
|
|
- );
|
|
|
|
|
- let row = {
|
|
|
|
|
- id: params.id,
|
|
|
|
|
- name: params.statementNo,
|
|
|
|
|
- code: params.statementNo,
|
|
|
|
|
- linkType: params.type == 1 ? 190 : 290,
|
|
|
|
|
- linkTypeName: params.type == 1 ? '销售对账单' : '采购对账单'
|
|
|
|
|
- };
|
|
|
|
|
- this.setSelectData(row);
|
|
|
|
|
- },
|
|
|
|
|
putValue(data) {
|
|
putValue(data) {
|
|
|
let tempData = JSON.parse(JSON.stringify(data));
|
|
let tempData = JSON.parse(JSON.stringify(data));
|
|
|
console.log('tableInfoNew putValue', tempData);
|
|
console.log('tableInfoNew putValue', tempData);
|
|
|
- tempData.detailList = this.convertToArrayFormat(tempData);
|
|
|
|
|
|
|
+ tempData.detailList = this.convertToArrayFormat(tempData, 'putValue');
|
|
|
console.log('data.detailList', data.detailList);
|
|
console.log('data.detailList', data.detailList);
|
|
|
this.tableForm = tempData;
|
|
this.tableForm = tempData;
|
|
|
console.log('tableInfoNew putValue~~~', this.tableForm);
|
|
console.log('tableInfoNew putValue~~~', this.tableForm);
|
|
|
},
|
|
},
|
|
|
setValue(data) {
|
|
setValue(data) {
|
|
|
- data.detailList = this.convertToArrayFormat(data);
|
|
|
|
|
- for(let item of data.detailList) {
|
|
|
|
|
- const total = item.amountTotalPrice;
|
|
|
|
|
- const details = item.details;
|
|
|
|
|
- const count = details.length;
|
|
|
|
|
-
|
|
|
|
|
- if (count === 0) continue;
|
|
|
|
|
-
|
|
|
|
|
- // 计算基础金额(向下取整)
|
|
|
|
|
- const baseAmount = Math.floor(total / count);
|
|
|
|
|
- // 计算余数
|
|
|
|
|
- const remainder = total - (baseAmount * count);
|
|
|
|
|
-
|
|
|
|
|
- // 为所有项设置基础金额
|
|
|
|
|
- details.forEach((detail) => {
|
|
|
|
|
- detail.invoiceAmount = baseAmount;
|
|
|
|
|
|
|
+ let tempData = JSON.parse(JSON.stringify(data));
|
|
|
|
|
+ tempData.detailList = this.convertToArrayFormat(tempData, 'setValue');
|
|
|
|
|
+ console.log('tempData.detailList', tempData.detailList);
|
|
|
|
|
+ this.tableForm = tempData;
|
|
|
|
|
+ },
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 分配开票金额到明细项(根据未开票金额unInvoiceAmount限制)
|
|
|
|
|
+ * @param {Array|Object} data - 明细列表或单个明细对象
|
|
|
|
|
+ * @returns {Array|Object} 处理后的数据
|
|
|
|
|
+ */
|
|
|
|
|
+ allocateInvoiceAmount(data) {
|
|
|
|
|
+ if (Array.isArray(data)) {
|
|
|
|
|
+ data.forEach(item => {
|
|
|
|
|
+ if (item && typeof item === 'object') {
|
|
|
|
|
+ this.allocateSingleInvoiceAmount(item);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- // 将余数加到最后一项
|
|
|
|
|
- if (remainder > 0 && details.length > 0) {
|
|
|
|
|
- details[details.length - 1].invoiceAmount += remainder;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return data;
|
|
|
|
|
+ } else if (data && typeof data === 'object') {
|
|
|
|
|
+ this.allocateSingleInvoiceAmount(data);
|
|
|
|
|
+ return data;
|
|
|
}
|
|
}
|
|
|
- this.tableForm = data;
|
|
|
|
|
- console.log('tableInfoNew detailList~~~', data.detailList);
|
|
|
|
|
- // this.$refs.table.reload();
|
|
|
|
|
|
|
+ return data;
|
|
|
|
|
+ },
|
|
|
|
|
+ allocateSingleInvoiceAmount(item) {
|
|
|
|
|
+ console.log('allocateSingleInvoiceAmount~~~', item);
|
|
|
|
|
+ const key = item.key;
|
|
|
|
|
+ const defaultAmountTotalPrice = this.toPrecision(item.defaultAmountTotalPrice);
|
|
|
|
|
+ const sameKeyItems = this.tableForm.detailList.filter(d => d.key === key);
|
|
|
|
|
+
|
|
|
|
|
+ let remainingTotal = defaultAmountTotalPrice;
|
|
|
|
|
+
|
|
|
|
|
+ sameKeyItems.forEach((detail) => {
|
|
|
|
|
+ if (remainingTotal <= 0) {
|
|
|
|
|
+ detail.invoiceAmount = 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const unInvoiceAmount = this.toPrecision(detail.unInvoiceAmount);
|
|
|
|
|
+
|
|
|
|
|
+ if (remainingTotal > unInvoiceAmount) {
|
|
|
|
|
+ detail.invoiceAmount = this.fromPrecision(unInvoiceAmount);
|
|
|
|
|
+ remainingTotal = this.subPrecision(remainingTotal, unInvoiceAmount);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detail.invoiceAmount = this.fromPrecision(remainingTotal);
|
|
|
|
|
+ remainingTotal = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ toPrecision(value) {
|
|
|
|
|
+ const num = parseFloat(value) || 0;
|
|
|
|
|
+ return Math.round(num * 100);
|
|
|
|
|
+ },
|
|
|
|
|
+ fromPrecision(value) {
|
|
|
|
|
+ const num = parseFloat(value) || 0;
|
|
|
|
|
+ return (num / 100).toFixed(2);
|
|
|
},
|
|
},
|
|
|
- setPrice(row, data) {
|
|
|
|
|
|
|
+ subPrecision(a, b) {
|
|
|
|
|
+ return a - b;
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ setSinglePrice(row, data) {
|
|
|
let index = this.tableForm.detailList.findIndex(item => item.key == row.relatedOrderNo);
|
|
let index = this.tableForm.detailList.findIndex(item => item.key == row.relatedOrderNo);
|
|
|
|
|
+ // let detail = this.tableForm.detailList[index];
|
|
|
|
|
+ // console.log('tableInfoNew setPrice', row, data, index);
|
|
|
const paymentItem = data.filter(item => item?.relatedOrderNo == row.relatedOrderNo);
|
|
const paymentItem = data.filter(item => item?.relatedOrderNo == row.relatedOrderNo);
|
|
|
|
|
+ console.log('tableInfoNew~~~', this.tableForm.detailList[index]);
|
|
|
this.tableForm.detailList[index].amountTotalPrice = paymentItem.length ? paymentItem.reduce((acc, cur) => acc + +cur.invoiceAmount, 0) : 0;
|
|
this.tableForm.detailList[index].amountTotalPrice = paymentItem.length ? paymentItem.reduce((acc, cur) => acc + +cur.invoiceAmount, 0) : 0;
|
|
|
|
|
+ this.tableForm.detailList[index].defaultAmountTotalPrice = paymentItem.length ? paymentItem.reduce((acc, cur) => acc + +cur.invoiceAmount, 0) : 0;
|
|
|
|
|
+ // console.log('tableInfoNew tableForm', this.tableForm.detailList);
|
|
|
|
|
+ // 直接修改对象,不需要赋值
|
|
|
|
|
+ this.allocateInvoiceAmount(this.tableForm.detailList[index]);
|
|
|
|
|
|
|
|
|
|
+ this.tableForm = {...this.tableForm};
|
|
|
|
|
+ this.$forceUpdate();
|
|
|
},
|
|
},
|
|
|
clearTable() {
|
|
clearTable() {
|
|
|
this.tableForm = {
|
|
this.tableForm = {
|
|
@@ -587,68 +533,52 @@
|
|
|
},
|
|
},
|
|
|
getTableValidate() {
|
|
getTableValidate() {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
|
- // 2. 验证每个表格表单
|
|
|
|
|
- const validationPromises = [];
|
|
|
|
|
- this.tableForm.detailList.forEach((item, index) => {
|
|
|
|
|
- validationPromises.push(
|
|
|
|
|
- new Promise((formResolve, formReject) => {
|
|
|
|
|
- // 正确获取表单实例
|
|
|
|
|
- const formInstance = this.$refs['form' + index];
|
|
|
|
|
-
|
|
|
|
|
- if (formInstance) {
|
|
|
|
|
- // 确保formInstance有validate方法
|
|
|
|
|
- if (typeof formInstance.validate === 'function') {
|
|
|
|
|
- formInstance.validate((valid, errors) => {
|
|
|
|
|
- if (!valid && errors) {
|
|
|
|
|
- // 显示第一个错误信息
|
|
|
|
|
- const firstError = Object.values(errors)[0][0];
|
|
|
|
|
- if (firstError) {
|
|
|
|
|
- this.$message.warning(firstError.message);
|
|
|
|
|
- }
|
|
|
|
|
- formReject(false);
|
|
|
|
|
- } else {
|
|
|
|
|
- formResolve(true);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- // 如果没有validate方法,检查是否是数组(多个表单实例)
|
|
|
|
|
- if (Array.isArray(formInstance) && formInstance.length > 0) {
|
|
|
|
|
- const firstForm = formInstance[0];
|
|
|
|
|
- if (typeof firstForm.validate === 'function') {
|
|
|
|
|
- firstForm.validate((valid, errors) => {
|
|
|
|
|
- if (!valid && errors) {
|
|
|
|
|
- const firstError = Object.values(errors)[0][0];
|
|
|
|
|
- if (firstError) {
|
|
|
|
|
- this.$message.warning(firstError.message);
|
|
|
|
|
- }
|
|
|
|
|
- formReject(false);
|
|
|
|
|
- } else {
|
|
|
|
|
- formResolve(true);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- formResolve(true); // 没有validate方法时默认通过
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- formResolve(true); // 不是预期的表单实例时默认通过
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- formResolve(true); // 表单不存在时默认通过
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- console.log('validationPromises~~~',validationPromises);
|
|
|
|
|
|
|
+ // 2. 验证单个表格表单
|
|
|
|
|
+ const formInstance = this.$refs['form'];
|
|
|
|
|
|
|
|
- // 3. 处理验证结果
|
|
|
|
|
- try {
|
|
|
|
|
- await Promise.all(validationPromises);
|
|
|
|
|
|
|
+ if (formInstance && typeof formInstance.validate === 'function') {
|
|
|
|
|
+ formInstance.validate(async (valid, errors) => {
|
|
|
|
|
+ if (!valid && errors) {
|
|
|
|
|
+ // 显示第一个错误信息
|
|
|
|
|
+ const firstError = Object.values(errors)[0][0];
|
|
|
|
|
+ if (firstError) {
|
|
|
|
|
+ this.$message.warning(firstError.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ reject(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 3. 校验 amountTotalPrice 和 defaultAmountTotalPrice 是否相等
|
|
|
|
|
+ // for (let i = 0; i < this.tableForm.detailList.length; i++) {
|
|
|
|
|
+ // const item = this.tableForm.detailList[i];
|
|
|
|
|
+ // const amountTotalPrice = parseFloat(item.amountTotalPrice) || 0;
|
|
|
|
|
+ // const defaultAmountTotalPrice = parseFloat(item.defaultAmountTotalPrice) || 0;
|
|
|
|
|
+
|
|
|
|
|
+ // if (amountTotalPrice !== defaultAmountTotalPrice) {
|
|
|
|
|
+ // this.$message.warning(`第${i + 1}条本次开票合计(${amountTotalPrice})必须等于本次开票金额合计(${defaultAmountTotalPrice})`);
|
|
|
|
|
+ // reject(false);
|
|
|
|
|
+ // return;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ resolve(this.tableForm);
|
|
|
|
|
+ console.log('this.tableForm~~~',this.tableForm);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 4. 校验 amountTotalPrice 和 defaultAmountTotalPrice 是否相等
|
|
|
|
|
+ // for (let i = 0; i < this.tableForm.detailList.length; i++) {
|
|
|
|
|
+ // const item = this.tableForm.detailList[i];
|
|
|
|
|
+ // const amountTotalPrice = parseFloat(item.amountTotalPrice) || 0;
|
|
|
|
|
+ // const defaultAmountTotalPrice = parseFloat(item.defaultAmountTotalPrice) || 0;
|
|
|
|
|
+
|
|
|
|
|
+ // // if (amountTotalPrice !== defaultAmountTotalPrice) {
|
|
|
|
|
+ // // this.$message.warning(`第${i + 1}条本次开票合计(${amountTotalPrice})必须等于本次开票金额合计(${defaultAmountTotalPrice})`);
|
|
|
|
|
+ // // reject(false);
|
|
|
|
|
+ // // return;
|
|
|
|
|
+ // // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
resolve(this.tableForm);
|
|
resolve(this.tableForm);
|
|
|
console.log('this.tableForm~~~',this.tableForm);
|
|
console.log('this.tableForm~~~',this.tableForm);
|
|
|
- } catch (error) {
|
|
|
|
|
- reject(false);
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
@@ -673,9 +603,13 @@
|
|
|
this.$set(this.tableForm.link[0], 'linkTypeName', val.linkTypeName);
|
|
this.$set(this.tableForm.link[0], 'linkTypeName', val.linkTypeName);
|
|
|
},
|
|
},
|
|
|
getTableData() {
|
|
getTableData() {
|
|
|
- const data = JSON.parse(JSON.stringify(this.tableForm.detailList));
|
|
|
|
|
|
|
+ const data = JSON.parse(JSON.stringify(this.tableForm.detailList));
|
|
|
const transformedData = data.reduce((result, item) => {
|
|
const transformedData = data.reduce((result, item) => {
|
|
|
- result[item.key] = item.details;
|
|
|
|
|
|
|
+ if (!result[item.key]) {
|
|
|
|
|
+ result[item.key] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ const { key, amountTotalPrice, defaultAmountTotalPrice, ...detail } = item;
|
|
|
|
|
+ result[item.key].push(detail);
|
|
|
return result;
|
|
return result;
|
|
|
}, {});
|
|
}, {});
|
|
|
return transformedData;
|
|
return transformedData;
|