浏览代码

部位明细,计量问题

MaiXinRong 5 年之前
父节点
当前提交
ae962c1f44
共有 1 个文件被更改,包括 23 次插入16 次删除
  1. 23 16
      app/service/stage_pos.js

+ 23 - 16
app/service/stage_pos.js

@@ -226,6 +226,7 @@ module.exports = app => {
             const datas = data instanceof Array ? data : [data];
             const orgPos = await this.ctx.service.pos.getPosDataByIds(this._.map(datas, 'pid'));
             const orgStagePos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: this._.map(datas, 'pid')});
+            console.log(orgStagePos);
 
             const transaction = await this.db.beginTransaction();
             try {
@@ -255,28 +256,33 @@ module.exports = app => {
                     }
 
                     if (d.contract_qty !== undefined || d.qc_qty !== undefined || d.postil !== undefined) {
-                        const sp = {pid: d.pid, lid: d.lid, contract_qty: d.contract_qty, qc_qty: d.qc_qty, postil: d.postil};
                         const osp = this._.find(orgStagePos, function (p) { return p.pid === d.pid; });
-                        if (precision) {
-                            this.ctx.helper.checkFieldPrecision(sp, this.qtyFields, precision.value);
-                        }
                         if (osp && osp.times === this.ctx.stage.curTimes && osp.order === this.ctx.stage.curOrder) {
-                            if (d.contract_qty === undefined) {
-                                d.contract_qty = osp.contract_qty;
+                            const sp = {};
+                            if (d.contract_qty !== undefined) {
+                                sp.contract_qty = this.ctx.helper.round(d.contract_qty, precision.value);
                             }
-                            if (d.qc_qty === undefined) {
-                                d.qc_qty = osp.qc_qty;
+                            if (d.qc_qty !== undefined) {
+                                sp.qc_qty = this.ctx.helper.round(d.qc_qty, precision.value);
                             }
-                            if (d.postil === undefined) {
-                                d.postil = osp.postil;
+                            if (d.postil !== undefined) {
+                                sp.postil = this.ctx.helper.round(d.postil, precision.value);
                             }
-                            await transaction.update(this.tableName, d, {where: {id: osp.id}});
+                            await transaction.update(this.tableName, sp, {where: {id: osp.id}});
                         } else {
-                            sp.tid = this.ctx.tender.id;
-                            sp.sid = this.ctx.stage.id;
-                            sp.said = this.ctx.session.sessionUser.accountId;
-                            sp.times = this.ctx.stage.curTimes;
-                            sp.order = this.ctx.stage.curOrder;
+                            const sp = {
+                                pid: d.pid, lid: d.lid,
+                                tid: this.ctx.tender.id, sid: this.ctx.stage.id,
+                                said: this.ctx.session.sessionUser.accountId,
+                                times: this.ctx.stage.curTimes, order: this.ctx.stage.curOrder
+                            };
+                            sp.contract_qty = d.contract_qty === undefined && osp
+                                ? osp.contract_qty
+                                : this.ctx.helper.round(d.contract_qty, precision.value);
+                            sp.qc_qty = d.qc_qty === undefined && osp
+                                ? osp.qc_qty
+                                : this.ctx.helper.round(d.qc_qty, precision.value);
+                            sp.postil = d.postil === undefined && osp ? osp.postil : d.postil;
                             await transaction.insert(this.tableName, sp);
                         }
                     }
@@ -355,6 +361,7 @@ module.exports = app => {
             if ((data.updateType === 'add' || data.upateType === 'delete') && this.ctx.tender.measure_type === measureType.tz) {
                 throw '台账模式下,不可在计量中新增或删除部位明细,如需操作,请进行台账修订';
             }
+            console.log(data);
             let refreshData;
             if (data.updateType === 'add') {
                 refreshData = await this._addStagePosData(data.updateData);