section_tree.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /**
  2. * Created by Zhong on 2017/12/18.
  3. */
  4. const locked = lockUtil.getLocked();
  5. const moduleName = 'stdRation';
  6. //上下拖动div节点的高度
  7. const verticalResize = 10;
  8. let pageOprObj = {
  9. rationLibName : null,
  10. rationLibId : null,
  11. gljLibId: null,
  12. initPage : function(libInfo) {
  13. this.rationLibId = libInfo.ID;
  14. this.gljLibId = libInfo.gljLib;
  15. this.rationLibName = libInfo.dispName;
  16. $('#rationname').html(`<a href="main">定额库</a><i class="fa fa-angle-right fa-fw"></i>${this.rationLibName}`);
  17. if (!this.gljLibId || this.gljLibId === -1) {
  18. alert('没有引用人材机库');
  19. setTimeout(() => window.location.href = '/rationRepository/main', 2000);
  20. }
  21. //job
  22. jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
  23. $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
  24. $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
  25. jobContentOprObj.bindAllEvents($('#txtareaAll'));
  26. //fz
  27. annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
  28. $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
  29. $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
  30. annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
  31. },
  32. };
  33. let sectionTreeObj = {
  34. cache: null,//ref to tree.items
  35. tree: null,
  36. controller: null,
  37. workBook: null,
  38. sheet: null,
  39. updateType: {new: 'new', update: 'update'},
  40. insertBtn: $('#tree_Insert'),
  41. removeBtn: $('#tree_remove'),
  42. upLevelBtn: $('#tree_upLevel'),
  43. downLevelBtn: $('#tree_downLevel'),
  44. downMoveBtn: $('#tree_downMove'),
  45. upMoveBtn: $('#tree_upMove'),
  46. setting: {
  47. sheet: {
  48. cols:[
  49. {
  50. head: {
  51. titleNames: ['ID'],
  52. spanCols: [1],
  53. spanRows: [2],
  54. vAlign: [1, 1],
  55. hAlign: [1, 1],
  56. font: 'Arial'
  57. },
  58. data: {
  59. field: 'ID',
  60. vAlign: 1,
  61. hAlign: 0,
  62. font: 'Arial'
  63. },
  64. width: 40
  65. },
  66. {
  67. head: {
  68. titleNames: ['名称'],
  69. spanCols: [1],
  70. spanRows: [2],
  71. vAlign: [1, 1],
  72. hAlign: [1, 1],
  73. font: 'Arial'
  74. },
  75. data: {
  76. field: 'name',
  77. vAlign: 1,
  78. hAlign: 0,
  79. font: 'Arial'
  80. },
  81. width: 370
  82. }
  83. ],
  84. headRows: 1,
  85. headRowHeight: [25],
  86. emptyRows: 0,
  87. treeCol: 1
  88. },
  89. tree: {
  90. id: 'ID',
  91. pid: 'ParentID',
  92. nid: 'NextSiblingID',
  93. rootId: -1
  94. },
  95. options: {
  96. tabStripVisible: false,
  97. allowContextMenu: false,
  98. allowCopyPasteExcelStyle : false,
  99. allowExtendPasteRange: false,
  100. allowUserDragDrop : false,
  101. allowUserDragFill: false,
  102. scrollbarMaxAlign : true
  103. }
  104. },
  105. isDef: function (v) {
  106. return v !== undefined && v !== null;
  107. },
  108. isFunc: function (v) {
  109. return this.isDef(v) && typeof v === 'function';
  110. },
  111. //sheet things
  112. setOptions: function (workbook, opts) {
  113. for(let opt in opts){
  114. workbook.options[opt] = opts[opt];
  115. }
  116. },
  117. renderFunc: function (sheet, func) {
  118. sheet.suspendPaint();
  119. sheet.suspendEvent();
  120. if(this.isFunc(func)){
  121. func();
  122. }
  123. sheet.resumePaint();
  124. sheet.resumeEvent();
  125. },
  126. buildSheet: function () {
  127. if(!this.isDef(this.workBook)){
  128. this.workBook = new GC.Spread.Sheets.Workbook($('#sectionSpread')[0], {sheetCount: 1});
  129. sheetCommonObj.bindEscKey(this.workBook, [{sheet: this.workBook.getSheet(0), editStarting: this.onEditStarting, editEnded: this.onEditEnded}]);
  130. this.sheet = this.workBook.getActiveSheet();
  131. this.setOptions(this.workBook, this.setting.options);
  132. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  133. this.bindEvents(this.sheet);
  134. }
  135. },
  136. bindEvents: function (sheet) {
  137. let me = sectionTreeObj;
  138. const Events = GC.Spread.Sheets.Events;
  139. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  140. sheet.bind(Events.EditStarting, me.onEditStarting);
  141. sheet.bind(Events.EditEnded, me.onEditEnded);
  142. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  143. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  144. },
  145. onSelectionChanged: function (sender, info) {
  146. let me = sectionTreeObj;
  147. let row = info.newSelections[0].row;
  148. let section = me.cache[row];
  149. me.initSelection(section);
  150. },
  151. onEditStarting: function (sender, args) {
  152. let me = sectionTreeObj;
  153. let dataCode = me.setting.sheet.cols[args.col]['data']['field'];
  154. if(dataCode === 'ID'){
  155. args.cancel = true;
  156. }
  157. },
  158. onEditEnded: function (sender, args) {
  159. let me = sectionTreeObj;
  160. let postData = [];
  161. let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : '';
  162. let node = me.cache[args.row];
  163. if(me.isDef(node) && node.data.name !== v){
  164. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, v, null);
  165. postData.push(updateObj);
  166. //ajax
  167. //update
  168. me.sectionTreeAjax(postData, function (rstData) {
  169. node.data.name = v;
  170. }, function () {
  171. args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : '');
  172. });
  173. }
  174. },
  175. onClipboardPasting: function (sender, info) {
  176. let me = sectionTreeObj;
  177. if(info.cellRange.col === 0){
  178. info.cancel = true;
  179. }
  180. },
  181. onClipboardPasted: function (sender, info) {
  182. let me = sectionTreeObj;
  183. let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'ID'}, {dataCode: 'name'}]}, info);
  184. let postData = [];
  185. let frontData = [];
  186. for(let i = 0, len = items.length; i < len; i++){
  187. let row = info.cellRange.row + i;
  188. let node = me.cache[row];
  189. if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){
  190. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, items[i].name, null);
  191. postData.push(updateObj);
  192. frontData.push({row: row, name: items[i].name});
  193. node.data.name = items[i].name;
  194. }
  195. }
  196. if(postData.length > 0){
  197. //ajax
  198. me.sectionTreeAjax(postData, function (rstData) {
  199. for(let i = 0, len = frontData.length; i < len; i++){
  200. let node = me.cache[frontData[i]['row']];
  201. if(me.isDef(node)){
  202. node.data.name = frontData[i]['name'];
  203. }
  204. }
  205. }, function () {
  206. for(let i = 0, len = frontData.length; i < len; i++){
  207. let node = me.cache[frontData[i]['row']];
  208. me.sheet.setValue(frontData[i]['row'], 1, me.isDef(node) ? node.data.name : '');
  209. }
  210. });
  211. }
  212. },
  213. loadRateWidth: function () {
  214. if (this.workBook) {
  215. //ID列固定40宽度
  216. let spreadWidth = $('#sectionSpread').width() - 65; //65: 列头宽度和垂直滚动条宽度和
  217. let IDRate = 40 / spreadWidth,
  218. nameRate = 1 - IDRate;
  219. sheetCommonObj.setColumnWidthByRate($('#sectionSpread').width() - 65, this.workBook, [{rateWidth: IDRate}, {rateWidth: nameRate}]);
  220. }
  221. },
  222. initSectionTree: function (sectionTree) {
  223. //init
  224. this.buildSheet();
  225. this.initTree(sectionTree);
  226. this.cache = this.tree.items;
  227. this.bindBtn();
  228. this.initController(this.tree, this.sheet, this.setting.sheet);
  229. this.controller.showTreeData();
  230. this.sheet.setFormatter(-1, 0, '@');
  231. this.initSelection(this.tree.selected);
  232. explanatoryOprObj.bindEvents(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor);
  233. this.loadRateWidth();
  234. this.autoLocate();
  235. },
  236. //自动定位
  237. autoLocate: function () {
  238. const hash = window.location.hash;
  239. const $searchInput = $('#rationSearch');
  240. if (hash) {
  241. const rationCode = hash.replace('#', '');
  242. $searchInput.val(rationCode);
  243. this.locateToSection(rationCode);
  244. }
  245. },
  246. initTree: function (datas) {
  247. this.tree = idTree.createNew(this.setting.tree);
  248. this.tree.loadDatas(datas);
  249. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  250. },
  251. initController: function (tree, sheet, setting) {
  252. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  253. },
  254. refreshBtn: function (selected) {
  255. if (locked) {
  256. return;
  257. }
  258. let me = this;
  259. me.insertBtn.removeClass('disabled');
  260. me.removeBtn.removeClass('disabled');
  261. me.upLevelBtn.removeClass('disabled');
  262. me.downLevelBtn.removeClass('disabled');
  263. me.downMoveBtn.removeClass('disabled');
  264. me.upMoveBtn.removeClass('disabled');
  265. if(!me.isDef(selected)){
  266. me.removeBtn.addClass('disabled');
  267. me.upLevelBtn.addClass('disabled');
  268. me.downLevelBtn.addClass('disabled');
  269. me.downMoveBtn.addClass('disabled');
  270. me.upMoveBtn.addClass('disabled');
  271. }
  272. else {
  273. if(!me.isDef(selected.preSibling)){
  274. me.downLevelBtn.addClass('disabled');
  275. me.upMoveBtn.addClass('disabled');
  276. }
  277. if(!me.isDef(selected.nextSibling)){
  278. me.downMoveBtn.addClass('disabled');
  279. }
  280. if(!me.isDef(selected.parent)){
  281. me.upLevelBtn.addClass('disabled');
  282. }
  283. }
  284. },
  285. bindBtn: function () {
  286. let me = this;
  287. me.insertBtn.click(function () {
  288. me.insert();
  289. });
  290. $('#delConfirm').click(function () {
  291. if(me.canRemoveSection){
  292. me.remove(me.tree.selected);
  293. }
  294. else {
  295. $('#delAlert').modal('hide');
  296. }
  297. });
  298. me.removeBtn.click(function () {
  299. //不可删除有子节点或有定额数据的节点
  300. let section = me.cache[me.workBook.getActiveSheet().getActiveRowIndex()];
  301. if(!section){
  302. return;
  303. }
  304. let sectionName = me.isDef(section.data.name) ? section.data.name : '';
  305. let sectionRations = rationOprObj.currentRations[`_SEC_ID_${section.data.ID}`];
  306. if(section.children.length > 0 || (sectionRations && sectionRations.length > 0)){
  307. me.canRemoveSection = false;
  308. $('#delAlert').find('.modal-body h5').text('当前节点下有数据,不可删除。');
  309. }
  310. else {
  311. me.canRemoveSection = true;
  312. $('#delAlert').find('.modal-body h5').text(`确认要删除章节 “${sectionName}”吗?`);
  313. }
  314. $('#delAlert').modal('show');
  315. });
  316. me.upLevelBtn.click(function () {
  317. me.upLevel(me.tree.selected);
  318. });
  319. me.downLevelBtn.click(function () {
  320. me.downLevel(me.tree.selected);
  321. });
  322. me.downMoveBtn.click(function () {
  323. me.downMove(me.tree.selected);
  324. });
  325. me.upMoveBtn.click(function () {
  326. me.upMove(me.tree.selected);
  327. });
  328. },
  329. insert: function () {
  330. let me = sectionTreeObj;
  331. me.insertBtn.addClass('disabled');
  332. let postData = [];
  333. CommonAjax.post('api/getNewRationTreeID', {}, function (newID) {
  334. if(!me.isDef(newID)){
  335. return;
  336. }
  337. me.tree.maxNodeID(newID - 1);
  338. let selected = me.tree.selected;
  339. let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
  340. if(me.isDef(selected)) {
  341. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
  342. postData.push(updateObj);
  343. insertObj.updateData.ParentID = selected.getParentID();
  344. if(me.isDef(selected.nextSibling)){
  345. insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
  346. }
  347. }
  348. postData.push(insertObj);
  349. if(postData.length > 0){
  350. //ajax
  351. me.sectionTreeAjax(postData, function (rstData) {
  352. me.controller.insert();
  353. me.refreshBtn(me.tree.selected);
  354. //fresh tools
  355. me.initTools(me.tree.selected);
  356. me.workBook.focus();
  357. me.initSelection(me.tree.selected);
  358. });
  359. }
  360. });
  361. },
  362. remove: function (selected) {
  363. let me = this;
  364. me.removeBtn.addClass('disabled');
  365. let postData = [], IDs = [];
  366. if(!selected){
  367. return;
  368. }
  369. getDelIds(selected);
  370. function getDelIds(node){
  371. if(me.isDef(node)){
  372. IDs.push(node.getID());
  373. if(node.children.length > 0){
  374. for(let i = 0, len = node.children.length; i < len; i++){
  375. getDelIds(node.children[i]);
  376. }
  377. }
  378. }
  379. }
  380. if(me.isDef(selected.preSibling)){
  381. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  382. postData.push(updateObj);
  383. }
  384. if(IDs.length > 0){
  385. for(let i = 0, len = IDs.length; i < len; i++){
  386. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  387. postData.push(delObj);
  388. }
  389. }
  390. if(postData.length > 0){
  391. //ajax
  392. me.sectionTreeAjax(postData, function (rstData) {
  393. $('#delAlert').modal('hide');
  394. me.removeRationsCodes(rationOprObj.currentRations["_SEC_ID_" + selected.data.ID]);
  395. me.controller.delete();
  396. me.refreshBtn(me.tree.selected);
  397. me.initTools(me.tree.selected);
  398. me.initSelection(me.tree.selected);
  399. me.workBook.focus();
  400. });
  401. }
  402. },
  403. removeRationsCodes: function (rations) {
  404. for(let ration of rations){
  405. rationOprObj.rationsCodes.splice(rationOprObj.rationsCodes.indexOf(ration.code), 1);
  406. }
  407. },
  408. getSameDepthNodes: function(){
  409. let rst = [];
  410. let sel = this.sheet.getSelections()[0];
  411. let selectedDepth = this.tree.selected.depth();
  412. for(let i = 0; i < sel.rowCount; i++){
  413. let row = sel.row + i;
  414. if(this.cache[row].depth() === selectedDepth){
  415. rst.push(this.cache[row]);
  416. }
  417. }
  418. return rst;
  419. },
  420. upLevel: function (selected) {
  421. let me = this;
  422. me.upLevelBtn.addClass('disabled');
  423. let postData = [];
  424. let selNodes = me.getSameDepthNodes();
  425. if(selNodes.length <= 0){
  426. return ;
  427. }
  428. let firstParent = selNodes[0].parent;
  429. if(!me.isDef(firstParent)){
  430. return;
  431. }
  432. //更新父节点
  433. postData.push(me.getUpdateObj(me.updateType.update, firstParent.getID(), selNodes[0].getID(), null, null, null));
  434. //更新前节点
  435. if(me.isDef(selNodes[0].preSibling)){
  436. postData.push(me.getUpdateObj(me.updateType.update, selNodes[0].preSibling.getID(), -1, null, null, null));
  437. }
  438. //更新选中节点的后兄弟节点
  439. let lastSelNode = selNodes[selNodes.length - 1];
  440. let nextIDs = [];
  441. getNext(lastSelNode);
  442. function getNext(node){
  443. if(me.isDef(node.nextSibling)){
  444. nextIDs.push(node.getNextSiblingID());
  445. getNext(node.nextSibling);
  446. }
  447. }
  448. for(let nextID of nextIDs){
  449. postData.push(me.getUpdateObj(me.updateType.update, nextID, null, lastSelNode.getID(), null, null));
  450. }
  451. //更新选中节点
  452. for(let i = 0; i < selNodes.length; i++){
  453. let selNode = selNodes[i];
  454. let nid = i === selNodes.length - 1 ? firstParent.getNextSiblingID() : selNode.getNextSiblingID();
  455. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), nid, firstParent.getParentID(), null, null));
  456. }
  457. if(postData.length > 0){
  458. //ajax
  459. me.sectionTreeAjax(postData, function (rstData) {
  460. for(let selNode of selNodes){
  461. me.controller.setTreeSelected(selNode);
  462. me.controller.upLevel();
  463. }
  464. me.refreshBtn(me.tree.selected);
  465. me.workBook.focus();
  466. });
  467. }
  468. },
  469. downLevel: function (selected) {
  470. let me = this;
  471. me.downLevelBtn.addClass('disabled');
  472. let postData = [];
  473. let selNodes = me.getSameDepthNodes();
  474. if(selNodes.length <= 0 ){
  475. return;
  476. }
  477. let firstPreSibling = selNodes[0].preSibling;
  478. if(!me.isDef(firstPreSibling)){
  479. return;
  480. }
  481. //更新前节点
  482. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.getID(), selNodes[selNodes.length - 1].getNextSiblingID(), null, null, null));
  483. //更新前节点最末子节点
  484. if(firstPreSibling.children.length > 0){
  485. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.children[firstPreSibling.children.length - 1].getID(), selNodes[0].getID(), null, null, null));
  486. }
  487. //更新选中节点
  488. for(let i = 0; i < selNodes.length; i++){
  489. let selNode = selNodes[i];
  490. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(), firstPreSibling.getID(), null, null));
  491. }
  492. if(postData.length > 0){
  493. //ajax
  494. me.sectionTreeAjax(postData, function (rstData) {
  495. for(let selNode of selNodes){
  496. me.controller.setTreeSelected(selNode);
  497. me.controller.downLevel();
  498. }
  499. me.refreshBtn(me.tree.selected);
  500. me.workBook.focus();
  501. });
  502. }
  503. },
  504. upMove: function (selected) {
  505. let me = this;
  506. me.upMoveBtn.addClass('disabled');
  507. let postData = [];
  508. if(!me.isDef(selected)){
  509. return;
  510. }
  511. if(!me.isDef(selected.preSibling)){
  512. return;
  513. }
  514. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  515. postData.push(updateObj);
  516. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  517. postData.push(updatePre);
  518. if(me.isDef(selected.preSibling.preSibling)){
  519. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  520. postData.push(updatePrepre);
  521. }
  522. if(postData.length > 0){
  523. //ajax
  524. me.sectionTreeAjax(postData, function (rstData) {
  525. me.controller.upMove();
  526. me.refreshBtn(me.tree.selected);
  527. me.workBook.focus();
  528. });
  529. }
  530. },
  531. downMove: function (selected) {
  532. let me = this;
  533. me.downMoveBtn.addClass('disabled');
  534. let postData = [];
  535. if(!me.isDef(selected)){
  536. return;
  537. }
  538. if(!me.isDef(selected.nextSibling)){
  539. return;
  540. }
  541. if(me.isDef(selected.preSibling)){
  542. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  543. postData.push(updatePre);
  544. }
  545. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  546. postData.push(updateObj);
  547. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  548. postData.push(updateNext);
  549. if(postData.length > 0){
  550. //ajax
  551. me.sectionTreeAjax(postData, function (rstData) {
  552. me.controller.downMove();
  553. me.refreshBtn(me.tree.selected);
  554. me.workBook.focus();
  555. });
  556. }
  557. },
  558. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  559. let updateObj = Object.create(null);
  560. updateObj.updateType = '';
  561. updateObj.updateData = Object.create(null);
  562. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  563. if(this.isDef(updateType)){
  564. updateObj.updateType = updateType;
  565. }
  566. if(this.isDef(id)){
  567. updateObj.updateData.ID = id;
  568. }
  569. if(this.isDef(nid)){
  570. updateObj.updateData.NextSiblingID = nid;
  571. }
  572. if(this.isDef(pid)){
  573. updateObj.updateData.ParentID = pid;
  574. }
  575. if(this.isDef(name)){
  576. updateObj.updateData.name = name;
  577. }
  578. if(this.isDef(deleted)){
  579. updateObj.updateData.isDeleted = true;
  580. }
  581. return updateObj;
  582. },
  583. sectionTreeAjax: function (postData, scFunc, errFunc) {
  584. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  585. },
  586. initTools: function (node) {
  587. if(this.isDef(node)){
  588. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  589. explanatoryOprObj.showText(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor, node.data.explanation, node.data.ruleText);
  590. //job
  591. jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.ALL;
  592. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
  593. jobContentOprObj.clickUpdate($('#txtareaAll'));
  594. //fz
  595. annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.ALL;
  596. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  597. }
  598. },
  599. //模仿默认点击
  600. initSelection: function (node, doAfterGetRation = null) {
  601. if (node && node.tree){
  602. node.tree.selected = node ? node : null;
  603. }
  604. let me = this;
  605. if(!me.isDef(node)){
  606. sheetCommonObj.cleanSheet(rationOprObj.workBook.getActiveSheet(), rationOprObj.setting, -1);
  607. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  608. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  609. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  610. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  611. return;
  612. }
  613. //me.workBook.getActiveSheet().setActiveCell(node.serialNo(), me.workBook.getActiveSheet().getActiveColumnIndex());
  614. me.initTools(node);
  615. me.refreshBtn(node);
  616. if(!me.isDef(node.children) || node.children.length === 0){
  617. //需要根据章节树下是否含有定额数据判断是否可以删除,在异步获取定额数据前将删除按钮无效化
  618. me.removeBtn.addClass('disabled');
  619. rationOprObj.canRations = true;
  620. rationOprObj.workBook.getSheet(0).clearSelection();
  621. //获取定额后的回调操作:1.正常变更章节树节点,则默认获取定额后定位至首行定额 2.搜索定额后,获取定额后定位至匹配到的定额
  622. if (doAfterGetRation && typeof doAfterGetRation === 'function') {
  623. rationOprObj.doAfterGetRation = doAfterGetRation;
  624. } else {
  625. rationOprObj.doAfterGetRation = function (rations) {
  626. rationOprObj.workBook.getActiveSheet().setActiveCell(0, 0);
  627. rationOprObj.rationSelInit(0, true);
  628. rationOprObj.workBook.getActiveSheet().showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  629. };
  630. }
  631. rationOprObj.getRationItems(node.data.ID, rationOprObj.doAfterGetRation);
  632. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  633. }
  634. else {
  635. rationOprObj.canRations = false;
  636. rationOprObj.currentSectionId = node.data.ID;
  637. rationOprObj.workBook.getSheet(0).setRowCount(30);
  638. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  639. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  640. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  641. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  642. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  643. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  644. rationGLJOprObj.sheet.getParent().focus(false);
  645. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  646. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  647. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  648. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  649. }
  650. me.workBook.focus(true);
  651. },
  652. //根据定额定位至章节树
  653. locateToSection: function (rationCode) {
  654. let me = this;
  655. //去后台搜索该定额
  656. CommonAjax.post('/rationRepository/api/getRationItem', {rationLibId: pageOprObj.rationLibId, code: rationCode}, function (rstData) {
  657. if (!rstData) {
  658. alert(`不存在定额${rationCode}`);
  659. return;
  660. }
  661. //定位至相关章节
  662. let sectionId = rstData.sectionId;
  663. if (!sectionId) {
  664. return;
  665. }
  666. let sectionNode = me.tree.nodes[`id_${sectionId}`];
  667. if (!sectionNode) {
  668. return;
  669. }
  670. let sectionRow = sectionNode.serialNo();
  671. me.sheet.setActiveCell(sectionRow, 1);
  672. me.sheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.top);
  673. let doAfterGetRation = function (rations) {
  674. let findRation = _.find(rations, {code: rationCode}),
  675. rIdx = rations.indexOf(findRation),
  676. rationSheet = rationOprObj.workBook.getActiveSheet();
  677. rationSheet.setActiveCell(rIdx, 0);
  678. rationOprObj.rationSelInit(rIdx, true);
  679. rationOprObj.workBook.getActiveSheet().showRow(rIdx, GC.Spread.Sheets.VerticalPosition.top);
  680. };
  681. me.initSelection(sectionNode, doAfterGetRation);
  682. }, function () {
  683. });
  684. }
  685. };
  686. $(document).ready(function () {
  687. $('#rationSearch').keydown(function (event) {
  688. if(event.keyCode === 13){
  689. $(this).blur();
  690. let rationCode = $(this).val().toUpperCase();
  691. if (rationCode) {
  692. sectionTreeObj.locateToSection(rationCode);
  693. }
  694. }
  695. });
  696. });