Browse Source

fix: 党组织工作经费管理金额加法方式调整

zhangying 5 days ago
parent
commit
001e619bfd

+ 6 - 6
src/main/resources/static/app/main/partyTwoExt/fundsBudget/edit.html

@@ -34,15 +34,15 @@
                     <tr>
                         <th>活动经费(万元)<span style="color: red;">*</span></th>
                         <td ng-class="{ 'focused error' : this.editForm.activityfunds.$invalid &&  this.editForm.$submitted}">
-                            <input type="number" name="activityfunds" ng-model="dataModel.activityfunds" step="0.00000000001" ng-change="fundsChange()"
-                                   class="form-control" ng-required="true"/>
+                            <input type="number" name="activityfunds" ng-model="dataModel.activityfunds" ng-change="fundsChange()"
+                                   class="form-control" ng-required="true" />
                             <label ng-show="this.editForm.activityfunds.$invalid &&  this.editForm.$submitted"
                                    class="error">必填.</label>
                         </td>
                         <th>“双创”经费(万元)<span style="color: red;">*</span></th>
                         <td ng-class="{ 'focused error' : this.editForm.rewardfunds.$invalid &&  this.editForm.$submitted}">
-                            <input type="number" name="rewardfunds" ng-model="dataModel.rewardfunds" step="0.0000000001"
-                                   class="form-control" ng-required="true" ng-change="fundsChange()"/>
+                            <input type="number" name="rewardfunds" ng-model="dataModel.rewardfunds"
+                                   class="form-control" ng-required="true" ng-change="fundsChange()" />
                             <label ng-show="this.editForm.rewardfunds.$invalid &&  this.editForm.$submitted"
                                    class="error">必填.</label>
                         </td>
@@ -50,8 +50,8 @@
                     <tr>
                         <th>预算费用(万元)<span style="color: red;">*</span></th>
                         <td ng-class="{ 'focused error' : this.editForm.budgetfunds.$invalid &&  this.editForm.$submitted}">
-                            <input type="number" name="budgetfunds" ng-model="dataModel.budgetfunds" step="0.0000000001"
-                                   class="form-control" ng-required="true" readonly/>
+                            <input type="number" name="budgetfunds" ng-model="dataModel.budgetfunds"
+                                   class="form-control" ng-required="true" readonly />
                             <label ng-show="this.editForm.budgetfunds.$invalid &&  this.editForm.$submitted"
                                    class="error">必填.</label>
                         </td>

+ 17 - 1
src/main/resources/static/app/main/partyTwoExt/fundsBudget/edit.js

@@ -93,7 +93,7 @@
         $scope.getNdList();
 
         $scope.fundsChange = function () {
-            $scope.dataModel.budgetfunds = $scope.dataModel.activityfunds + $scope.dataModel.rewardfunds;
+            $scope.dataModel.budgetfunds = autoAddPrecision($scope.dataModel.activityfunds ,$scope.dataModel.rewardfunds);
         }
         $scope.pagechange = function () {
             var inTab = $bsRouterState.$getRouteType() == 'tab';
@@ -116,5 +116,21 @@
 
         };
 
+        // 动态检测小数位数,自动匹配输入值的精度
+        function getMaxDecimalPlaces(a, b) {
+            const decimalA = (a.toString().split('.')[1] || '').length;
+            const decimalB = (b.toString().split('.')[1] || '').length;
+            return Math.max(decimalA, decimalB);
+        }
+        function autoAddPrecision(a, b) {
+            const decimalPlaces = getMaxDecimalPlaces(a, b);
+            return addWithPrecision(a, b, decimalPlaces);
+        }
+        function addWithPrecision(a, b, decimalPlaces = 2) {
+            const factor = Math.pow(10, decimalPlaces);
+            const preciseSum = (Math.round(a * factor) + Math.round(b * factor)) / factor;
+            return preciseSum;
+        }
+
     });
 })(angular);