section_tree.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /**
  2. * Created by Zhong on 2017/12/18.
  3. */
  4. let pageOprObj = {
  5. rationLibName : null,
  6. rationLibId : null,
  7. initPage : function() {
  8. var me = this, rationLibId = getQueryString("repository"),//获取定额库参数
  9. rationLibName = storageUtil.getSessionCache("RationGrp","repositoryID_" + rationLibId);
  10. if (rationLibName) {
  11. var html = $("#rationname")[0].outerHTML;
  12. html = html.replace("XXX定额库", rationLibName);
  13. $("#rationname")[0].outerHTML = html;
  14. me.rationLibName = rationLibName;
  15. me.rationLibId = rationLibId;
  16. sectionTreeObj.getSectionTree(rationLibId);
  17. //job
  18. jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
  19. $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
  20. $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
  21. jobContentOprObj.bindAllEvents($('#txtareaAll'));
  22. //fz
  23. annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
  24. $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
  25. $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
  26. annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
  27. }
  28. }
  29. }
  30. let sectionTreeObj = {
  31. cache: null,//ref to tree.items
  32. tree: null,
  33. controller: null,
  34. workBook: null,
  35. sheet: null,
  36. updateType: {new: 'new', update: 'update'},
  37. insertBtn: $('#tree_Insert'),
  38. removeBtn: $('#tree_remove'),
  39. upLevelBtn: $('#tree_upLevel'),
  40. downLevelBtn: $('#tree_downLevel'),
  41. downMoveBtn: $('#tree_downMove'),
  42. upMoveBtn: $('#tree_upMove'),
  43. setting: {
  44. sheet: {
  45. cols:[
  46. {
  47. head: {
  48. titleNames: ['名称'],
  49. spanCols: [1],
  50. spanRows: [2],
  51. vAlign: [1, 1],
  52. hAlign: [1, 1],
  53. font: 'Arial'
  54. },
  55. data: {
  56. field: 'name',
  57. vAlign: 1,
  58. hAlign: 0,
  59. font: 'Arial'
  60. },
  61. width: 400
  62. }
  63. ],
  64. headRows: 1,
  65. headRowHeight: [47],
  66. emptyRows: 0,
  67. treeCol: 0
  68. },
  69. tree: {
  70. id: 'ID',
  71. pid: 'ParentID',
  72. nid: 'NextSiblingID',
  73. rootId: -1
  74. },
  75. options: {
  76. tabStripVisible: false,
  77. allowCopyPasteExcelStyle : false,
  78. allowExtendPasteRange: false,
  79. allowUserDragDrop : false,
  80. allowUserDragFill: false,
  81. scrollbarMaxAlign : true
  82. }
  83. },
  84. isDef: function (v) {
  85. return v !== undefined && v !== null;
  86. },
  87. isFunc: function (v) {
  88. return this.isDef(v) && typeof v === 'function';
  89. },
  90. //sheet things
  91. setOptions: function (workbook, opts) {
  92. for(let opt in opts){
  93. workbook.options[opt] = opts[opt];
  94. }
  95. },
  96. renderFunc: function (sheet, func) {
  97. sheet.suspendPaint();
  98. sheet.suspendEvent();
  99. if(this.isFunc(func)){
  100. func();
  101. }
  102. sheet.resumePaint();
  103. sheet.resumeEvent();
  104. },
  105. buildSheet: function () {
  106. if(!this.isDef(this.workBook)){
  107. this.workBook = new GC.Spread.Sheets.Workbook($('#sectionSpread')[0], {sheetCount: 1});
  108. this.sheet = this.workBook.getActiveSheet();
  109. this.setOptions(this.workBook, this.setting.options);
  110. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  111. this.bindEvents(this.sheet);
  112. }
  113. },
  114. bindEvents: function (sheet) {
  115. let me = sectionTreeObj;
  116. const Events = GC.Spread.Sheets.Events;
  117. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  118. sheet.bind(Events.EditEnded, me.onEditEnded);
  119. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  120. },
  121. onSelectionChanged: function (sender, info) {
  122. let me = sectionTreeObj;
  123. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  124. let row = info.newSelections[0].row;
  125. let section = me.cache[row];
  126. me.initSelection(section);
  127. /*if(!me.isDef(section)){
  128. return;
  129. }
  130. me.initTools(section);
  131. me.refreshBtn(section);
  132. if(!me.isDef(section.children) || section.children.length === 0){
  133. rationOprObj.canRations = true;
  134. rationOprObj.workBook.getSheet(0).clearSelection();
  135. rationOprObj.getRationItems(section.data.ID);
  136. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  137. }
  138. else {
  139. rationOprObj.canRations = false;
  140. rationOprObj.currentSectionId = section.data.ID;
  141. rationOprObj.workBook.getSheet(0).setRowCount(30);
  142. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  143. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  144. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  145. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  146. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  147. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  148. }
  149. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  150. rationGLJOprObj.sheet.getParent().focus(false);
  151. me.workBook.focus(true);*/
  152. }
  153. else {
  154. me.refreshBtn(null);
  155. }
  156. },
  157. onEditEnded: function (sender, args) {
  158. let me = sectionTreeObj;
  159. let postData = [];
  160. let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : '';
  161. let node = me.cache[args.row];
  162. if(me.isDef(node) && node.data.name !== v){
  163. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, v, null);
  164. postData.push(updateObj);
  165. //ajax
  166. //update
  167. me.sectionTreeAjax(postData, function (rstData) {
  168. node.data.name = v;
  169. }, function () {
  170. args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : '');
  171. });
  172. }
  173. },
  174. onClipboardPasted: function (sender, info) {
  175. let me = sectionTreeObj;
  176. let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'name'}]}, info);
  177. let postData = [];
  178. let frontData = [];
  179. for(let i = 0, len = items.length; i < len; i++){
  180. let row = info.cellRange.row + i;
  181. let node = me.cache[row];
  182. if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){
  183. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, items[i].name, null);
  184. postData.push(updateObj);
  185. frontData.push({row: row, name: items[i].name});
  186. node.data.name = items[i].name;
  187. }
  188. }
  189. if(postData.length > 0){
  190. //ajax
  191. me.sectionTreeAjax(postData, function (rstData) {
  192. for(let i = 0, len = frontData.length; i < len; i++){
  193. let node = me.cache[frontData[i]['row']];
  194. if(me.isDef(node)){
  195. node.data.name = frontData[i]['name'];
  196. }
  197. }
  198. }, function () {
  199. for(let i = 0, len = frontData.length; i < len; i++){
  200. let node = me.cache[frontData[i]['row']];
  201. me.sheet.setValue(frontData[i]['row'], 0, me.isDef(node) ? node.data.name : '');
  202. }
  203. });
  204. }
  205. },
  206. getSectionTree: function (repId) {
  207. let me = sectionTreeObj;
  208. let url = 'api/getRationTree';
  209. let postData = {rationLibId: repId};
  210. let sucFunc = function (rstData) {
  211. if(rstData.length > 0){
  212. storageUtil.setSessionCache("RationGrp","repositoryID",rstData[0].rationRepId);
  213. }
  214. //init
  215. me.buildSheet();
  216. me.initTree(rstData);
  217. me.cache = me.tree.items;
  218. //me.refreshBtn(me.tree.selected);
  219. me.bindBtn();
  220. me.initController(me.tree, me.sheet, me.setting.sheet);
  221. me.controller.showTreeData();
  222. //me.initTools(me.tree.selected);
  223. me.initSelection(me.tree.selected);
  224. explanatoryOprObj.bindEvents($('#explanationShow'), $('#ruleTextShow'));
  225. };
  226. let errFunc = function () {
  227. };
  228. CommonAjax.post(url, postData, sucFunc, errFunc);
  229. },
  230. initTree: function (datas) {
  231. this.tree = idTree.createNew(this.setting.tree);
  232. this.tree.loadDatas(datas);
  233. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  234. },
  235. initController: function (tree, sheet, setting) {
  236. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  237. },
  238. refreshBtn: function (selected) {
  239. let me = this;
  240. me.insertBtn.removeClass('disabled');
  241. me.removeBtn.removeClass('disabled');
  242. me.upLevelBtn.removeClass('disabled');
  243. me.downLevelBtn.removeClass('disabled');
  244. me.downMoveBtn.removeClass('disabled');
  245. me.upMoveBtn.removeClass('disabled');
  246. if(!me.isDef(selected)){
  247. me.removeBtn.addClass('disabled');
  248. me.upLevelBtn.addClass('disabled');
  249. me.downLevelBtn.addClass('disabled');
  250. me.downMoveBtn.addClass('disabled');
  251. me.upMoveBtn.addClass('disabled');
  252. }
  253. else {
  254. if(!me.isDef(selected.preSibling)){
  255. me.downLevelBtn.addClass('disabled');
  256. me.upMoveBtn.addClass('disabled');
  257. }
  258. if(!me.isDef(selected.nextSibling)){
  259. me.downMoveBtn.addClass('disabled');
  260. }
  261. if(!me.isDef(selected.parent)){
  262. me.upLevelBtn.addClass('disabled');
  263. }
  264. }
  265. },
  266. bindBtn: function () {
  267. let me = this;
  268. me.insertBtn.click(function () {
  269. me.insert();
  270. });
  271. me.removeBtn.click(function () {
  272. me.remove(me.tree.selected);
  273. });
  274. me.upLevelBtn.click(function () {
  275. me.upLevel(me.tree.selected);
  276. });
  277. me.downLevelBtn.click(function () {
  278. me.downLevel(me.tree.selected);
  279. });
  280. me.downMoveBtn.click(function () {
  281. me.downMove(me.tree.selected);
  282. });
  283. me.upMoveBtn.click(function () {
  284. me.upMove(me.tree.selected);
  285. });
  286. },
  287. insert: function () {
  288. let me = this;
  289. me.insertBtn.addClass('disabled');
  290. let postData = [];
  291. let newID = me.tree.newNodeID();
  292. let selected = me.tree.selected;
  293. let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
  294. if(me.isDef(selected)) {
  295. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
  296. postData.push(updateObj);
  297. insertObj.updateData.ParentID = selected.getParentID();
  298. if(me.isDef(selected.nextSibling)){
  299. insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
  300. }
  301. }
  302. postData.push(insertObj);
  303. if(postData.length > 0){
  304. //ajax
  305. me.sectionTreeAjax(postData, function (rstData) {
  306. me.controller.insert();
  307. me.refreshBtn(me.tree.selected);
  308. //fresh tools
  309. me.initTools(me.tree.selected);
  310. });
  311. }
  312. },
  313. remove: function (selected) {
  314. let me = this;
  315. me.removeBtn.addClass('disabled');
  316. let postData = [], IDs = [];
  317. if(!selected){
  318. return;
  319. }
  320. getDelIds(selected);
  321. function getDelIds(node){
  322. if(me.isDef(node)){
  323. IDs.push(node.getID());
  324. if(node.children.length > 0){
  325. for(let i = 0, len = node.children.length; i < len; i++){
  326. getDelIds(node.children[i]);
  327. }
  328. }
  329. }
  330. }
  331. if(me.isDef(selected.preSibling)){
  332. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  333. postData.push(updateObj);
  334. }
  335. if(IDs.length > 0){
  336. for(let i = 0, len = IDs.length; i < len; i++){
  337. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  338. postData.push(delObj);
  339. }
  340. }
  341. if(postData.length > 0){
  342. //ajax
  343. me.sectionTreeAjax(postData, function (rstData) {
  344. me.controller.delete();
  345. me.refreshBtn(me.tree.selected);
  346. me.initTools(me.tree.selected);
  347. });
  348. }
  349. },
  350. upLevel: function (selected) {
  351. let me = this;
  352. me.upLevelBtn.addClass('disabled');
  353. let postData = [];
  354. if(!me.isDef(selected)){
  355. return;
  356. }
  357. if(!me.isDef(selected.parent)){
  358. return;
  359. }
  360. if(me.isDef(selected.preSibling)){
  361. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), -1, null, null, null);
  362. postData.push(updateObj);
  363. }
  364. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.parent.getNextSiblingID(), selected.parent.getParentID(), null, null);
  365. postData.push(updateObj);
  366. let updateParent = me.getUpdateObj(me.updateType.update, selected.getParentID(), selected.getID(), null, null, null);
  367. postData.push(updateParent);
  368. let nextIDs = [];
  369. getNext(selected);
  370. function getNext(node){
  371. if(me.isDef(node.nextSibling)){
  372. nextIDs.push(node.getNextSiblingID());
  373. getNext(node.nextSibling);
  374. }
  375. }
  376. for(let i = 0, len = nextIDs.length; i < len; i++){
  377. postData.push(me.getUpdateObj(me.updateType.update, nextIDs[i], null, selected.getID(), null, null));
  378. }
  379. if(postData.length > 0){
  380. //ajax
  381. me.sectionTreeAjax(postData, function (rstData) {
  382. me.controller.upLevel();
  383. me.refreshBtn(me.tree.selected);
  384. });
  385. }
  386. },
  387. downLevel: function (selected) {
  388. let me = this;
  389. me.downLevelBtn.addClass('disabled');
  390. let postData = [];
  391. if(!me.isDef(selected)){
  392. return;
  393. }
  394. if(!me.isDef(selected.preSibling)){
  395. return;
  396. }
  397. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  398. postData.push(updatePre);
  399. if(selected.preSibling.children.length > 0){
  400. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.children[selected.preSibling.children.length - 1].getID(), selected.getID(), null, null, null);
  401. postData.push(updateObj);
  402. }
  403. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), -1, selected.preSibling.getID(), null, null);
  404. postData.push(updateObj);
  405. if(postData.length > 0){
  406. //ajax
  407. me.sectionTreeAjax(postData, function (rstData) {
  408. me.controller.downLevel();
  409. me.refreshBtn(me.tree.selected);
  410. });
  411. }
  412. },
  413. upMove: function (selected) {
  414. let me = this;
  415. me.upMoveBtn.addClass('disabled');
  416. let postData = [];
  417. if(!me.isDef(selected)){
  418. return;
  419. }
  420. if(!me.isDef(selected.preSibling)){
  421. return;
  422. }
  423. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  424. postData.push(updateObj);
  425. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  426. postData.push(updatePre);
  427. if(me.isDef(selected.preSibling.preSibling)){
  428. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  429. postData.push(updatePrepre);
  430. }
  431. if(postData.length > 0){
  432. //ajax
  433. me.sectionTreeAjax(postData, function (rstData) {
  434. me.controller.upMove();
  435. me.refreshBtn(me.tree.selected);
  436. });
  437. }
  438. },
  439. downMove: function (selected) {
  440. let me = this;
  441. me.downMoveBtn.addClass('disabled');
  442. let postData = [];
  443. if(!me.isDef(selected)){
  444. return;
  445. }
  446. if(!me.isDef(selected.nextSibling)){
  447. return;
  448. }
  449. if(me.isDef(selected.preSibling)){
  450. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  451. postData.push(updatePre);
  452. }
  453. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  454. postData.push(updateObj);
  455. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  456. postData.push(updateNext);
  457. if(postData.length > 0){
  458. //ajax
  459. me.sectionTreeAjax(postData, function (rstData) {
  460. me.controller.downMove();
  461. me.refreshBtn(me.tree.selected);
  462. });
  463. }
  464. },
  465. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  466. let updateObj = Object.create(null);
  467. updateObj.updateType = '';
  468. updateObj.updateData = Object.create(null);
  469. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  470. if(this.isDef(updateType)){
  471. updateObj.updateType = updateType;
  472. }
  473. if(this.isDef(id)){
  474. updateObj.updateData.ID = id;
  475. }
  476. if(this.isDef(nid)){
  477. updateObj.updateData.NextSiblingID = nid;
  478. }
  479. if(this.isDef(pid)){
  480. updateObj.updateData.ParentID = pid;
  481. }
  482. if(this.isDef(name)){
  483. updateObj.updateData.name = name;
  484. }
  485. if(this.isDef(deleted)){
  486. updateObj.updateData.isDeleted = true;
  487. }
  488. return updateObj;
  489. },
  490. sectionTreeAjax: function (postData, scFunc, errFunc) {
  491. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  492. },
  493. initTools: function (node) {
  494. if(this.isDef(node)){
  495. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  496. explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
  497. explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), node.data.explanation, node.data.ruleText);
  498. //job
  499. jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.NONE;
  500. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
  501. jobContentOprObj.clickUpdate($('#txtareaAll'));
  502. //fz
  503. annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.NONE;
  504. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  505. }
  506. },
  507. //模仿默认点击
  508. initSelection: function (node) {
  509. let me = this;
  510. if(!me.isDef(node)){
  511. return;
  512. }
  513. me.initTools(node);
  514. me.refreshBtn(node);
  515. if(!me.isDef(node.children) || node.children.length === 0){
  516. rationOprObj.canRations = true;
  517. rationOprObj.workBook.getSheet(0).clearSelection();
  518. rationOprObj.getRationItems(node.data.ID);
  519. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  520. }
  521. else {
  522. rationOprObj.canRations = false;
  523. rationOprObj.currentSectionId = node.data.ID;
  524. rationOprObj.workBook.getSheet(0).setRowCount(30);
  525. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  526. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  527. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  528. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  529. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  530. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  531. }
  532. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  533. rationGLJOprObj.sheet.getParent().focus(false);
  534. me.workBook.focus(true);
  535. }
  536. };