Browse Source

定额库右键菜单

MaiXinRong 7 years ago
parent
commit
24250a2d19

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

@@ -82,6 +82,20 @@ ProjectController = {
             this.syncDisplayNewNode(sheetController, newNode);
         }
     },
+    replaceRation: function (project, sheetController, std) {
+        if (!project || !sheetController) { return; }
+
+        let selected = project.mainTree.selected, newSource = null, newNode = null;
+        if (selected === null) { return; }
+
+        if (selected.sourceType === project.Ration.getSourceType()) {
+            project.Ration.replaceRation(selected.source, std);
+            project.ration_glj.addRationGLJ(selected.source, std);
+            sheetController.refreshTreeNode([selected], false);
+        } else {
+            alert('当前焦点行不是定额,无法替换。');
+        }
+    },
     addVolumePrice: function (project, sheetController) {
         if (!project || !sheetController) { return null; }
 

+ 39 - 0
web/building_saas/main/js/views/std_ration_lib.js

@@ -86,6 +86,44 @@ var rationLibObj = {
             });
         }
     },
+    loadStdRationContextMenu: function () {
+        let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet();
+        $.contextMenu({
+            selector: '#stdSectionRations',
+            build: function ($trigger, e) {
+                let target = SheetDataHelper.safeRightClickSelection($trigger, e, rationSpread);
+                return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
+            },
+            items: {
+                "insertStdRation": {
+                    name: "插入定额",
+                    icon: 'fa-sign-in',
+                    callback: function (key, opt) {
+                        let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
+                        let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
+                        if (rationCode !== '') {
+                            CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
+                                ProjectController.addRation(projectObj.project, projectObj.mainController, data);
+                            });
+                        }
+                    }
+                },
+                "replaceStdRation": {
+                    name: "替换定额",
+                    icon: 'fa-sign-in',
+                    callback: function (key, opt) {
+                        let select = $('#stdRationLibSelect'), rationSelect = rationSheet.getSelections();
+                        let rationCode = rationSelect.length > 0 ? rationSheet.getText(rationSelect[0].row, 0) : '';
+                        if (rationCode !== '') {
+                            CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
+                                ProjectController.replaceRation(projectObj.project, projectObj.mainController, data);
+                            });
+                        }
+                    }
+                },
+            }
+        });
+    },
     rationChapterTreeSetting: {
         "emptyRows":0,
         "headRows":1,
@@ -195,6 +233,7 @@ $('#stdRationTab').bind('click', function () {
     rationLibObj.checkSpread();
     if (select[0].options.length === 0) {
         rationLibObj.loadStdRationLibs();
+        rationLibObj.loadStdRationContextMenu();
     };
 });
 $('#stdRationLibSelect').change(function () {