section_tree.js 29 KB

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