Browse Source

小数位保留问题

laiguoran 3 years ago
parent
commit
d22af8df71
2 changed files with 9 additions and 1 deletions
  1. 8 1
      app/public/js/material_exponent.js
  2. 1 0
      app/view/material/exponent.ejs

+ 8 - 1
app/public/js/material_exponent.js

@@ -502,7 +502,14 @@ $(document).ready(() => {
         });
         // 自定义金额变更并提交
         $('#calc_zdy').on('blur', function () {
-            const newValue = parseFloat($(this).val());
+            let newValue = parseFloat($(this).val());
+            // 判断输入位数,并自动四舍五入
+            newValue = ZhCalc.round(newValue, decimal.tp);
+            $('#calc_zdy').val(newValue);
+            if (isNaN(newValue)) {
+                toastr.error('请输入正确的金额');
+                return false;
+            }
             const zdy = _.find(ex_calc, { code: 'zdy' });
             if (zdy.value === newValue) {
                 return;

+ 1 - 0
app/view/material/exponent.ejs

@@ -115,6 +115,7 @@
     const readOnly = <%- material.readOnly %>;
     const materialID = <%- material.id %>;
     const materialOrder = <%- material.order %>;
+    const decimal = JSON.parse('<%- JSON.stringify(ctx.tender.info.decimal) %>');
     let m_tp = <%= material.m_tp !== null ? material.m_tp : 0 %>;
     let ex_tp = <%= material.ex_tp !== null ? material.ex_tp : 0 %>;
     const pre_tp = <%= material.pre_tp !== null ? material.pre_tp : 0 %>;