Forráskód Böngészése

修复变更清单调用计算值bug

laiguoran 2 éve
szülő
commit
847a5f0979
1 módosított fájl, 11 hozzáadás és 14 törlés
  1. 11 14
      app/controller/change_controller.js

+ 11 - 14
app/controller/change_controller.js

@@ -774,24 +774,21 @@ module.exports = app => {
 
                 // 获取是否已存在调用变更令
                 let changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, change.cid);
-                // changeUsedData = ctx.helper._.uniqWith(ctx.helper._.sortBy(ctx.helper._.orderBy(ctx.helper._.filter(changeUsedData, function(item) {
-                //     return item.qty !== null;
-                // }), ['sorder'], ['desc']), 'sorder', function(item3) {
-                //     return item3.sorder === 0;// 针对未审批完成期需要读取sorder为0的在前面
-                // }), function(item1, item2) {
-                //     return item1.cbid === item2.cbid;
-                // });
                 changeUsedData = ctx.helper._.orderBy(ctx.helper._.filter(changeUsedData, function(item) {
                     return item.qty !== null;
                 }), ['sorder'], ['desc']);
                 const useChangeUsedData = [];
-                for (const cu of changeUsedData) {
-                    if (cu.sorder !== 0) {
-                        const index = ctx.helper._.findIndex(useChangeUsedData, { cbid: cu.cbid });
-                        if (index !== -1) {
-                            useChangeUsedData[index].qty = ctx.helper.add(useChangeUsedData[index].qty, cu.qty);
-                        } else {
-                            useChangeUsedData.push(cu);
+                if (changeUsedData.length > 0) { // 防止未创建期时调用
+                    const stage = await this.ctx.service.stage.getLastestStage(ctx.tender.id, true);
+                    for (const cu of changeUsedData) {
+                        if (cu.sorder !== 0 ||
+                            (cu.sorder === 0 && !(stage.status === audit.stage.status.uncheck || stage.status === audit.stage.status.checkNo))) {
+                            const index = ctx.helper._.findIndex(useChangeUsedData, { cbid: cu.cbid });
+                            if (index !== -1) {
+                                useChangeUsedData[index].qty = ctx.helper.add(useChangeUsedData[index].qty, cu.qty);
+                            } else {
+                                useChangeUsedData.push(cu);
+                            }
                         }
                     }
                 }