Chenshilong 7 years ago
parent
commit
15e0e94440

+ 8 - 14
web/building_saas/main/js/controllers/project_controller.js

@@ -59,20 +59,16 @@ ProjectController = {
             } else if (false) {
                 alert('当前清单已有公式计算,不能套用定额。');
             } else {
-                let firstChild = selected.firstChild();
-                if (firstChild && firstChild.sourceType === project.VolumePrice.getSourceType()) {
-                    alert('当前位置已有量价,不能套用定额。');
+                if (std) {
+                    newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
+                    project.ration_glj.addRationGLJ(newSource,std);
                 } else {
-                    if (std) {
-                        newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
-                        project.ration_glj.addRationGLJ(newSource,std);
-                    } else {
-                        newSource = project.Ration.insertRation(selected.source.getID());
-                    }
+                    newSource = project.Ration.insertRation(selected.source.getID());
                 }
+
                 newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
             }
-        } else if (selected.sourceType === project.Ration.getSourceType()) {
+        } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
             if (std) {
                 newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
                 project.ration_glj.addRationGLJ(newSource,std);
@@ -80,9 +76,7 @@ ProjectController = {
                 newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source);
             }
             newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
-        } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
-            alert('当前位置已有量价,不能套用定额。');
-        }
+        };
         if (newNode) {
             newNode.source = newSource;
             newNode.sourceType = project.Ration.getSourceType();
@@ -117,7 +111,7 @@ ProjectController = {
         if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
             newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
             newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
-        } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
+        } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
             newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
             newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
         }

+ 1 - 1
web/building_saas/main/js/models/ration.js

@@ -154,7 +154,7 @@ var Ration = {
         ration.prototype.getInsertRationData = function (billsID, preRation) {
             var br = this.getBillsSortRation(billsID);
             var updateData = [];
-            if (preRation) {
+            if (preRation && br.indexOf(preRation) > -1) {  // CSL, 2017-11-28  如果preIndex是-1,表明preRation 是量价。
                 var preIndex = br.indexOf(preRation), i;
                 updateData.push({updateType: 'ut_create', updateData: this.getTempRationData(this.maxRationID() + 1, billsID, preIndex < br.length - 1 ? br[preIndex + 1].serialNo : br[preIndex].serialNo + 1)});
                 for (i = preIndex + 1; i < br.length; i++) {

+ 2 - 2
web/building_saas/main/js/models/volume_price.js

@@ -75,7 +75,7 @@ var VolumePrice = {
             getInsertVolumePriceData (billsID, pre) {
                 let bv = this.getBillsSortVolumePrice(billsID);
                 let updateData = [];
-                if (pre) {
+                if (pre && bv.indexOf(pre) > -1) {
                     let preIndex = bv.indexOf(pre), i;
                     updateData.push({updateType: 'ut_create', updateData: this.getTempVolumePrice(this.maxID() + 1, billsID, preIndex < bv.length - 1 ? bv[preIndex + 1].serialNo : bv[preIndex].serialNo + 1)});
                     for (i = preIndex + 1; i < bv.length; i++) {
@@ -90,7 +90,7 @@ var VolumePrice = {
                 tools.owner.pushNow('insertVolumePrice', [this.getSourceType(), this.getProject().projCounter()], [this.getInsertVolumePriceData(billsID, pre), this.getCounterData()]);
 
                 let bv = this.getBillsSortVolumePrice(billsID), newVP = null;
-                if (pre) {
+                if (pre && bv.indexOf(pre) > -1) {
                     let preIndex = bv.indexOf(pre);
                     newVP = this.getTempVolumePrice(this.getNewID(), billsID, preIndex < bv.length - 1 ? bv[preIndex + 1].serialNo : bv[preIndex].serialNo + 1);
                     this.datas.push(newVP);

+ 14 - 28
web/building_saas/main/js/views/project_view.js

@@ -414,20 +414,13 @@ var projectObj = {
                     disabled: function () {
                         var selected = project.mainTree.selected;
                         if (selected) {
-                            if (selected.sourceType === project.Ration.getSourceType()) {
-                                return false;
-                            } else if (selected.sourceType === project.Bills.getSourceType()) {
-                                if (selected.source.children.length === 0) {
-                                    return selected.children.length !== 0 ? selected.firstChild().sourceType !== project.Ration.getSourceType() : false;
-                                } else {
-                                    return true;
-                                }
-                            } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
-                                return true;
-                            };
-                        } else {
-                            return true;
-                        }
+                            if (            // CSL, 2017-11-28
+                                selected.sourceType === project.Ration.getSourceType() ||
+                                selected.sourceType === project.VolumePrice.getSourceType() ||
+                                (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0)
+                               ) return false
+                            else return true
+                        } else return true
                     },
                     callback: function (key, opt) {
                         ProjectController.addRation(project, controller);
@@ -439,20 +432,13 @@ var projectObj = {
                     disabled: function () {
                         var selected = project.mainTree.selected;
                         if (selected) {
-                            if (selected.sourceType === project.Ration.getSourceType()) {
-                                return true;
-                            } else if (selected.sourceType === project.Bills.getSourceType()) {
-                                if (selected.source.children.length === 0) {
-                                    return selected.children.length !== 0 ? selected.firstChild().sourceType !== project.VolumePrice.getSourceType() : false;
-                                } else {
-                                    return true;
-                                }
-                            } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
-                                return false;
-                            };
-                        } else {
-                            return true;
-                        }
+                            if (            // CSL, 2017-11-28
+                            selected.sourceType === project.Ration.getSourceType() ||
+                            selected.sourceType === project.VolumePrice.getSourceType() ||
+                            (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0)
+                            ) return false
+                            else return true
+                        } else return true
                     },
                     callback: function (key, opt) {
                         ProjectController.addVolumePrice(project, controller);