section_tree.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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. 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. if (locked) {
  255. return;
  256. }
  257. let me = this;
  258. me.insertBtn.removeClass('disabled');
  259. me.removeBtn.removeClass('disabled');
  260. me.upLevelBtn.removeClass('disabled');
  261. me.downLevelBtn.removeClass('disabled');
  262. me.downMoveBtn.removeClass('disabled');
  263. me.upMoveBtn.removeClass('disabled');
  264. if(!me.isDef(selected)){
  265. me.removeBtn.addClass('disabled');
  266. me.upLevelBtn.addClass('disabled');
  267. me.downLevelBtn.addClass('disabled');
  268. me.downMoveBtn.addClass('disabled');
  269. me.upMoveBtn.addClass('disabled');
  270. }
  271. else {
  272. if(!me.isDef(selected.preSibling)){
  273. me.downLevelBtn.addClass('disabled');
  274. me.upMoveBtn.addClass('disabled');
  275. }
  276. if(!me.isDef(selected.nextSibling)){
  277. me.downMoveBtn.addClass('disabled');
  278. }
  279. if(!me.isDef(selected.parent)){
  280. me.upLevelBtn.addClass('disabled');
  281. }
  282. }
  283. },
  284. bindBtn: function () {
  285. let me = this;
  286. me.insertBtn.click(function () {
  287. me.insert();
  288. });
  289. $('#delConfirm').click(function () {
  290. if(me.canRemoveSection){
  291. me.remove(me.tree.selected);
  292. }
  293. else {
  294. $('#delAlert').modal('hide');
  295. }
  296. });
  297. me.removeBtn.click(function () {
  298. //不可删除有子节点或有定额数据的节点
  299. let section = me.cache[me.workBook.getActiveSheet().getActiveRowIndex()];
  300. if(!section){
  301. return;
  302. }
  303. let sectionName = me.isDef(section.data.name) ? section.data.name : '';
  304. let sectionRations = rationOprObj.currentRations[`_SEC_ID_${section.data.ID}`];
  305. if(section.children.length > 0 || (sectionRations && sectionRations.length > 0)){
  306. me.canRemoveSection = false;
  307. $('#delAlert').find('.modal-body h5').text('当前节点下有数据,不可删除。');
  308. }
  309. else {
  310. me.canRemoveSection = true;
  311. $('#delAlert').find('.modal-body h5').text(`确认要删除章节 “${sectionName}”吗?`);
  312. }
  313. $('#delAlert').modal('show');
  314. });
  315. me.upLevelBtn.click(function () {
  316. me.upLevel(me.tree.selected);
  317. });
  318. me.downLevelBtn.click(function () {
  319. me.downLevel(me.tree.selected);
  320. });
  321. me.downMoveBtn.click(function () {
  322. me.downMove(me.tree.selected);
  323. });
  324. me.upMoveBtn.click(function () {
  325. me.upMove(me.tree.selected);
  326. });
  327. },
  328. insert: function () {
  329. let me = sectionTreeObj;
  330. me.insertBtn.addClass('disabled');
  331. let postData = [];
  332. CommonAjax.post('api/getNewRationTreeID', {}, function (newID) {
  333. if(!me.isDef(newID)){
  334. return;
  335. }
  336. me.tree.maxNodeID(newID - 1);
  337. let selected = me.tree.selected;
  338. let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
  339. if(me.isDef(selected)) {
  340. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
  341. postData.push(updateObj);
  342. insertObj.updateData.ParentID = selected.getParentID();
  343. if(me.isDef(selected.nextSibling)){
  344. insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
  345. }
  346. }
  347. postData.push(insertObj);
  348. if(postData.length > 0){
  349. //ajax
  350. me.sectionTreeAjax(postData, function (rstData) {
  351. me.controller.insert();
  352. me.refreshBtn(me.tree.selected);
  353. //fresh tools
  354. me.initTools(me.tree.selected);
  355. me.workBook.focus();
  356. me.initSelection(me.tree.selected);
  357. });
  358. }
  359. });
  360. },
  361. remove: function (selected) {
  362. let me = this;
  363. me.removeBtn.addClass('disabled');
  364. let postData = [], IDs = [];
  365. if(!selected){
  366. return;
  367. }
  368. getDelIds(selected);
  369. function getDelIds(node){
  370. if(me.isDef(node)){
  371. IDs.push(node.getID());
  372. if(node.children.length > 0){
  373. for(let i = 0, len = node.children.length; i < len; i++){
  374. getDelIds(node.children[i]);
  375. }
  376. }
  377. }
  378. }
  379. if(me.isDef(selected.preSibling)){
  380. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  381. postData.push(updateObj);
  382. }
  383. if(IDs.length > 0){
  384. for(let i = 0, len = IDs.length; i < len; i++){
  385. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  386. postData.push(delObj);
  387. }
  388. }
  389. if(postData.length > 0){
  390. //ajax
  391. me.sectionTreeAjax(postData, function (rstData) {
  392. $('#delAlert').modal('hide');
  393. me.removeRationsCodes(rationOprObj.currentRations["_SEC_ID_" + selected.data.ID]);
  394. me.controller.delete();
  395. me.refreshBtn(me.tree.selected);
  396. me.initTools(me.tree.selected);
  397. me.initSelection(me.tree.selected);
  398. me.workBook.focus();
  399. });
  400. }
  401. },
  402. removeRationsCodes: function (rations) {
  403. for(let ration of rations){
  404. rationOprObj.rationsCodes.splice(rationOprObj.rationsCodes.indexOf(ration.code), 1);
  405. }
  406. },
  407. getSameDepthNodes: function(){
  408. let rst = [];
  409. let sel = this.sheet.getSelections()[0];
  410. let selectedDepth = this.tree.selected.depth();
  411. for(let i = 0; i < sel.rowCount; i++){
  412. let row = sel.row + i;
  413. if(this.cache[row].depth() === selectedDepth){
  414. rst.push(this.cache[row]);
  415. }
  416. }
  417. return rst;
  418. },
  419. upLevel: function (selected) {
  420. let me = this;
  421. me.upLevelBtn.addClass('disabled');
  422. let postData = [];
  423. let selNodes = me.getSameDepthNodes();
  424. if(selNodes.length <= 0){
  425. return ;
  426. }
  427. let firstParent = selNodes[0].parent;
  428. if(!me.isDef(firstParent)){
  429. return;
  430. }
  431. //更新父节点
  432. postData.push(me.getUpdateObj(me.updateType.update, firstParent.getID(), selNodes[0].getID(), null, null, null));
  433. //更新前节点
  434. if(me.isDef(selNodes[0].preSibling)){
  435. postData.push(me.getUpdateObj(me.updateType.update, selNodes[0].preSibling.getID(), -1, null, null, null));
  436. }
  437. //更新选中节点的后兄弟节点
  438. let lastSelNode = selNodes[selNodes.length - 1];
  439. let nextIDs = [];
  440. getNext(lastSelNode);
  441. function getNext(node){
  442. if(me.isDef(node.nextSibling)){
  443. nextIDs.push(node.getNextSiblingID());
  444. getNext(node.nextSibling);
  445. }
  446. }
  447. for(let nextID of nextIDs){
  448. postData.push(me.getUpdateObj(me.updateType.update, nextID, null, lastSelNode.getID(), null, null));
  449. }
  450. //更新选中节点
  451. for(let i = 0; i < selNodes.length; i++){
  452. let selNode = selNodes[i];
  453. let nid = i === selNodes.length - 1 ? firstParent.getNextSiblingID() : selNode.getNextSiblingID();
  454. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), nid, firstParent.getParentID(), null, null));
  455. }
  456. if(postData.length > 0){
  457. //ajax
  458. me.sectionTreeAjax(postData, function (rstData) {
  459. for(let selNode of selNodes){
  460. me.controller.setTreeSelected(selNode);
  461. me.controller.upLevel();
  462. }
  463. me.refreshBtn(me.tree.selected);
  464. me.workBook.focus();
  465. });
  466. }
  467. },
  468. downLevel: function (selected) {
  469. let me = this;
  470. me.downLevelBtn.addClass('disabled');
  471. let postData = [];
  472. let selNodes = me.getSameDepthNodes();
  473. if(selNodes.length <= 0 ){
  474. return;
  475. }
  476. let firstPreSibling = selNodes[0].preSibling;
  477. if(!me.isDef(firstPreSibling)){
  478. return;
  479. }
  480. //更新前节点
  481. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.getID(), selNodes[selNodes.length - 1].getNextSiblingID(), null, null, null));
  482. //更新前节点最末子节点
  483. if(firstPreSibling.children.length > 0){
  484. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.children[firstPreSibling.children.length - 1].getID(), selNodes[0].getID(), null, null, null));
  485. }
  486. //更新选中节点
  487. for(let i = 0; i < selNodes.length; i++){
  488. let selNode = selNodes[i];
  489. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(), firstPreSibling.getID(), null, null));
  490. }
  491. if(postData.length > 0){
  492. //ajax
  493. me.sectionTreeAjax(postData, function (rstData) {
  494. for(let selNode of selNodes){
  495. me.controller.setTreeSelected(selNode);
  496. me.controller.downLevel();
  497. }
  498. me.refreshBtn(me.tree.selected);
  499. me.workBook.focus();
  500. });
  501. }
  502. },
  503. upMove: function (selected) {
  504. let me = this;
  505. me.upMoveBtn.addClass('disabled');
  506. let postData = [];
  507. if(!me.isDef(selected)){
  508. return;
  509. }
  510. if(!me.isDef(selected.preSibling)){
  511. return;
  512. }
  513. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  514. postData.push(updateObj);
  515. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  516. postData.push(updatePre);
  517. if(me.isDef(selected.preSibling.preSibling)){
  518. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  519. postData.push(updatePrepre);
  520. }
  521. if(postData.length > 0){
  522. //ajax
  523. me.sectionTreeAjax(postData, function (rstData) {
  524. me.controller.upMove();
  525. me.refreshBtn(me.tree.selected);
  526. me.workBook.focus();
  527. });
  528. }
  529. },
  530. downMove: function (selected) {
  531. let me = this;
  532. me.downMoveBtn.addClass('disabled');
  533. let postData = [];
  534. if(!me.isDef(selected)){
  535. return;
  536. }
  537. if(!me.isDef(selected.nextSibling)){
  538. return;
  539. }
  540. if(me.isDef(selected.preSibling)){
  541. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  542. postData.push(updatePre);
  543. }
  544. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  545. postData.push(updateObj);
  546. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  547. postData.push(updateNext);
  548. if(postData.length > 0){
  549. //ajax
  550. me.sectionTreeAjax(postData, function (rstData) {
  551. me.controller.downMove();
  552. me.refreshBtn(me.tree.selected);
  553. me.workBook.focus();
  554. });
  555. }
  556. },
  557. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  558. let updateObj = Object.create(null);
  559. updateObj.updateType = '';
  560. updateObj.updateData = Object.create(null);
  561. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  562. if(this.isDef(updateType)){
  563. updateObj.updateType = updateType;
  564. }
  565. if(this.isDef(id)){
  566. updateObj.updateData.ID = id;
  567. }
  568. if(this.isDef(nid)){
  569. updateObj.updateData.NextSiblingID = nid;
  570. }
  571. if(this.isDef(pid)){
  572. updateObj.updateData.ParentID = pid;
  573. }
  574. if(this.isDef(name)){
  575. updateObj.updateData.name = name;
  576. }
  577. if(this.isDef(deleted)){
  578. updateObj.updateData.isDeleted = true;
  579. }
  580. return updateObj;
  581. },
  582. sectionTreeAjax: function (postData, scFunc, errFunc) {
  583. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  584. },
  585. initTools: function (node) {
  586. if(this.isDef(node)){
  587. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  588. //explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
  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. const me = this;
  655. const $seach = $('#rationSearch');
  656. $seach.val(rationCode);
  657. //去后台搜索该定额
  658. $.bootstrapLoading.start();
  659. CommonAjax.post('/rationRepository/api/getRationItem', {rationLibId: pageOprObj.rationLibId, code: rationCode}, function (rstData) {
  660. if (!rstData) {
  661. alert(`不存在定额${rationCode}`);
  662. $.bootstrapLoading.end();
  663. return;
  664. }
  665. //定位至相关章节
  666. let sectionId = rstData.sectionId;
  667. if (!sectionId) {
  668. $.bootstrapLoading.end();
  669. return;
  670. }
  671. let sectionNode = me.tree.nodes[`id_${sectionId}`];
  672. if (!sectionNode) {
  673. $.bootstrapLoading.end();
  674. return;
  675. }
  676. let sectionRow = sectionNode.serialNo();
  677. me.sheet.setActiveCell(sectionRow, 1);
  678. me.sheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.top);
  679. $.bootstrapLoading.end();
  680. let doAfterGetRation = function (rations) {
  681. let findRation = _.find(rations, {code: rationCode}),
  682. rIdx = rations.indexOf(findRation),
  683. rationSheet = rationOprObj.workBook.getActiveSheet();
  684. rationSheet.setActiveCell(rIdx, 0);
  685. rationOprObj.rationSelInit(rIdx, true);
  686. rationOprObj.workBook.getActiveSheet().showRow(rIdx, GC.Spread.Sheets.VerticalPosition.top);
  687. };
  688. me.initSelection(sectionNode, doAfterGetRation);
  689. }, function () {
  690. $.bootstrapLoading.end();
  691. });
  692. }
  693. };
  694. $(document).ready(function () {
  695. $('#rationSearch').keydown(function (event) {
  696. if(event.keyCode === 13){
  697. $(this).blur();
  698. let rationCode = $(this).val().toUpperCase();
  699. if (rationCode) {
  700. sectionTreeObj.locateToSection(rationCode);
  701. }
  702. }
  703. });
  704. });