Ver código fonte

修复已调用变更bug

laiguoran 2 anos atrás
pai
commit
e2a971aab2
1 arquivos alterados com 21 adições e 7 exclusões
  1. 21 7
      app/controller/change_controller.js

+ 21 - 7
app/controller/change_controller.js

@@ -774,14 +774,28 @@ 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) {
+                // 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']), 'sorder', function(item3) {
-                    return item3.sorder === 0;// 针对未审批完成期需要读取sorder为0的在前面
-                }), function(item1, item2) {
-                    return item1.cbid === item2.cbid;
-                });
-                renderData.changeUsedData = changeUsedData;
+                }), ['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);
+                        }
+                    }
+                }
+                renderData.changeUsedData = useChangeUsedData;
                 renderData.stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.qty); }));
                 await this.layout('change/information.ejs', renderData, 'change/information_modal.ejs');
             } catch (err) {