section_tree.js 29 KB

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