|
@@ -0,0 +1,180 @@
|
|
|
+/**
|
|
|
+ * Created by Zhong on 2018/1/16.
|
|
|
+ */
|
|
|
+let gljClassTreeObj = {
|
|
|
+ cache: null,//ref to tree.items
|
|
|
+ tree: null,
|
|
|
+ controller: null,
|
|
|
+ workBook: null,
|
|
|
+ sheet: null,
|
|
|
+ setting: {
|
|
|
+ sheet: {
|
|
|
+ cols:[
|
|
|
+ {
|
|
|
+ head: {
|
|
|
+ titleNames: ['名称'],
|
|
|
+ spanCols: [1],
|
|
|
+ spanRows: [2],
|
|
|
+ vAlign: [1, 1],
|
|
|
+ hAlign: [1, 1],
|
|
|
+ font: 'Arial'
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ field: 'Name',
|
|
|
+ vAlign: 1,
|
|
|
+ hAlign: 0,
|
|
|
+ font: 'Arial'
|
|
|
+ },
|
|
|
+ width: 400
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [47],
|
|
|
+ emptyRows: 0,
|
|
|
+ treeCol: 0
|
|
|
+ },
|
|
|
+ tree: {
|
|
|
+ id: 'ID',
|
|
|
+ pid: 'ParentID',
|
|
|
+ nid: 'NextSiblingID',
|
|
|
+ rootId: -1
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ tabStripVisible: false,
|
|
|
+ allowCopyPasteExcelStyle : false,
|
|
|
+ allowExtendPasteRange: false,
|
|
|
+ allowUserDragDrop : false,
|
|
|
+ allowUserDragFill: false,
|
|
|
+ scrollbarMaxAlign : true
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ isDef: function (v) {
|
|
|
+ return v !== undefined && v !== null;
|
|
|
+ },
|
|
|
+ isFunc: function (v) {
|
|
|
+ return this.isDef(v) && typeof v === 'function';
|
|
|
+ },
|
|
|
+ //sheet things
|
|
|
+ setOptions: function (workbook, opts) {
|
|
|
+ for(let opt in opts){
|
|
|
+ workbook.options[opt] = opts[opt];
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ renderFunc: function (sheet, func) {
|
|
|
+ sheet.suspendPaint();
|
|
|
+ sheet.suspendEvent();
|
|
|
+ if(this.isFunc(func)){
|
|
|
+ func();
|
|
|
+ }
|
|
|
+ sheet.resumePaint();
|
|
|
+ sheet.resumeEvent();
|
|
|
+ },
|
|
|
+
|
|
|
+ buildSheet: function () {
|
|
|
+ if(!this.isDef(this.workBook)){
|
|
|
+ this.workBook = new GC.Spread.Sheets.Workbook($('#gljClassSpread')[0], {sheetCount: 1});
|
|
|
+ this.sheet = this.workBook.getActiveSheet();
|
|
|
+ this.setOptions(this.workBook, this.setting.options);
|
|
|
+ this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
|
|
|
+ this.bindEvents(this.sheet);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ bindEvents: function (sheet) {
|
|
|
+ let me = gljClassTreeObj;
|
|
|
+ const Events = GC.Spread.Sheets.Events;
|
|
|
+ sheet.bind(Events.SelectionChanging, me.onSelectionChanged);
|
|
|
+ sheet.bind(Events.EditStarting, me.onEditStarting);
|
|
|
+ sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
|
|
|
+ },
|
|
|
+
|
|
|
+ onSelectionChanged: function (sender, info) {
|
|
|
+ let me = gljClassTreeObj;
|
|
|
+ if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
|
|
|
+ let row = info.newSelections[0].row;
|
|
|
+ let node = me.cache[row];
|
|
|
+ me.initSelection(node);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ onEditStarting: function (sender, args) {
|
|
|
+ args.cancel = true;
|
|
|
+ },
|
|
|
+
|
|
|
+ onClipboardPasting: function (sender, info) {
|
|
|
+ info.cancel = true;
|
|
|
+ },
|
|
|
+
|
|
|
+ getGljClassTree: function (gljLibId, callback) {
|
|
|
+ let me = gljClassTreeObj;
|
|
|
+ let re = repositoryGljObj;
|
|
|
+ let url = 'complementartGlj/api/getGljTree';
|
|
|
+ let postData = {gljLibId: gljLibId};
|
|
|
+ let sucFunc = function (rstData) {
|
|
|
+ zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
|
|
|
+ let rootNode = componentOprObj.treeObj.getNodes()[0];
|
|
|
+ if(rootNode && rootNode.isParent && rootNode.isFirstNode){
|
|
|
+ componentOprObj.rootNode = rootNode;
|
|
|
+ }
|
|
|
+ if (rstData && rstData.length > 0) {
|
|
|
+ me.gljCurTypeId = rstData[0].ID;
|
|
|
+ }
|
|
|
+ //init
|
|
|
+ me.buildSheet();
|
|
|
+ me.initTree(rstData);
|
|
|
+ me.cache = me.tree.items;
|
|
|
+ re.updateParentNodeIds(me.cache, re);
|
|
|
+ me.initController(me.tree, me.sheet, me.setting.sheet);
|
|
|
+ me.controller.showTreeData();
|
|
|
+ me.sheet.setFormatter(-1, 0, '@');
|
|
|
+ me.initSelection(me.tree.selected);
|
|
|
+ if(callback){
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ let errFunc = function () {
|
|
|
+
|
|
|
+ };
|
|
|
+ CommonAjax.post(url, postData, sucFunc, errFunc);
|
|
|
+ },
|
|
|
+
|
|
|
+ initTree: function (datas) {
|
|
|
+ this.tree = idTree.createNew(this.setting.tree);
|
|
|
+ this.tree.loadDatas(datas);
|
|
|
+ this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
|
|
|
+ },
|
|
|
+
|
|
|
+ initController: function (tree, sheet, setting) {
|
|
|
+ this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
|
|
|
+ },
|
|
|
+
|
|
|
+ gljClassTreeAjax: function (postData, scFunc, errFunc) {
|
|
|
+ CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
|
|
|
+ },
|
|
|
+ //模仿默认点击
|
|
|
+ initSelection: function (node) {
|
|
|
+ let me = this,
|
|
|
+ re = repositoryGljObj,
|
|
|
+ that = gljComponentOprObj;
|
|
|
+ if(!re.isDef(node)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let gljTypeId = node.data.ID;
|
|
|
+ re.gljCurTypeId = node.data.ID;
|
|
|
+ re.addGljObj = null;
|
|
|
+ sheetOpr.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
|
|
|
+ if (re.parentNodeIds["_pNodeId_" + gljTypeId]) {
|
|
|
+ re.currentOprParent = 1;
|
|
|
+ re.currentCache = re.getParentCache(re.parentNodeIds["_pNodeId_" + gljTypeId]);
|
|
|
+ re.workBook.getSheet(0).setRowCount(re.currentCache.length);
|
|
|
+ } else {
|
|
|
+ re.currentOprParent = 0;
|
|
|
+ re.currentCache = re.getCache();
|
|
|
+ }
|
|
|
+ re.showGljItems(re.complementaryGljList, gljTypeId);
|
|
|
+ me.workBook.focus(true);
|
|
|
+ }
|
|
|
+}
|