section_tree.js 29 KB

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