section_tree.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. if (hash) {
  240. const rationCode = hash.replace('#', '');
  241. this.locateToSection(rationCode);
  242. }
  243. },
  244. initTree: function (datas) {
  245. this.tree = idTree.createNew(this.setting.tree);
  246. this.tree.loadDatas(datas);
  247. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  248. },
  249. initController: function (tree, sheet, setting) {
  250. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  251. },
  252. refreshBtn: function (selected) {
  253. if (locked) {
  254. return;
  255. }
  256. let me = this;
  257. me.insertBtn.removeClass('disabled');
  258. me.removeBtn.removeClass('disabled');
  259. me.upLevelBtn.removeClass('disabled');
  260. me.downLevelBtn.removeClass('disabled');
  261. me.downMoveBtn.removeClass('disabled');
  262. me.upMoveBtn.removeClass('disabled');
  263. if(!me.isDef(selected)){
  264. me.removeBtn.addClass('disabled');
  265. me.upLevelBtn.addClass('disabled');
  266. me.downLevelBtn.addClass('disabled');
  267. me.downMoveBtn.addClass('disabled');
  268. me.upMoveBtn.addClass('disabled');
  269. }
  270. else {
  271. if(!me.isDef(selected.preSibling)){
  272. me.downLevelBtn.addClass('disabled');
  273. me.upMoveBtn.addClass('disabled');
  274. }
  275. if(!me.isDef(selected.nextSibling)){
  276. me.downMoveBtn.addClass('disabled');
  277. }
  278. if(!me.isDef(selected.parent)){
  279. me.upLevelBtn.addClass('disabled');
  280. }
  281. }
  282. },
  283. bindBtn: function () {
  284. let me = this;
  285. me.insertBtn.click(function () {
  286. me.insert();
  287. });
  288. $('#delConfirm').click(function () {
  289. if(me.canRemoveSection){
  290. me.remove(me.tree.selected);
  291. }
  292. else {
  293. $('#delAlert').modal('hide');
  294. }
  295. });
  296. me.removeBtn.click(function () {
  297. //不可删除有子节点或有定额数据的节点
  298. let section = me.cache[me.workBook.getActiveSheet().getActiveRowIndex()];
  299. if(!section){
  300. return;
  301. }
  302. let sectionName = me.isDef(section.data.name) ? section.data.name : '';
  303. let sectionRations = rationOprObj.currentRations[`_SEC_ID_${section.data.ID}`];
  304. if(section.children.length > 0 || (sectionRations && sectionRations.length > 0)){
  305. me.canRemoveSection = false;
  306. $('#delAlert').find('.modal-body h5').text('当前节点下有数据,不可删除。');
  307. }
  308. else {
  309. me.canRemoveSection = true;
  310. $('#delAlert').find('.modal-body h5').text(`确认要删除章节 “${sectionName}”吗?`);
  311. }
  312. $('#delAlert').modal('show');
  313. });
  314. me.upLevelBtn.click(function () {
  315. me.upLevel(me.tree.selected);
  316. });
  317. me.downLevelBtn.click(function () {
  318. me.downLevel(me.tree.selected);
  319. });
  320. me.downMoveBtn.click(function () {
  321. me.downMove(me.tree.selected);
  322. });
  323. me.upMoveBtn.click(function () {
  324. me.upMove(me.tree.selected);
  325. });
  326. },
  327. insert: function () {
  328. let me = sectionTreeObj;
  329. me.insertBtn.addClass('disabled');
  330. let postData = [];
  331. CommonAjax.post('api/getNewRationTreeID', {}, function (newID) {
  332. if(!me.isDef(newID)){
  333. return;
  334. }
  335. me.tree.maxNodeID(newID - 1);
  336. let selected = me.tree.selected;
  337. let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
  338. if(me.isDef(selected)) {
  339. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
  340. postData.push(updateObj);
  341. insertObj.updateData.ParentID = selected.getParentID();
  342. if(me.isDef(selected.nextSibling)){
  343. insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
  344. }
  345. }
  346. postData.push(insertObj);
  347. if(postData.length > 0){
  348. //ajax
  349. me.sectionTreeAjax(postData, function (rstData) {
  350. me.controller.insert();
  351. me.refreshBtn(me.tree.selected);
  352. //fresh tools
  353. me.initTools(me.tree.selected);
  354. me.workBook.focus();
  355. me.initSelection(me.tree.selected);
  356. });
  357. }
  358. });
  359. },
  360. remove: function (selected) {
  361. let me = this;
  362. me.removeBtn.addClass('disabled');
  363. let postData = [], IDs = [];
  364. if(!selected){
  365. return;
  366. }
  367. getDelIds(selected);
  368. function getDelIds(node){
  369. if(me.isDef(node)){
  370. IDs.push(node.getID());
  371. if(node.children.length > 0){
  372. for(let i = 0, len = node.children.length; i < len; i++){
  373. getDelIds(node.children[i]);
  374. }
  375. }
  376. }
  377. }
  378. if(me.isDef(selected.preSibling)){
  379. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  380. postData.push(updateObj);
  381. }
  382. if(IDs.length > 0){
  383. for(let i = 0, len = IDs.length; i < len; i++){
  384. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  385. postData.push(delObj);
  386. }
  387. }
  388. if(postData.length > 0){
  389. //ajax
  390. me.sectionTreeAjax(postData, function (rstData) {
  391. $('#delAlert').modal('hide');
  392. me.removeRationsCodes(rationOprObj.currentRations["_SEC_ID_" + selected.data.ID]);
  393. me.controller.delete();
  394. me.refreshBtn(me.tree.selected);
  395. me.initTools(me.tree.selected);
  396. me.initSelection(me.tree.selected);
  397. me.workBook.focus();
  398. });
  399. }
  400. },
  401. removeRationsCodes: function (rations) {
  402. for(let ration of rations){
  403. rationOprObj.rationsCodes.splice(rationOprObj.rationsCodes.indexOf(ration.code), 1);
  404. }
  405. },
  406. getSameDepthNodes: function(){
  407. let rst = [];
  408. let sel = this.sheet.getSelections()[0];
  409. let selectedDepth = this.tree.selected.depth();
  410. for(let i = 0; i < sel.rowCount; i++){
  411. let row = sel.row + i;
  412. if(this.cache[row].depth() === selectedDepth){
  413. rst.push(this.cache[row]);
  414. }
  415. }
  416. return rst;
  417. },
  418. upLevel: function (selected) {
  419. let me = this;
  420. me.upLevelBtn.addClass('disabled');
  421. let postData = [];
  422. let selNodes = me.getSameDepthNodes();
  423. if(selNodes.length <= 0){
  424. return ;
  425. }
  426. let firstParent = selNodes[0].parent;
  427. if(!me.isDef(firstParent)){
  428. return;
  429. }
  430. //更新父节点
  431. postData.push(me.getUpdateObj(me.updateType.update, firstParent.getID(), selNodes[0].getID(), null, null, null));
  432. //更新前节点
  433. if(me.isDef(selNodes[0].preSibling)){
  434. postData.push(me.getUpdateObj(me.updateType.update, selNodes[0].preSibling.getID(), -1, null, null, null));
  435. }
  436. //更新选中节点的后兄弟节点
  437. let lastSelNode = selNodes[selNodes.length - 1];
  438. let nextIDs = [];
  439. getNext(lastSelNode);
  440. function getNext(node){
  441. if(me.isDef(node.nextSibling)){
  442. nextIDs.push(node.getNextSiblingID());
  443. getNext(node.nextSibling);
  444. }
  445. }
  446. for(let nextID of nextIDs){
  447. postData.push(me.getUpdateObj(me.updateType.update, nextID, null, lastSelNode.getID(), null, null));
  448. }
  449. //更新选中节点
  450. for(let i = 0; i < selNodes.length; i++){
  451. let selNode = selNodes[i];
  452. let nid = i === selNodes.length - 1 ? firstParent.getNextSiblingID() : selNode.getNextSiblingID();
  453. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), nid, firstParent.getParentID(), null, null));
  454. }
  455. if(postData.length > 0){
  456. //ajax
  457. me.sectionTreeAjax(postData, function (rstData) {
  458. for(let selNode of selNodes){
  459. me.controller.setTreeSelected(selNode);
  460. me.controller.upLevel();
  461. }
  462. me.refreshBtn(me.tree.selected);
  463. me.workBook.focus();
  464. });
  465. }
  466. },
  467. downLevel: function (selected) {
  468. let me = this;
  469. me.downLevelBtn.addClass('disabled');
  470. let postData = [];
  471. let selNodes = me.getSameDepthNodes();
  472. if(selNodes.length <= 0 ){
  473. return;
  474. }
  475. let firstPreSibling = selNodes[0].preSibling;
  476. if(!me.isDef(firstPreSibling)){
  477. return;
  478. }
  479. //更新前节点
  480. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.getID(), selNodes[selNodes.length - 1].getNextSiblingID(), null, null, null));
  481. //更新前节点最末子节点
  482. if(firstPreSibling.children.length > 0){
  483. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.children[firstPreSibling.children.length - 1].getID(), selNodes[0].getID(), null, null, null));
  484. }
  485. //更新选中节点
  486. for(let i = 0; i < selNodes.length; i++){
  487. let selNode = selNodes[i];
  488. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(), firstPreSibling.getID(), null, null));
  489. }
  490. if(postData.length > 0){
  491. //ajax
  492. me.sectionTreeAjax(postData, function (rstData) {
  493. for(let selNode of selNodes){
  494. me.controller.setTreeSelected(selNode);
  495. me.controller.downLevel();
  496. }
  497. me.refreshBtn(me.tree.selected);
  498. me.workBook.focus();
  499. });
  500. }
  501. },
  502. upMove: function (selected) {
  503. let me = this;
  504. me.upMoveBtn.addClass('disabled');
  505. let postData = [];
  506. if(!me.isDef(selected)){
  507. return;
  508. }
  509. if(!me.isDef(selected.preSibling)){
  510. return;
  511. }
  512. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  513. postData.push(updateObj);
  514. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  515. postData.push(updatePre);
  516. if(me.isDef(selected.preSibling.preSibling)){
  517. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  518. postData.push(updatePrepre);
  519. }
  520. if(postData.length > 0){
  521. //ajax
  522. me.sectionTreeAjax(postData, function (rstData) {
  523. me.controller.upMove();
  524. me.refreshBtn(me.tree.selected);
  525. me.workBook.focus();
  526. });
  527. }
  528. },
  529. downMove: function (selected) {
  530. let me = this;
  531. me.downMoveBtn.addClass('disabled');
  532. let postData = [];
  533. if(!me.isDef(selected)){
  534. return;
  535. }
  536. if(!me.isDef(selected.nextSibling)){
  537. return;
  538. }
  539. if(me.isDef(selected.preSibling)){
  540. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  541. postData.push(updatePre);
  542. }
  543. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  544. postData.push(updateObj);
  545. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  546. postData.push(updateNext);
  547. if(postData.length > 0){
  548. //ajax
  549. me.sectionTreeAjax(postData, function (rstData) {
  550. me.controller.downMove();
  551. me.refreshBtn(me.tree.selected);
  552. me.workBook.focus();
  553. });
  554. }
  555. },
  556. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  557. let updateObj = Object.create(null);
  558. updateObj.updateType = '';
  559. updateObj.updateData = Object.create(null);
  560. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  561. if(this.isDef(updateType)){
  562. updateObj.updateType = updateType;
  563. }
  564. if(this.isDef(id)){
  565. updateObj.updateData.ID = id;
  566. }
  567. if(this.isDef(nid)){
  568. updateObj.updateData.NextSiblingID = nid;
  569. }
  570. if(this.isDef(pid)){
  571. updateObj.updateData.ParentID = pid;
  572. }
  573. if(this.isDef(name)){
  574. updateObj.updateData.name = name;
  575. }
  576. if(this.isDef(deleted)){
  577. updateObj.updateData.isDeleted = true;
  578. }
  579. return updateObj;
  580. },
  581. sectionTreeAjax: function (postData, scFunc, errFunc) {
  582. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  583. },
  584. initTools: function (node) {
  585. if(this.isDef(node)){
  586. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  587. explanatoryOprObj.showText(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor, node.data.explanation, node.data.ruleText);
  588. //job
  589. jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.ALL;
  590. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
  591. jobContentOprObj.clickUpdate($('#txtareaAll'));
  592. //fz
  593. annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.ALL;
  594. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  595. }
  596. },
  597. //模仿默认点击
  598. initSelection: function (node, doAfterGetRation = null) {
  599. if (node && node.tree){
  600. node.tree.selected = node ? node : null;
  601. }
  602. let me = this;
  603. if(!me.isDef(node)){
  604. sheetCommonObj.cleanSheet(rationOprObj.workBook.getActiveSheet(), rationOprObj.setting, -1);
  605. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  606. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  607. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  608. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  609. return;
  610. }
  611. //me.workBook.getActiveSheet().setActiveCell(node.serialNo(), me.workBook.getActiveSheet().getActiveColumnIndex());
  612. me.initTools(node);
  613. me.refreshBtn(node);
  614. if(!me.isDef(node.children) || node.children.length === 0){
  615. //需要根据章节树下是否含有定额数据判断是否可以删除,在异步获取定额数据前将删除按钮无效化
  616. me.removeBtn.addClass('disabled');
  617. rationOprObj.canRations = true;
  618. rationOprObj.workBook.getSheet(0).clearSelection();
  619. //获取定额后的回调操作:1.正常变更章节树节点,则默认获取定额后定位至首行定额 2.搜索定额后,获取定额后定位至匹配到的定额
  620. if (doAfterGetRation && typeof doAfterGetRation === 'function') {
  621. rationOprObj.doAfterGetRation = doAfterGetRation;
  622. } else {
  623. rationOprObj.doAfterGetRation = function (rations) {
  624. rationOprObj.workBook.getActiveSheet().setActiveCell(0, 0);
  625. rationOprObj.rationSelInit(0, true);
  626. rationOprObj.workBook.getActiveSheet().showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  627. };
  628. }
  629. rationOprObj.getRationItems(node.data.ID, rationOprObj.doAfterGetRation);
  630. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  631. }
  632. else {
  633. rationOprObj.canRations = false;
  634. rationOprObj.currentSectionId = node.data.ID;
  635. rationOprObj.workBook.getSheet(0).setRowCount(30);
  636. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  637. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  638. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  639. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  640. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  641. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  642. rationGLJOprObj.sheet.getParent().focus(false);
  643. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  644. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  645. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  646. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  647. }
  648. me.workBook.focus(true);
  649. },
  650. //根据定额定位至章节树
  651. locateToSection: function (rationCode) {
  652. const me = this;
  653. const $seach = $('#rationSearch');
  654. $seach.val(rationCode);
  655. //去后台搜索该定额
  656. $.bootstrapLoading.start();
  657. CommonAjax.post('/rationRepository/api/getRationItem', {rationLibId: pageOprObj.rationLibId, code: rationCode}, function (rstData) {
  658. if (!rstData) {
  659. alert(`不存在定额${rationCode}`);
  660. $.bootstrapLoading.end();
  661. return;
  662. }
  663. //定位至相关章节
  664. const sectionId = rstData.sectionId;
  665. if (!sectionId) {
  666. $.bootstrapLoading.end();
  667. return;
  668. }
  669. const sectionNode = me.tree.nodes[`id_${sectionId}`];
  670. if (!sectionNode) {
  671. $.bootstrapLoading.end();
  672. return;
  673. }
  674. const sectionRow = sectionNode.serialNo();
  675. me.sheet.setActiveCell(sectionRow, 1);
  676. me.sheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.top);
  677. $.bootstrapLoading.end();
  678. const doAfterGetRation = function (rations) {
  679. const findRation = _.find(rations, {code: rationCode});
  680. const rIdx = rations.indexOf(findRation);
  681. const rationSheet = rationOprObj.workBook.getActiveSheet();
  682. rationSheet.setActiveCell(rIdx, 0);
  683. rationOprObj.rationSelInit(rIdx, true);
  684. rationOprObj.workBook.getActiveSheet().showRow(rIdx, GC.Spread.Sheets.VerticalPosition.top);
  685. };
  686. me.initSelection(sectionNode, doAfterGetRation);
  687. }, function () {
  688. $.bootstrapLoading.end();
  689. });
  690. }
  691. };
  692. $(document).ready(function () {
  693. $('#rationSearch').keydown(function (event) {
  694. if(event.keyCode === 13){
  695. $(this).blur();
  696. let rationCode = $(this).val().toUpperCase();
  697. if (rationCode) {
  698. sectionTreeObj.locateToSection(rationCode);
  699. }
  700. }
  701. });
  702. });