section_tree.js 28 KB

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