Browse Source

计算精度,单价

MaiXinRong 6 years ago
parent
commit
075874878d
5 changed files with 15 additions and 9 deletions
  1. 1 0
      app/const/tender_info.js
  2. 1 1
      app/extend/helper.js
  3. 1 1
      app/public/js/ledger.js
  4. 12 6
      app/service/ledger.js
  5. 0 1
      app/service/pos.js

+ 1 - 0
app/const/tender_info.js

@@ -57,6 +57,7 @@ const defaultInfo = {
     },
     // 小数位数
     decimal: {
+        up: 2,
         qty: 3,
         tp: 2,
         pay: false,

+ 1 - 1
app/extend/helper.js

@@ -561,7 +561,7 @@ module.exports = {
      * @param {Number} precision - 精度
      * @constructor
      */
-    checkFieldPrecision(Obj, fields, precision) {
+    checkFieldPrecision(Obj, fields, precision = 2) {
         if (Obj) {
             for (const field of fields) {
                 if (Obj[field]) {

+ 1 - 1
app/public/js/ledger.js

@@ -681,7 +681,7 @@ $(document).ready(function() {
                     return;
                 } else {
                     data.updateType = 'update';
-                    data.updateData = {id: position.id};
+                    data.updateData = {id: posData.id};
                     data.updateData[col.field] = col.type === 'Number' ? parseFloat(newText) : newText;
                 }
                 postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {

+ 12 - 6
app/service/ledger.js

@@ -23,7 +23,9 @@ const keyFields = {
 // 以下字段仅可通过树结构操作改变,不可直接通过update方式从接口提交,发现时过滤
 const readOnlyFields = ['id', 'tender_id', 'ledger_id', 'ledger_pid', 'order', 'level', 'full_path', 'is_leaf'];
 const calcFields = ['quantity', 'unit_price', 'total_price', 'deal_qty', 'deal_tp'];
+const upFields = ['unit_price'];
 const qtyFields = ['quantity', 'deal_qty', 'dgn_qty1', 'dgn_qty2'];
+const tpFields = ['total_price', 'deal_tp'];
 const zeroRange = 0.0000000001;
 const rootId = -1;
 const keyPre = 'tender_node_maxId:';
@@ -1597,27 +1599,31 @@ module.exports = app => {
                     if (this._checkCalcField(row)) {
                         let calcData = JSON.parse(JSON.stringify(row));
                         const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, row.unit ? row.unit : updateNode.unit);
+                        // 数量保留小数位数
                         this.ctx.helper.checkFieldPrecision(calcData, qtyFields, precision.value);
+                        // 单位保留小数位数
+                        this.ctx.helper.checkFieldPrecision(calcData, upFields, this.ctx.tender.info.decimal.up);
+                        // 计算
                         if (row.quantity !== undefined) {
                             if (row.unit_price  !== undefined) {
-                                calcData.total_price = this.ctx.helper.times(row.quantity, row.unit_price);
+                                calcData.total_price = this.ctx.helper.times(calcData.quantity, calcData.unit_price);
                             } else {
-                                calcData.total_price = this.ctx.helper.times(row.quantity, updateNode.unit_price);
+                                calcData.total_price = this.ctx.helper.times(calcData.quantity, updateNode.unit_price);
                             }
                         } else if (row.unit_price !== undefined) {
-                            calcData.total_price = this.ctx.helper.times(updateNode.quantity, row.unit_price);
+                            calcData.total_price = this.ctx.helper.times(updateNode.quantity, calcData.unit_price);
                         }
                         if (row.total_price !== undefined) {
                             calcData.quantity = null;
                         }
                         if (row.deal_qty !== undefined) {
                             if (row.unit_price !== undefined) {
-                                calcData.deal_tp = this.ctx.helper.times(row.deal_qty, row.unit_price);
+                                calcData.deal_tp = this.ctx.helper.times(calcData.deal_qty, calcData.unit_price);
                             } else {
-                                calcData.deal_tp = this.ctx.helper.times(row.deal_qty, updateNode.unit_price);
+                                calcData.deal_tp = this.ctx.helper.times(calcData.deal_qty, updateNode.unit_price);
                             }
                         } else if (row.unit_price !== undefined) {
-                            calcData.deal_tp = this.ctx.helper.times(updateNode.deal_qty, row.unit_price);
+                            calcData.deal_tp = this.ctx.helper.times(updateNode.deal_qty, calcData.unit_price);
                         }
                         if (row.deal_tp !== undefined) {
                             calcData.deal_qty = null;

+ 0 - 1
app/service/pos.js

@@ -51,7 +51,6 @@ module.exports = app => {
          * @returns {Promise<{ledger: {}, pos: null}>}
          */
         async savePosData(data, tid) {
-            console.log(data);
             const transaction = await this.db.beginTransaction();
             try {
                 const result = { ledger: {}, pos: null };