gljClassTree.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * Created by Zhong on 2018/1/16.
  3. */
  4. let gljClassTreeObj = {
  5. treeData: null,
  6. cache: null,//ref to tree.items
  7. tree: null,
  8. controller: null,
  9. workBook: null,
  10. sheet: null,
  11. setting: {
  12. sheet: {
  13. cols:[
  14. {
  15. head: {
  16. titleNames: ['名称'],
  17. spanCols: [1],
  18. spanRows: [2],
  19. vAlign: [1, 1],
  20. hAlign: [1, 1],
  21. font: 'Arial'
  22. },
  23. data: {
  24. field: 'Name',
  25. vAlign: 1,
  26. hAlign: 0,
  27. font: 'Arial'
  28. },
  29. width: 400
  30. }
  31. ],
  32. headRows: 1,
  33. headRowHeight: [47],
  34. emptyRows: 0,
  35. treeCol: 0
  36. },
  37. tree: {
  38. id: 'ID',
  39. pid: 'ParentID',
  40. nid: 'NextSiblingID',
  41. rootId: -1
  42. },
  43. options: {
  44. tabStripVisible: false,
  45. allowContextMenu: false,
  46. allowCopyPasteExcelStyle : false,
  47. allowExtendPasteRange: false,
  48. allowUserDragDrop : false,
  49. allowUserDragFill: false,
  50. scrollbarMaxAlign : true
  51. }
  52. },
  53. isDef: function (v) {
  54. return v !== undefined && v !== null;
  55. },
  56. isFunc: function (v) {
  57. return this.isDef(v) && typeof v === 'function';
  58. },
  59. //sheet things
  60. setOptions: function (workbook, opts) {
  61. for(let opt in opts){
  62. workbook.options[opt] = opts[opt];
  63. }
  64. },
  65. renderFunc: function (sheet, func) {
  66. sheet.suspendPaint();
  67. sheet.suspendEvent();
  68. if(this.isFunc(func)){
  69. func();
  70. }
  71. sheet.resumePaint();
  72. sheet.resumeEvent();
  73. },
  74. buildSheet: function () {
  75. if(!this.isDef(this.workBook)){
  76. this.workBook = new GC.Spread.Sheets.Workbook($('#gljClassSpread')[0], {sheetCount: 1});
  77. sheetCommonObj.spreadDefaultStyle(this.workBook);
  78. this.sheet = this.workBook.getActiveSheet();
  79. this.setOptions(this.workBook, this.setting.options);
  80. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  81. this.bindEvents(this.sheet);
  82. }
  83. },
  84. bindEvents: function (sheet) {
  85. let me = gljClassTreeObj;
  86. const Events = GC.Spread.Sheets.Events;
  87. sheet.bind(Events.SelectionChanging, me.onSelectionChanged);
  88. sheet.bind(Events.EditStarting, me.onEditStarting);
  89. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  90. },
  91. onSelectionChanged: function (sender, info) {
  92. let me = gljClassTreeObj;
  93. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  94. let row = info.newSelections[0].row;
  95. let node = me.cache[row];
  96. me.initSelection(node);
  97. }
  98. },
  99. onEditStarting: function (sender, args) {
  100. args.cancel = true;
  101. },
  102. onClipboardPasting: function (sender, info) {
  103. info.cancel = true;
  104. },
  105. getGljClassTree: function (gljLibId, callback) {
  106. console.log('enter1');
  107. let me = gljClassTreeObj;
  108. let re = repositoryGljObj;
  109. let url = '/complementartGlj/api/getMixedTree';
  110. let postData = {gljLibId: gljLibId};
  111. let sucFunc = function (rstData) {
  112. me.treeData = rstData;
  113. let compleTreeData = me.treeData.comple;
  114. /*zTreeHelper.createTree(rstData.std, componentSetting, "componentTree", componentOprObj);
  115. let rootNode = componentOprObj.treeObj.getNodes()[0];
  116. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  117. componentOprObj.rootNode = rootNode;
  118. }*/
  119. if (compleTreeData && compleTreeData.length > 0) {
  120. me.gljCurTypeId = compleTreeData[0].ID;
  121. }
  122. //init
  123. me.buildSheet();
  124. me.initTree(compleTreeData);
  125. me.cache = me.tree.items;
  126. re.updateParentNodeIds(me.cache, re);
  127. me.initController(me.tree, me.sheet, me.setting.sheet);
  128. me.controller.showTreeData();
  129. me.sheet.setFormatter(-1, 0, '@');
  130. me.initSelection(me.tree.selected);
  131. if(callback){
  132. callback();
  133. }
  134. };
  135. let errFunc = function () {
  136. };
  137. CommonAjax.post(url, postData, sucFunc, errFunc);
  138. },
  139. initTree: function (datas) {
  140. this.tree = idTree.createNew(this.setting.tree);
  141. this.tree.loadDatas(datas);
  142. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  143. },
  144. initController: function (tree, sheet, setting) {
  145. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  146. },
  147. gljClassTreeAjax: function (postData, scFunc, errFunc) {
  148. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  149. },
  150. //模仿默认点击
  151. initSelection: function (node) {
  152. let me = this,
  153. re = repositoryGljObj,
  154. that = gljComponentOprObj;
  155. if(!re.isDef(node)){
  156. return;
  157. }
  158. let gljTypeId = node.data.ID;
  159. re.gljCurTypeId = node.data.ID;
  160. re.addGljObj = null;
  161. sheetOpr.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
  162. if (re.parentNodeIds["_pNodeId_" + gljTypeId]) {
  163. re.currentOprParent = 1;
  164. re.currentCache = re.getParentCache(re.parentNodeIds["_pNodeId_" + gljTypeId]);
  165. re.workBook.getSheet(0).setRowCount(re.currentCache.length);
  166. } else {
  167. re.currentOprParent = 0;
  168. re.currentCache = re.getCache();
  169. }
  170. re.showGljItems(re.complementaryGljList, gljTypeId);
  171. re.initSel(re.workBook.getSheet(0).getActiveRowIndex());
  172. me.workBook.focus(true);
  173. }
  174. }