Эх сурвалжийг харах

Merge branch 'dev' into test

liujt 4 сар өмнө
parent
commit
8f68f6b83d

+ 74 - 11
src/BIZComponents/paymentCollectionPlan/Index.vue

@@ -354,7 +354,8 @@
         return this.form.datasource.reduce((acc, cur) => acc + Number(cur.ratio), 0).toFixed(2);
       },
       allPrice() {
-        return this.form.datasource.reduce((acc, cur) => acc + Number(cur.price), 0).toFixed(2);
+        // 使用分进行计算,避免浮点数精度问题
+        return (this.form.datasource.reduce((acc, cur) => acc + Math.round(Number(cur.price) * 100), 0) / 100).toFixed(2);
       },
     },
     watch: {
@@ -382,11 +383,9 @@
     methods: {
       setDiscountAmount(val) {
         console.log(val, '000000');
-        this.isLoadingFromApi = true;
         this.discountAmount = val;
-        setTimeout(() => {
-          this.isLoadingFromApi = false;
-        }, 100);
+        // 立即更新价格,无需设置isLoadingFromApi为true
+        this.refreshprice();
       },
       typeChange(val, index = null) {
         // console.log(val, index, '55555');
@@ -449,14 +448,66 @@
         });
       },
       refreshprice() {
-        // console.log(this.form, '666666');
-        let newData = this.form.datasource;
-        newData.forEach(async (r, index) => {
+        // 如果正在从API加载数据,则不执行刷新操作
+        if (this.isLoadingFromApi) {
+          return;
+        }
+        
+        // 创建一个新的数组,避免直接修改原数组
+        let newData = JSON.parse(JSON.stringify(this.form.datasource));
+        console.log('newData after copy:', newData);
+        
+        // 先根据比例计算所有价格
+        for (let i = 0; i < newData.length; i++) {
+          const r = newData[i];
           if (r.ratio) {
-            console.log(this.ratioInput(Number(r.ratio)), '9999888888');
-            r.price = await this.ratioInput(Number(r.ratio));
+            // 直接计算价格,避免使用async/await的forEach
+            let val = Number(r.ratio);
+            let newval = (val / 100).toFixed(2);
+            let price = (this.discountAmount * newval).toFixed(2);
+            newData[i] = {
+              ...r,
+              price: price
+            };
+            console.log('updated item', i, 'price:', price);
           }
-        });
+        }
+        
+        // 验证并调整最后一行价格,确保总和等于优惠后的总金额
+        // 使用分进行计算,避免浮点数精度问题
+        const allPriceSum = newData.reduce((acc, cur) => acc + Math.round(Number(cur.price || 0) * 100), 0) / 100;
+        const discountAmount = Number(this.discountAmount);
+        // 直接计算比例总和,避免字符串转换问题
+        const allRatio = newData.reduce((acc, cur) => acc + Number(cur.ratio || 0), 0);
+        
+        console.log('allPriceSum:', allPriceSum, 'discountAmount:', discountAmount, 'allRatio:', allRatio);
+        
+        // 检查是否所有数据都有price且比例合计为100%
+        const allHavePrice = newData.every(item => item.price != null && item.price !== '');
+        
+        console.log('allHavePrice:', allHavePrice);
+        
+        if (allHavePrice && Math.abs(allRatio - 100) < 0.01 && Math.abs(allPriceSum - discountAmount) >= 0.01) {
+          // 调整最后一行的价格
+          if (newData.length > 0) {
+            const lastIndex = newData.length - 1;
+            // 使用分进行计算,避免浮点数精度问题
+            const otherPriceSum = newData.slice(0, lastIndex).reduce((acc, cur) => acc + Math.round(Number(cur.price || 0) * 100), 0) / 100;
+            // 计算最后一行应该有的价格
+            const lastPrice = Math.round((discountAmount - otherPriceSum) * 100) / 100;
+            newData[lastIndex] = {
+              ...newData[lastIndex],
+              price: lastPrice.toFixed(2)
+            };
+            console.log('adjusted last item price:', lastPrice);
+          }
+        }
+        
+        console.log('newData before update:', newData);
+        
+        // 确保更新this.form.datasource,触发Vue的响应式更新
+        this.form.datasource = newData;
+        console.log('after update, datasource:', this.form.datasource);
       },
       // 返回列表数据
       getTableValue() {
@@ -608,12 +659,23 @@
         const basicRatio = 100 / tempPeriod;
         let totalRatio = 0;
         
+        // 保存原有数据
+        const existingData = [...this.form.datasource];
+        
         // 生成付款计划列表项
         const tempList = [];
         
         // 根据传入的period参数生成付款计划
         for (let i = 0; i < tempPeriod; i++) {
           let item = JSON.parse(JSON.stringify(this.defaultForm));
+          // let item;
+          // // 如果原有数据中有对应项,则保留原有数据
+          // if (i < existingData.length) {
+          //   item = JSON.parse(JSON.stringify(existingData[i]));
+          // } else {
+          //   item = JSON.parse(JSON.stringify(this.defaultForm));
+          // }
+          
           // 获取日期:如果i小于日期数组长度则使用对应日期,否则设为空
           const deadLine = i < dateRange.length ? dateRange[i] : '';
           const ratio = parseFloat(basicRatio.toFixed(2));
@@ -638,6 +700,7 @@
         this.form.datasource = tempList;
         // this.$set(this.form, 'datasource', tempList);
         console.log('付款计划列表:', this.form.datasource);
+        this.$forceUpdate();
       },
       // 添加
       handlAdd() {

+ 9 - 5
src/views/contractManage/contractBook/components/addDialog.vue

@@ -1962,15 +1962,19 @@
             return;
           }
 
-          let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+          // 使用分进行计算,避免浮点数精度问题
+          let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
           const payAmount = +commitData.payAmount;
           
           if(+ratioSum == 100) {
-            const difference = payAmount - receiptPaymentListSum;
-            if (Math.abs(difference) > 0.01 && commitData.receiptPaymentList.length > 0) {
+            // 使用分进行计算,避免浮点数精度问题
+            const difference = Math.round((payAmount - receiptPaymentListSum) * 100) / 100;
+            if (Math.abs(difference) >= 0.01 && commitData.receiptPaymentList.length > 0) {
               const lastIndex = commitData.receiptPaymentList.length - 1;
-              commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
-              receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+              // 使用分进行计算,避免浮点数精度问题
+              const newPrice = Math.round((+commitData.receiptPaymentList[lastIndex].price + difference) * 100) / 100;
+              commitData.receiptPaymentList[lastIndex].price = newPrice.toFixed(2);
+              receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
             }
           }
 

+ 8 - 8
src/views/purchasingManage/purchaseOrder/accountstatement/components/addAccountDialog.vue

@@ -149,10 +149,10 @@
       async getInfo(row) {
         let data = await accountstatementInfoAPI(row.id);
         // this.recorpayList = data.recorpayList || [];
-        data.orderTotalAmount = data.orderList.reduce((pre, cur) => pre + +cur.orderAmount, 0);
-        data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + +cur.amountTotalPrice, 0);
-        data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.statementAmount, 0);
-        data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.unStatementAmount, 0);
+        data.orderTotalAmount = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100;
+        data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.amountTotalPrice * 100), 0) / 100;
+        data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100;
+        data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
         this.datasource = data.orderList || [];
         this.dataForm = data;
         switch (this.dataForm.dateType) {
@@ -204,10 +204,10 @@
           // amountTotalPrice: data.amountTotalPrice,
           // amountPayablePass: data.amountPayablePass,
           // amountReceivablePass: data.amountReceivablePass
-          orderTotalAmount: data.reduce((pre, cur) => pre + +cur.orderAmount, 0),
-          amountTotalPrice: data.reduce((pre, cur) => pre + +cur.amountTotalPrice, 0),
-          amountCompletePrice: data.reduce((pre, cur) => pre + +cur.statementAmount, 0),
-          amountUnCompletePrice: data.reduce((pre, cur) => pre + +cur.unStatementAmount, 0)
+          orderTotalAmount: data.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100,
+          amountTotalPrice: data.reduce((pre, cur) => pre + Math.round(+cur.amountTotalPrice * 100), 0) / 100,
+          amountCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100,
+          amountUnCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100
         };
         // if (!this.datasource.length) this.$message.warning('暂无订单信息');
       },

+ 9 - 6
src/views/purchasingManage/purchaseOrder/accountstatement/components/searchTable.vue

@@ -3,14 +3,16 @@
   <seekPage :seekList="seekList" :formLength="3" @search="search"></seekPage>
 </template>
 <script>
-import { receiptType, reviewStatusSelect } from '@/enum/dict';
+import { receiptType, reviewStatusSelect, reconciliationType } from '@/enum/dict';
 import {
 
   assessmentIndicatorsOptions
 } from '@/views/targetManage/util.js';
 export default {
   data() {
-    return {};
+    return {
+
+    };
   },
   computed: {
     // 表格列配置
@@ -37,9 +39,10 @@ export default {
         {
           label: '对账方式:',
           value: 'dateType',
-          width: 380,
-          type: 'input',
-          placeholder: '请输入',
+          // width: 380,
+          placeholder: '请选择',
+          type: 'select',
+          planList: reconciliationType
         },
         // {
         //   label: '对账开始日期:',
@@ -83,7 +86,7 @@ export default {
         {
           label: '状态:',
           value: 'reviewStatus',
-          width: 380,
+          // width: 380,
           type: 'select',
           placeholder: '请选择状态',
           planList: reviewStatusSelect

+ 9 - 5
src/views/purchasingManage/purchaseOrder/components/addDialogNew.vue

@@ -2166,15 +2166,19 @@
             return;
           }
 
-          let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+          // 使用分进行计算,避免浮点数精度问题
+          let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
           const payAmount = +commitData.payAmount;
           
           if(+ratioSum == 100) {
-            const difference = payAmount - receiptPaymentListSum;
-            if (Math.abs(difference) > 0.01 && commitData.receiptPaymentList.length > 0) {
+            // 使用分进行计算,避免浮点数精度问题
+            const difference = Math.round((payAmount - receiptPaymentListSum) * 100) / 100;
+            if (Math.abs(difference) >= 0.01 && commitData.receiptPaymentList.length > 0) {
               const lastIndex = commitData.receiptPaymentList.length - 1;
-              commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
-              receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+              // 使用分进行计算,避免浮点数精度问题
+              const newPrice = Math.round((+commitData.receiptPaymentList[lastIndex].price + difference) * 100) / 100;
+              commitData.receiptPaymentList[lastIndex].price = newPrice.toFixed(2);
+              receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
             }
           }
 

+ 18 - 8
src/views/saleManage/saleOrder/accountstatement/components/addAccountDialog.vue

@@ -51,6 +51,7 @@
         :dataForm="dataForm"
         :datasource.sync="datasource"
         :dialogType="dialogType"
+        @changeDiscountPrice="changeDiscountPrice"
       ></inventoryTable>
     </div>
     <div slot="footer" class="footer">
@@ -158,6 +159,14 @@
     },
     computed: {},
     methods: {
+      changeDiscountPrice(price, tableIndex) {
+        console.log('price~~~', price, tableIndex)
+        this.datasource[tableIndex].amountTotalPrice = price;
+        this.datasource[tableIndex].unStatementAmount = price;
+        console.log('this.datasource', this.datasource)
+        this.dataForm.amountTotalPrice = this.datasource.reduce((pre, cur) => pre + Math.round(+cur.amountTotalPrice * 100), 0) / 100;
+        this.dataForm.amountUnCompletePrice = this.datasource.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
+      },
       open(dialogType, row, type = '') {
         this.dialogType = dialogType;
         this.title =
@@ -184,10 +193,11 @@
       async getInfo(row) {
         let data = await accountstatementInfoAPI(row.id);
         // this.recorpayList = data.recorpayList || [];
-        data.orderTotalAmount = data.orderList.reduce((pre, cur) => pre + +cur.orderAmount, 0);
-        data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + +cur.amountTotalPrice, 0);
-        data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.statementAmount, 0);
-        data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.unStatementAmount, 0);
+        // 解决小数精度丢失问题,使用分进行计算
+        data.orderTotalAmount = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100;
+        data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.amountTotalPrice * 100), 0) / 100;
+        data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100;
+        data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
         data.orderList = data.orderList.map(item => {
             item.deliveryProducts = item.deliveryProducts.map(i => {
               return {
@@ -270,10 +280,10 @@
             // amountTotalPrice: data.amountTotalPrice,
             // amountPayablePass: data.amountPayablePass,
             // amountReceivablePass: data.amountReceivablePass
-            orderTotalAmount: data.reduce((pre, cur) => pre + +cur.orderAmount, 0),
-            amountTotalPrice: data.reduce((pre, cur) => pre + +cur.amountTotalPrice, 0),
-            amountCompletePrice: data.reduce((pre, cur) => pre + +cur.statementAmount, 0),
-            amountUnCompletePrice: data.reduce((pre, cur) => pre + +cur.unStatementAmount, 0)
+            orderTotalAmount: data.reduce((pre, cur) => pre + Math.round(+cur.orderAmount * 100), 0) / 100,
+            amountTotalPrice: data.reduce((pre, cur) => pre + Math.round(+cur.amountTotalPrice * 100), 0) / 100,
+            amountCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100,
+            amountUnCompletePrice: data.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100
           };
           this.$forceUpdate();
         } catch (error) {

+ 4 - 4
src/views/saleManage/saleOrder/accountstatement/components/detailDialog.vue

@@ -28,7 +28,7 @@
         </div>
       </div>
     </el-card>
-    <div v-if="activeComp==='main'">
+    <div v-show="activeComp==='main'">
       <!--销售表单表单-->
       <sale-form :dataForm.sync="dataForm" :datasource.sync="datasource"
                  dialogType="view"></sale-form>
@@ -110,9 +110,9 @@ export default {
 
       this.datasource = data.orderList
       // this.recorpayList = data.recorpayList || [];
-      data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + +cur.amountTotalPrice, 0),
-      data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.statementAmount, 0),
-      data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.unStatementAmount, 0)
+        data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.amountTotalPrice * 100), 0) / 100;
+        data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.statementAmount * 100), 0) / 100;
+        data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + Math.round(+cur.unStatementAmount * 100), 0) / 100;
       this.dataForm = data
       switch (this.dataForm.dateType) {
         case 1:

+ 15 - 7
src/views/saleManage/saleOrder/accountstatement/components/inventoryTable.vue

@@ -116,8 +116,8 @@
                       <el-input
                         v-model="scope.row.singlePrice"
                         placeholder="请输入"
-                        @input="changeCount(scope.row, scope.$index)"
-                        :disabled="item.orderCategory != 4"
+                        @input="changeCount(scope.row, scope.$index, item, index)"
+                        :disabled="item.orderCategory != 4 || dialogType === 'view'"
                         type="number"
                       >
                         <template slot="append">元</template>
@@ -139,7 +139,7 @@
                         placeholder="请输入"
                         type="number"
                         @input="getNotaxSinglePrice(scope.row, scope.$index)"
-                        :disabled="item.orderCategory != 4"
+                        :disabled="item.orderCategory != 4 || dialogType === 'view'"
                       >
                         <template slot="append">%</template>
                       </el-input>
@@ -161,7 +161,7 @@
                         type="number"
                         :min="0"
                         :max="100"
-                        :disabled="item.orderCategory != 4"
+                        :disabled="item.orderCategory != 4 || dialogType === 'view'"
                         @input="getDiscountRatioPrice(scope.row, scope.$index)"
                       >
                         <template slot="append">%</template>
@@ -629,7 +629,7 @@ export default {
   },
   methods: {
     //改变数量
-      changeCount(item, index) {
+      changeCount(item, index, row, tableIndex) {
         console.log('changeCount~~~', item)
         console.log('this.datasource[index]~~~', this.datasource[index])
         // row.totalPrice = parseFloat((item.totalCount * item.singlePrice).toFixed(2))
@@ -645,7 +645,7 @@ export default {
           item.totalPrice = ''
         }
         this.getNotaxSinglePrice(item, index);
-        this.getDiscountRatioPrice(item, index);
+        this.getDiscountRatioPrice(item, index, row, tableIndex);
         this.$forceUpdate();
         // if (this.clientEnvironmentId == 4 && !isBlockCount) {
         //   this.tableHandleKeyUp(row, index, 'sum');
@@ -675,7 +675,7 @@ export default {
       },
 
       // 计算折让单价,折让总价
-      getDiscountRatioPrice(item, index) {
+      getDiscountRatioPrice(item, index, row, tableIndex) {
 
           if (item.singlePrice && item.discountRatio) {
             // this.$set(
@@ -706,6 +706,14 @@ export default {
             item.discountSinglePrice = ''
             item.discountTotalPrice = ''
           }
+          console.log('row~~~', row, tableIndex)
+          row.unStatementAmount = this.datasource[tableIndex].deliveryProducts.reduce((prev, curr) => {
+            return prev + Number(curr.discountTotalPrice || 0)
+          }, 0)
+          row.amountTotalPrice = this.datasource[tableIndex].deliveryProducts.reduce((prev, curr) => {
+            return prev + Number(curr.discountTotalPrice || 0)
+          }, 0)
+          this.$emit('changeDiscountPrice', row.amountTotalPrice, tableIndex)
       },
     remove(tableIndex, lineIndex, delType) {
       let params = {

+ 12 - 7
src/views/saleManage/saleOrder/components/addDialogNew.vue

@@ -1934,15 +1934,20 @@
               return;
             }
 
-            let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+            // 使用分进行计算,避免浮点数精度问题
+            let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
             const payAmount = +commitData.payAmount;
             
             if(+ratioSum == 100) {
-              const difference = payAmount - receiptPaymentListSum;
-              if (Math.abs(difference) > 0.01 && commitData.receiptPaymentList.length > 0) {
+              // 使用分进行计算,避免浮点数精度问题
+              const difference = Math.round((payAmount - receiptPaymentListSum) * 100) / 100;
+              console.log('difference~~~', difference);
+              if (Math.abs(difference) >= 0.01 && commitData.receiptPaymentList.length > 0) {
                 const lastIndex = commitData.receiptPaymentList.length - 1;
-                commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
-                receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+                // 使用分进行计算,避免浮点数精度问题
+                const newPrice = Math.round((+commitData.receiptPaymentList[lastIndex].price + difference) * 100) / 100;
+                commitData.receiptPaymentList[lastIndex].price = newPrice.toFixed(2);
+                receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + Math.round(+cur.price * 100), 0) / 100;
               }
             }
 
@@ -2091,9 +2096,9 @@
         }
         if(this.form.settlementMode == 2) {
         //   // this.transformMonth(val)
-          dateRange = this.transformMonthFun(val);
+          dateRange = this.transformMonthFun(val, this.form.receiptDate);
         }
-        // console.log('dateRange~~~', dateRange);
+        console.log('dateRange~~~', dateRange);
         this.$set(this.form, 'issueNumber', dateRange.length);
         // this.setDefaultList(dateRange)
         this.$refs.paymentCollectionPlanRef.defaultList(this.form.settlementMode, this.form.issueNumber, dateRange);

+ 10 - 4
src/views/saleManage/saleOrder/invoice/components/inventoryTable.vue

@@ -803,8 +803,7 @@
           //   slot: 'measuringUnit',
           //   align: 'center'
           // },
-          this.clientEnvironmentId == 4
-            ? {
+          this.clientEnvironmentId == 4 ? {
                 width: 150,
                 prop: 'blockCount',
                 label: '发货块数',
@@ -1282,8 +1281,15 @@
           let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
           modeHight = Number(modeHight);
           if (name === 'sum') {
-            row.blockCount = Math.floor(
-              row.totalCount / ((modelLong * modeWide * modeHight) / 1000000)
+            // row.blockCount = Math.floor(
+            //   row.totalCount / ((modelLong * modeWide * modeHight) / 1000000)
+            // );
+            this.$set(
+              this.form.datasource[index],
+              'blockCount',
+              Math.floor(
+                row.totalCount / ((modelLong * modeWide * modeHight) / 1000000)
+              )
             );
           } else if (name === 'blockCount') {
             row.totalCount =