gljClassTree.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. if (compleTreeData && compleTreeData.length > 0) {
  115. me.gljCurTypeId = compleTreeData[0].ID;
  116. }
  117. //init
  118. me.buildSheet();
  119. me.initTree(compleTreeData);
  120. me.cache = me.tree.items;
  121. re.updateParentNodeIds(me.cache, re);
  122. me.initController(me.tree, me.sheet, me.setting.sheet);
  123. me.controller.showTreeData();
  124. me.sheet.setFormatter(-1, 0, '@');
  125. //me.initSelection(me.tree.selected);
  126. if(callback){
  127. callback();
  128. }
  129. };
  130. CommonAjax.post(url, postData, sucFunc);
  131. },
  132. initTree: function (datas) {
  133. this.tree = idTree.createNew(this.setting.tree);
  134. this.tree.loadDatas(datas);
  135. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  136. },
  137. initController: function (tree, sheet, setting) {
  138. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  139. },
  140. gljClassTreeAjax: function (postData, scFunc, errFunc) {
  141. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  142. },
  143. //模仿默认点击
  144. initSelection: function (node) {
  145. let me = this,
  146. re = repositoryGljObj,
  147. that = gljComponentOprObj;
  148. if(!re.isDef(node)){
  149. return;
  150. }
  151. let gljTypeId = node.data.ID;
  152. re.gljCurTypeId = node.data.ID;
  153. re.addGljObj = null;
  154. sheetOpr.cleanSheet(that.workBook.getSheet(0), that.setting, 5);
  155. if (re.parentNodeIds["_pNodeId_" + gljTypeId]) {
  156. re.currentOprParent = 1;
  157. re.currentCache = re.getParentCache(re.parentNodeIds["_pNodeId_" + gljTypeId]);
  158. re.workBook.getSheet(0).setRowCount(re.currentCache.length);
  159. } else {
  160. re.currentOprParent = 0;
  161. re.currentCache = re.getCache();
  162. }
  163. re.showGljItems(re.complementaryGljList, gljTypeId);
  164. re.initSel(re.workBook.getSheet(0).getActiveRowIndex());
  165. me.workBook.focus(true);
  166. }
  167. }