|
|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <el-tabs type="border-card">
|
|
|
+ <!-- <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
|
|
|
@@ -76,8 +76,80 @@
|
|
|
</ele-pro-table>
|
|
|
</el-form>
|
|
|
</el-tab-pane>
|
|
|
- </el-tabs>
|
|
|
-
|
|
|
+ </el-tabs> -->
|
|
|
+ <el-form :ref="'form'" :model="tableForm">
|
|
|
+ <ele-pro-table
|
|
|
+ ref="table"
|
|
|
+ :needPage="false"
|
|
|
+ :columns="columns"
|
|
|
+ :datasource="tableForm.detailList"
|
|
|
+ row-key="id"
|
|
|
+ class="time-form"
|
|
|
+ >
|
|
|
+ <template v-slot:toolbar>
|
|
|
+ <span>本次开票合计:{{ totalAmountTotalPrice }}</span>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-slot:invoiceAmount="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="width: 100%;"
|
|
|
+ :prop="'detailList.' + 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) > scope.row.defaultAmountTotalPrice) {
|
|
|
+ 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, scope.$index)"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-slot:taxRate="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="width: 100%;"
|
|
|
+ :prop="'detailList.' + 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, 0, scope.$index)" style="width: 80%;"></el-input>%
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ </ele-pro-table>
|
|
|
+ </el-form>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
@@ -192,8 +264,8 @@
|
|
|
{
|
|
|
minWidth: 150,
|
|
|
prop: 'invoiceAmount',
|
|
|
- label: '开票金额',
|
|
|
- slot: 'invoiceAmount',
|
|
|
+ label: '本次开票金额',
|
|
|
+ // slot: 'invoiceAmount',
|
|
|
align: 'center'
|
|
|
},
|
|
|
{
|
|
|
@@ -207,12 +279,12 @@
|
|
|
prop: 'taxRate',
|
|
|
label: '税率',
|
|
|
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,
|
|
|
@@ -338,15 +410,48 @@
|
|
|
},
|
|
|
methods: {
|
|
|
convertToArrayFormat(data) {
|
|
|
- return Object.keys(data.productMap).map(key => {
|
|
|
- console.log('key', key);
|
|
|
- const paymentItem = data.receiptPayments?.filter(item => item?.relatedOrderNo == key)|| [];
|
|
|
- return {
|
|
|
- key: key,
|
|
|
- amountTotalPrice: paymentItem.length ? paymentItem.reduce((acc, cur) => acc + cur.invoiceAmount, 0) : 0,
|
|
|
- details: data.productMap[key] || []
|
|
|
- };
|
|
|
+ const result = [];
|
|
|
+ Object.keys(data.productMap).forEach(key => {
|
|
|
+ console.log('key!!!', key);
|
|
|
+ const paymentItem = data.receiptPayments?.filter(item => item?.relatedOrderNo == key) || [];
|
|
|
+ console.log('paymentItem', paymentItem);
|
|
|
+ const amountTotalPrice = paymentItem.length ? paymentItem.reduce((acc, cur) => acc + cur.invoiceAmount, 0) : 0;
|
|
|
+ const defaultAmountTotalPrice = paymentItem.length ? paymentItem.reduce((acc, cur) => acc + cur.unInvoiceAmount, 0) : 0;
|
|
|
+ const details = data.productMap[key] || [];
|
|
|
+
|
|
|
+ details.forEach(detail => {
|
|
|
+ result.push({
|
|
|
+ key: key,
|
|
|
+ amountTotalPrice: amountTotalPrice,
|
|
|
+ defaultAmountTotalPrice: defaultAmountTotalPrice,
|
|
|
+ ...detail,
|
|
|
+ invoiceAmount: '',
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
+
|
|
|
+ // 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;
|
|
|
},
|
|
|
// 校验发票金额
|
|
|
invoiceAmountChange(val, item, idx, index) {
|
|
|
@@ -425,9 +530,12 @@
|
|
|
this.setSelectData(row);
|
|
|
},
|
|
|
putValue(data) {
|
|
|
- console.log('tableInfoNew putValue', data);
|
|
|
- data.detailList = this.convertToArrayFormat(data);
|
|
|
- this.tableForm = data;
|
|
|
+ let tempData = JSON.parse(JSON.stringify(data));
|
|
|
+ console.log('tableInfoNew putValue', tempData);
|
|
|
+ tempData.detailList = this.convertToArrayFormat(tempData);
|
|
|
+ console.log('data.detailList', data.detailList);
|
|
|
+ this.tableForm = tempData;
|
|
|
+ console.log('tableInfoNew putValue~~~', this.tableForm);
|
|
|
},
|
|
|
setValue(data) {
|
|
|
data.detailList = this.convertToArrayFormat(data);
|