Browse Source

show/hide standard Bills/Ration Lib, refresh mainTree

MaiXinRong 8 years ago
parent
commit
92f2805d9b

+ 2 - 196
web/building_saas/main/html/main.html

@@ -519,6 +519,8 @@
     <!-- Test Data -->
     <script type="text/javascript" src="/test/tmp_data/bills_grid_setting.js"></script>
     <!-- view -->
+    <script type="text/javascript" src="/web/building_saas/main/js/views/project_info.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/views/project_view.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/main_ajax.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/main.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/controllers/project_controller.js"></script>
@@ -593,200 +595,4 @@
   	</SCRIPT>
     <script type="text/javascript" src="/web/building_saas/main/js/views/gljView.js"></script>
 </body>
-<script>
-
-    var project;
-    var controller;
-    var billsSpread;
-
-    $(document).ready(function () {
-        GC.Spread.Common.CultureManager.culture("zh-cn");
-
-        billsSpread = new GC.Spread.Sheets.Workbook($('#billsSpread')[0], { sheetCount: 1 });
-        billsSpread.options.tabStripVisible = false;
-        billsSpread.options.scrollbarMaxAlign = true;
-        billsSpread.options.allowUserDragDrop = false;
-        billsSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);
-
-        // For Test
-        /*datas.forEach(function (data) {
-            data.fees = [];
-            data.fees.push({fieldName: 'labour', unitFee: '1', totalFee: '2', tenderUnitFee: '3', tenderTotalFee: '4'});
-            data.flags = [];
-            data.flags.push({fieldName: 'isPartGather', flag: true});
-        });
-        drawing_data.forEach(function (data) {
-            data.fees = [];
-            data.fees.push({fieldName: 'machine', unitFee: '5', totalFee: '6', tenderUnitFee: '7', tenderTotalFee: '8'});
-            data.flags = [];
-            data.flags.push({fieldName: 'isPartGather', flag: false});
-        });*/
-
-        project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
-        project.loadDatas(function (err) {
-            if (!err) {
-                controller = TREE_SHEET_CONTROLLER.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
-
-                controller.showTreeData();
-                controller.bind('refreshBaseActn', function (tree) {
-                    var setButtonValid = function (valid, btn) {
-                        if (valid) {
-                            btn.removeClass('disabled');
-                        } else {
-                            btn.addClass('disabled');
-                        }
-                    };
-                    setButtonValid(tree.selected && tree.selected.canUpLevel(), $('#upLevel'));
-                    setButtonValid(tree.selected && tree.selected.canDownLevel(), $('#downLevel'));
-                    setButtonValid(tree.selected && tree.selected.canUpMove(), $('#upMove'));
-                    setButtonValid(tree.selected && tree.selected.canDownMove(), $('#downMove'));
-                    setButtonValid(tree.selected ? true : false, $('#delete'));
-                });
-
-                gljView.showDatas(project.GLJ.datas);
-//                alert('GLJDatas1:' + objTest(project.GLJ.datas[0]));
-//                project.FeeRate.getRate();
-            }
-            else {
-
-            }
-        });
-
-        $.contextMenu({
-            selector: '#billsSpread',
-            build: function ($trigger, e) {
-                var target = SheetDataHelper.safeRightClickSelection($trigger, e, billsSpread);
-                controller.setTreeSelected(controller.tree.items[target.row]);
-                return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
-            },
-            items: {
-                "insertBills": {
-                    name: "插入清单",
-                    icon: 'fa-sign-in',
-                    disabled: function () {
-                        return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
-                    },
-                    callback: function (key, opt) {
-                        ProjectController.addBills(project, controller);
-                    }
-                },
-                "insertRation": {
-                    name: "插入定额",
-                    icon: 'fa-sign-in',
-                    disabled: function () {
-                        var selected = project.mainTree.selected;
-                        if (selected) {
-                            if (selected.sourceType === project.Ration.getSourceType()) {
-                                return false;
-                            } else if (selected.sourceType === project.Bills.getSourceType()) {
-                                return selected.source.children.length !== 0;
-                            };
-                        } else {
-                            return true;
-                        }
-                    },
-                    callback: function (key, opt) {
-                        ProjectController.addRation(project, controller);
-                    }
-                },
-                "insertLJ": {
-                    name: "插入量价",
-                    icon: 'fa-sign-in',
-                    disabled: function () {
-                        var selected = project.mainTree.selected;
-                        if (selected) {
-                            if (selected.sourceType === project.Ration.getSourceType()) {
-                                return false;
-                            } else if (selected.sourceType === project.Bills.getSourceType()) {
-                                return selected.source.children.length !== 0;
-                            };
-                        } else {
-                            return true;
-                        }
-                    }
-                },
-                "spr1": '--------',
-                "delete": {
-                    name: '删除',
-                    icon: 'fa-remove',
-                    disabled: function () {
-                        var selected = project.mainTree.selected;
-                        return !selected;
-                    },
-                    callback: function () {
-                        var selected = controller.tree.selected;
-                        if (selected) {
-                            if (selected.sourceType === project.Bills.getSourceType()) {
-                                project.Bills.deleteBills(selected.source);
-                                controller.delete();
-                            };
-                        }
-
-                    }
-                }
-            }
-        });
-
-        $('#insert').click(function () {
-            var selected = controller.tree.selected;
-
-            if (!selected || selected.sourceType === project.Bills.getSourceType()) {
-                ProjectController.addBills(project, controller);
-            } else if (selected.sourceType === project.Ration.getSourceType()) {
-                ProjectController.addRation(project, controller);
-            }
-        });
-        $('#delete').click(function () {
-            var selected = controller.tree.selected;
-            if (selected) {
-                if (selected.sourceType === project.Bills.getSourceType()) {
-                    project.Bills.deleteBills(selected.source);
-                    controller.delete();
-                } else if (selected.sourceType === project.Ration.getSourceType()) {
-                    project.Ration.delete(selected.source);
-                    controller.delete();
-                };
-            }
-        });
-        $('#upLevel').click(function () {
-            console.log(project.Bills.tree.getInsertData(project.Bills.tree.selected.getParentID(), project.Bills.tree.selected.getNextSiblingID()));
-            var selected = controller.tree.selected;
-            if (selected && selected.sourceType === project.Bills.getSourceType()) {
-                selected.source.upLevel();
-                controller.upLevel();
-            }
-        });
-        $('#downLevel').click(function () {
-            var selected = controller.tree.selected;
-            if (selected && selected.sourceType === project.Bills.getSourceType()) {
-                selected.source.upLevel();
-                controller.downLevel();
-            }
-        });
-        $('#upMove').click(function () {
-            var selected = controller.tree.selected, pre, preSerialNo;
-            if (selected) {
-                if (selected.sourceType === project.Bills.getSourceType()) {
-                    selected.source.upLevel();
-                    controller.upMove();
-                } else if (selected.sourceType === project.Ration.getSourceType()) {
-                    project.Ration.changePos(selected.source, selected.preSibling.source);
-                    controller.upMove();
-                }
-            }
-        });
-        $('#downMove').click(function () {
-            var selected = controller.tree.selected, next, nextSerialNo;
-            if (selected) {
-                if (selected.sourceType === project.Bills.getSourceType()) {
-                    selected.source.downLevel();
-                    controller.downMove();
-                } else if (selected.sourceType === project.Ration.getSourceType()) {
-                    project.Ration.changePos(selected.source, selected.nextSibling.source);
-                    controller.downMove();
-                }
-            }
-        });
-    });
-</script>
 </html>

+ 3 - 14
web/building_saas/main/js/main.js

@@ -3,18 +3,7 @@
  */
 
 $(function () {
-    var getFullPathHtml = function (proj) {
-        var fullPath = [], i, pm = '<a href="/pm">项目管理</a>', angleRight = '<i class="fa fa-angle-right fa-fw"></i>';
-        fullPath.push(pm);
-        for (i = 0; i < proj.fullFolder.length; i++) {
-            fullPath.push(angleRight, proj.fullFolder[i]);
-        }
-        fullPath.push(angleRight, proj.name);
-        return fullPath.join('');
-    };
-    CommonAjax.post('/pm/api/getProject', {"user_id": userID, "proj_id": scUrlUtil.GetQueryString('project')}, function (data) {
-        if (data) {
-            $('#fullpath').html(getFullPathHtml(data));
-        }
-    });
+    projectInfoObj.showProjectInfo();
+    projectObj.checkMainSpread();
+    projectObj.loadProjectData();
 });

+ 27 - 0
web/building_saas/main/js/views/project_info.js

@@ -0,0 +1,27 @@
+/**
+ * Created by Mai on 2017/6/21.
+ */
+
+var projectInfoObj = {
+    projectInfo: null,
+    getFullPathHtml: function (proj) {
+        var fullPath = [], i, pm = '<a href="/pm">项目管理</a>', angleRight = '<i class="fa fa-angle-right fa-fw"></i>';
+        if (proj && proj.fullFolder) {
+            for (i = 0; i < proj.fullFolder.length; i++) {
+                fullPath.push(angleRight, proj.fullFolder[i]);
+            }
+            fullPath.push(angleRight, proj.name);
+        }
+        fullPath.push(pm);
+        return fullPath.join('');
+    },
+    showProjectInfo: function (proj) {
+        var that = this;
+        CommonAjax.post('/pm/api/getProject', {"user_id": userID, "proj_id": scUrlUtil.GetQueryString('project')}, function (data) {
+            if (data) {
+                that.projectInfo = data;
+                $('#fullpath').html(that.getFullPathHtml(that.projectInfo));
+            }
+        });
+    }
+};

+ 198 - 0
web/building_saas/main/js/views/project_view.js

@@ -0,0 +1,198 @@
+/**
+ * Created by Mai on 2017/6/21.
+ */
+
+var projectObj = {
+    project: null,
+    mainSpread: null,
+    mainController: null,
+    checkMainSpread: function () {
+        if (!this.mainSpread) {
+            this.mainSpread = SheetDataHelper.createNewSpread($('#billsSpread')[0]);
+            this.mainSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);
+        }
+    },
+    refreshMainSpread: function () {
+        if (this.mainSpread) {
+            this.mainSpread.refresh();
+        }
+    },
+    loadProjectData: function () {
+        var that = this;
+        this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
+        this.project.loadDatas(function (err) {
+            if (!err) {
+                that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), BillsGridSetting);
+
+                that.mainController.showTreeData();
+                that.mainController.bind('refreshBaseActn', function (tree) {
+                    var setButtonValid = function (valid, btn) {
+                        if (valid) {
+                            btn.removeClass('disabled');
+                        } else {
+                            btn.addClass('disabled');
+                        }
+                    };
+                    setButtonValid(tree.selected && tree.selected.canUpLevel(), $('#upLevel'));
+                    setButtonValid(tree.selected && tree.selected.canDownLevel(), $('#downLevel'));
+                    setButtonValid(tree.selected && tree.selected.canUpMove(), $('#upMove'));
+                    setButtonValid(tree.selected && tree.selected.canDownMove(), $('#downMove'));
+                    setButtonValid(tree.selected ? true : false, $('#delete'));
+                });
+
+                that.loadMainSpreadContextMenu();
+            }
+            else {
+
+            }
+        });
+    },
+    loadMainSpreadContextMenu: function () {
+        var project = this.project, spread = this.mainSpread, controller = this.mainController;
+        $.contextMenu({
+            selector: '#billsSpread',
+            build: function ($trigger, e) {
+                var target = SheetDataHelper.safeRightClickSelection($trigger, e, spread);
+                controller.setTreeSelected(controller.tree.items[target.row]);
+                return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
+            },
+            items: {
+                "insertBills": {
+                    name: "插入清单",
+                    icon: 'fa-sign-in',
+                    disabled: function () {
+                        return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
+                    },
+                    callback: function (key, opt) {
+                        ProjectController.addBills(project, controller);
+                    }
+                },
+                "insertRation": {
+                    name: "插入定额",
+                    icon: 'fa-sign-in',
+                    disabled: function () {
+                        var selected = project.mainTree.selected;
+                        if (selected) {
+                            if (selected.sourceType === project.Ration.getSourceType()) {
+                                return false;
+                            } else if (selected.sourceType === project.Bills.getSourceType()) {
+                                return selected.source.children.length !== 0;
+                            };
+                        } else {
+                            return true;
+                        }
+                    },
+                    callback: function (key, opt) {
+                        ProjectController.addRation(project, controller);
+                    }
+                },
+                "insertLJ": {
+                    name: "插入量价",
+                    icon: 'fa-sign-in',
+                    disabled: function () {
+                        var selected = project.mainTree.selected;
+                        if (selected) {
+                            if (selected.sourceType === project.Ration.getSourceType()) {
+                                return false;
+                            } else if (selected.sourceType === project.Bills.getSourceType()) {
+                                return selected.source.children.length !== 0;
+                            };
+                        } else {
+                            return true;
+                        }
+                    }
+                },
+                "spr1": '--------',
+                "delete": {
+                    name: '删除',
+                    icon: 'fa-remove',
+                    disabled: function () {
+                        var selected = project.mainTree.selected;
+                        return !selected;
+                    },
+                    callback: function () {
+                        var selected = controller.tree.selected;
+                        if (selected) {
+                            if (selected.sourceType === project.Bills.getSourceType()) {
+                                project.Bills.deleteBills(selected.source);
+                                controller.delete();
+                            };
+                        }
+
+                    }
+                }
+            }
+        });
+    }
+};
+
+$('#insert').click(function () {
+    var controller = projectObj.mainController, project = projectObj.project;
+    var selected = controller.tree.selected;
+
+    if (!selected || selected.sourceType === project.Bills.getSourceType()) {
+        ProjectController.addBills(project, controller);
+    } else if (selected.sourceType === project.Ration.getSourceType()) {
+        ProjectController.addRation(project, controller);
+    }
+});
+$('#delete').click(function () {
+    var controller = projectObj.mainController, project = projectObj.project;
+    var selected = controller.tree.selected;
+
+    if (selected) {
+        if (selected.sourceType === project.Bills.getSourceType()) {
+            project.Bills.deleteBills(selected.source);
+            controller.delete();
+        } else if (selected.sourceType === project.Ration.getSourceType()) {
+            project.Ration.delete(selected.source);
+            controller.delete();
+        };
+    }
+});
+$('#upLevel').click(function () {
+    var controller = projectObj.mainController, project = projectObj.project;
+    var selected = controller.tree.selected;
+
+    if (selected && selected.sourceType === project.Bills.getSourceType()) {
+        selected.source.upLevel();
+        controller.upLevel();
+    }
+});
+$('#downLevel').click(function () {
+    var controller = projectObj.mainController, project = projectObj.project;
+    var selected = controller.tree.selected;
+    if (selected && selected.sourceType === project.Bills.getSourceType()) {
+        selected.source.upLevel();
+        controller.downLevel();
+    }
+});
+$('#upMove').click(function () {
+    var controller = projectObj.mainController, project = projectObj.project;
+    var selected = controller.tree.selected, pre, preSerialNo;
+
+    if (selected) {
+        if (selected.sourceType === project.Bills.getSourceType()) {
+            selected.source.upLevel();
+            controller.upMove();
+        } else if (selected.sourceType === project.Ration.getSourceType()) {
+            project.Ration.changePos(selected.source, selected.preSibling.source);
+            controller.upMove();
+        }
+    }
+});
+$('#downMove').click(function () {
+    var controller = projectObj.mainController, project = projectObj.project;
+    var selected = controller.tree.selected, next, nextSerialNo;
+
+    if (selected) {
+        if (selected.sourceType === project.Bills.getSourceType()) {
+            selected.source.downLevel();
+            controller.downMove();
+        } else if (selected.sourceType === project.Ration.getSourceType()) {
+            project.Ration.changePos(selected.source, selected.nextSibling.source);
+            controller.downMove();
+        }
+    }
+});
+

+ 1 - 0
web/building_saas/main/js/views/side_tools.js

@@ -32,4 +32,5 @@ $('.side-tabs ul li a').bind('click', function () {
         sideToolsObj.showSideTools(tab.hasClass('active'));
         tabPanel.hide();
     }
+    projectObj.refreshMainSpread();
 });

+ 23 - 0
web/building_saas/main/js/views/std_bills_lib.js

@@ -12,6 +12,11 @@ var billsLibObj = {
             this.stdBillsSpread = SheetDataHelper.createNewSpread($('#stdBillsSpread')[0]);
         }
     },
+    refreshBillsSpread: function () {
+        if (this.stdBillsSpread) {
+            this.stdBillsSpread.refresh();
+        }
+    },
     checkBillsRelaSpread: function () {
         if (!this.stdBillsJobSpread) {
             this.stdBillsJobSpread = SheetDataHelper.createNewSpread($('#stdBillsJobs')[0]);
@@ -20,6 +25,14 @@ var billsLibObj = {
             this.stdBillsFeatureSpread = SheetDataHelper.createNewSpread($('#stdBillsFeatures')[0]);
         }
     },
+    refreshBillsRelaSpread: function () {
+        if (this.stdBillsJobSpread) {
+            this.stdBillsJobSpread.refresh();
+        }
+        if (this.stdBillsFeatureSpread) {
+            this.stdBillsFeatureSpread.refresh();
+        }
+    },
     loadStdBillsLib: function () {
         CommonAjax.post('/stdBillsEditor/getStdBillsLib', {userId: userID}, function (datas) {
             var i, select = $('#stdBillsLibSelect');
@@ -34,6 +47,7 @@ var billsLibObj = {
         });
     },
     loadStdBills: function (stdBillsLibID) {
+        var that = this;
         var stdBillsJobData, stdBillsFeatureData, stdBills;
         var stdBillsTree  = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
         var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(stdBillsTree, billsLibObj.stdBillsSpread.getActiveSheet(), billsLibObj.stdBillsTreeSetting);
@@ -115,6 +129,13 @@ var billsLibObj = {
             showBillsRela(stdBillsTree.firstNode());
 
             stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
+            that.stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
+                if (stdBillsTree.items[args.row].children.length === 0) {
+                    ProjectController.addBills(projectObj.project, projectObj.mainController, stdBillsTree.items[args.row]);
+                }
+            });
+        }, function () {
+            that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
         });
 
         $('#stdBillsSearch>span>button').click(function () {
@@ -285,6 +306,8 @@ var billsLibObj = {
 $('#stdBillsTab').bind('click', function () {
     $(".main-data-side-q").height($(window).height() - $(".header").height() - $(".toolsbar").height() -  $(".tools-bar-height-q").height() - 202);
     var select = $('#stdBillsLibSelect');
+    billsLibObj.refreshBillsSpread();
+    billsLibObj.refreshBillsRelaSpread();
     billsLibObj.checkBillsSpread();
     if (select[0].options.length === 0) {
         billsLibObj.loadStdBillsLib();

+ 10 - 1
web/building_saas/main/js/views/std_ration_lib.js

@@ -18,6 +18,14 @@ var rationLibObj = {
             this.sectionRationsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onRationSpreadCellDoubleClick);
         }
     },
+    refreshSpread: function () {
+        if (this.rationChapterSpread) {
+            this.rationChapterSpread.refresh();
+        }
+        if (this.sectionRationsSpread) {
+            this.sectionRationsSpread.refresh();
+        }
+    },
     loadStdRationLibs: function () {
         CommonAjax.postRationLib('/rationRepository/api/getRationDisplayNames', {user_id: userID}, function (datas) {
             var select = $('#stdRationLibSelect');
@@ -76,7 +84,7 @@ var rationLibObj = {
         var select = $('#stdRationLibSelect'), rationCode = args.sheet.getText(args.row, 0);
         if (rationCode !== '') {
             CommonAjax.postRationLib('/rationRepository/api/getRationItem', {user_id: userID, rationLibId: select.val(), code: rationCode}, function (data) {
-                ProjectController.addRation(project, controller, data);
+                ProjectController.addRation(projectObj.project, projectObj.mainController, data);
             });
         }
     },
@@ -184,6 +192,7 @@ var rationLibObj = {
 $('#stdRationTab').bind('click', function () {
     var select = $('#stdRationLibSelect');
     $(".main-data-side-d").height($(window).height() - $(".header").height() - $(".toolsbar").height() -  $(".tools-bar-height-d").height() - 202);
+    rationLibObj.refreshSpread();
     rationLibObj.checkSpread();
     if (select[0].options.length === 0) {
         rationLibObj.loadStdRationLibs();