section_tree.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. this.buildContextMenu();
  135. }
  136. },
  137. bindEvents: function (sheet) {
  138. let me = sectionTreeObj;
  139. const Events = GC.Spread.Sheets.Events;
  140. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  141. sheet.bind(Events.EditStarting, me.onEditStarting);
  142. sheet.bind(Events.EditEnded, me.onEditEnded);
  143. sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);
  144. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  145. },
  146. onSelectionChanged: function (sender, info) {
  147. let me = sectionTreeObj;
  148. let row = info.newSelections[0].row;
  149. let section = me.cache[row];
  150. me.initSelection(section);
  151. },
  152. onEditStarting: function (sender, args) {
  153. let me = sectionTreeObj;
  154. let dataCode = me.setting.sheet.cols[args.col]['data']['field'];
  155. if(dataCode === 'ID'){
  156. args.cancel = true;
  157. }
  158. },
  159. onEditEnded: function (sender, args) {
  160. let me = sectionTreeObj;
  161. let postData = [];
  162. let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : '';
  163. let node = me.cache[args.row];
  164. if(me.isDef(node) && node.data.name !== v){
  165. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, v, null);
  166. postData.push(updateObj);
  167. //ajax
  168. //update
  169. me.sectionTreeAjax(postData, function (rstData) {
  170. node.data.name = v;
  171. }, function () {
  172. args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : '');
  173. });
  174. }
  175. },
  176. onClipboardPasting: function (sender, info) {
  177. let me = sectionTreeObj;
  178. if(info.cellRange.col === 0){
  179. info.cancel = true;
  180. }
  181. },
  182. onClipboardPasted: function (sender, info) {
  183. let me = sectionTreeObj;
  184. let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'ID'}, {dataCode: 'name'}]}, info);
  185. let postData = [];
  186. let frontData = [];
  187. for(let i = 0, len = items.length; i < len; i++){
  188. let row = info.cellRange.row + i;
  189. let node = me.cache[row];
  190. if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){
  191. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, items[i].name, null);
  192. postData.push(updateObj);
  193. frontData.push({row: row, name: items[i].name});
  194. node.data.name = items[i].name;
  195. }
  196. }
  197. if(postData.length > 0){
  198. //ajax
  199. me.sectionTreeAjax(postData, function (rstData) {
  200. for(let i = 0, len = frontData.length; i < len; i++){
  201. let node = me.cache[frontData[i]['row']];
  202. if(me.isDef(node)){
  203. node.data.name = frontData[i]['name'];
  204. }
  205. }
  206. }, function () {
  207. for(let i = 0, len = frontData.length; i < len; i++){
  208. let node = me.cache[frontData[i]['row']];
  209. me.sheet.setValue(frontData[i]['row'], 1, me.isDef(node) ? node.data.name : '');
  210. }
  211. });
  212. }
  213. },
  214. loadRateWidth: function () {
  215. if (this.workBook) {
  216. //ID列固定40宽度
  217. let spreadWidth = $('#sectionSpread').width() - 65; //65: 列头宽度和垂直滚动条宽度和
  218. let IDRate = 40 / spreadWidth,
  219. nameRate = 1 - IDRate;
  220. sheetCommonObj.setColumnWidthByRate($('#sectionSpread').width() - 65, this.workBook, [{rateWidth: IDRate}, {rateWidth: nameRate}]);
  221. }
  222. },
  223. buildContextMenu: function () {//右键菜单
  224. const me = this;
  225. $.contextMenu({
  226. selector: '#sectionSpread',
  227. build: function($triggerElement, e){
  228. //控制允许右键菜单在哪个位置出现
  229. const target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  230. const sheet = me.workBook.getSheet(0);
  231. if (target.hitTestType === 3) {
  232. if (typeof target.row !== 'undefined') {
  233. const section = me.cache[target.row];
  234. me.initSelection(section);
  235. }
  236. return {
  237. callback: function(){},
  238. items: {
  239. "setManage": {
  240. name: "设置管理费率",
  241. disabled: function () {
  242. const section = me.cache[target.row];
  243. return locked || !section;
  244. },
  245. icon: "fa-pencil-square-o",
  246. callback: function (key, opt) {
  247. $('#set-rate-dialog').modal('show');
  248. }
  249. }
  250. }
  251. };
  252. }
  253. }
  254. });
  255. },
  256. // 获取章节节点的叶子章节列表ID(自身及后代)
  257. getSectionLeafList: function (section) {
  258. if (!section) {
  259. return [];
  260. }
  261. const posterity = section.getPosterity();
  262. const allSections = [section, ...posterity];
  263. return allSections
  264. .filter(section => !section.children.length)
  265. .map(section => section.data.ID);
  266. },
  267. initSectionTree: function (sectionTree) {
  268. //init
  269. this.buildSheet();
  270. this.initTree(sectionTree);
  271. this.cache = this.tree.items;
  272. this.bindBtn();
  273. this.initController(this.tree, this.sheet, this.setting.sheet);
  274. this.controller.showTreeData();
  275. this.sheet.setFormatter(-1, 0, '@');
  276. this.initSelection(this.tree.selected);
  277. explanatoryOprObj.bindEvents(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor);
  278. this.loadRateWidth();
  279. this.autoLocate();
  280. },
  281. //自动定位
  282. autoLocate: function () {
  283. const hash = window.location.hash;
  284. const $searchInput = $('#rationSearch');
  285. if (hash) {
  286. const rationCode = hash.replace('#', '');
  287. this.locateToSection(rationCode);
  288. }
  289. },
  290. initTree: function (datas) {
  291. this.tree = idTree.createNew(this.setting.tree);
  292. this.tree.loadDatas(datas);
  293. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  294. },
  295. initController: function (tree, sheet, setting) {
  296. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  297. },
  298. refreshBtn: function (selected) {
  299. if (locked) {
  300. return;
  301. }
  302. let me = this;
  303. me.insertBtn.removeClass('disabled');
  304. me.removeBtn.removeClass('disabled');
  305. me.upLevelBtn.removeClass('disabled');
  306. me.downLevelBtn.removeClass('disabled');
  307. me.downMoveBtn.removeClass('disabled');
  308. me.upMoveBtn.removeClass('disabled');
  309. if(!me.isDef(selected)){
  310. me.removeBtn.addClass('disabled');
  311. me.upLevelBtn.addClass('disabled');
  312. me.downLevelBtn.addClass('disabled');
  313. me.downMoveBtn.addClass('disabled');
  314. me.upMoveBtn.addClass('disabled');
  315. }
  316. else {
  317. if(!me.isDef(selected.preSibling)){
  318. me.downLevelBtn.addClass('disabled');
  319. me.upMoveBtn.addClass('disabled');
  320. }
  321. if(!me.isDef(selected.nextSibling)){
  322. me.downMoveBtn.addClass('disabled');
  323. }
  324. if(!me.isDef(selected.parent)){
  325. me.upLevelBtn.addClass('disabled');
  326. }
  327. }
  328. },
  329. bindBtn: function () {
  330. let me = this;
  331. me.insertBtn.click(function () {
  332. me.insert();
  333. });
  334. $('#delConfirm').click(function () {
  335. if(me.canRemoveSection){
  336. me.remove(me.tree.selected);
  337. }
  338. else {
  339. $('#delAlert').modal('hide');
  340. }
  341. });
  342. me.removeBtn.click(function () {
  343. //不可删除有子节点或有定额数据的节点
  344. let section = me.cache[me.workBook.getActiveSheet().getActiveRowIndex()];
  345. if(!section){
  346. return;
  347. }
  348. let sectionName = me.isDef(section.data.name) ? section.data.name : '';
  349. let sectionRations = rationOprObj.currentRations[`_SEC_ID_${section.data.ID}`];
  350. if(section.children.length > 0 || (sectionRations && sectionRations.length > 0)){
  351. me.canRemoveSection = false;
  352. $('#delAlert').find('.modal-body h5').text('当前节点下有数据,不可删除。');
  353. }
  354. else {
  355. me.canRemoveSection = true;
  356. $('#delAlert').find('.modal-body h5').text(`确认要删除章节 “${sectionName}”吗?`);
  357. }
  358. $('#delAlert').modal('show');
  359. });
  360. me.upLevelBtn.click(function () {
  361. me.upLevel(me.tree.selected);
  362. });
  363. me.downLevelBtn.click(function () {
  364. me.downLevel(me.tree.selected);
  365. });
  366. me.downMoveBtn.click(function () {
  367. me.downMove(me.tree.selected);
  368. });
  369. me.upMoveBtn.click(function () {
  370. me.upMove(me.tree.selected);
  371. });
  372. // 设置管理费费率,设置给其下所有定额
  373. $('#set-rate-confirm').click(function () {
  374. $.bootstrapLoading.start();
  375. const rate = $('#manage-fee-rate').val();
  376. const section = me.tree.selected;
  377. const sectionList = me.getSectionLeafList(section);
  378. const postData = {
  379. rationRepId: pageOprObj.rationLibId,
  380. sectionList,
  381. updateData: { manageFeeRate: rate }
  382. };
  383. $('#manage-fee-rate').val('');
  384. CommonAjax.post('/rationRepository/api/updateRationBySection', postData, function () {
  385. me.initSelection(section);
  386. $.bootstrapLoading.end();
  387. }, function () {
  388. $.bootstrapLoading.end();
  389. });
  390. });
  391. },
  392. insert: function () {
  393. let me = sectionTreeObj;
  394. me.insertBtn.addClass('disabled');
  395. let postData = [];
  396. CommonAjax.post('api/getNewRationTreeID', {}, function (newID) {
  397. if(!me.isDef(newID)){
  398. return;
  399. }
  400. me.tree.maxNodeID(newID - 1);
  401. let selected = me.tree.selected;
  402. let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
  403. if(me.isDef(selected)) {
  404. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
  405. postData.push(updateObj);
  406. insertObj.updateData.ParentID = selected.getParentID();
  407. if(me.isDef(selected.nextSibling)){
  408. insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
  409. }
  410. }
  411. postData.push(insertObj);
  412. if(postData.length > 0){
  413. //ajax
  414. me.sectionTreeAjax(postData, function (rstData) {
  415. me.controller.insert();
  416. me.refreshBtn(me.tree.selected);
  417. //fresh tools
  418. me.initTools(me.tree.selected);
  419. me.workBook.focus();
  420. me.initSelection(me.tree.selected);
  421. });
  422. }
  423. });
  424. },
  425. remove: function (selected) {
  426. let me = this;
  427. me.removeBtn.addClass('disabled');
  428. let postData = [], IDs = [];
  429. if(!selected){
  430. return;
  431. }
  432. getDelIds(selected);
  433. function getDelIds(node){
  434. if(me.isDef(node)){
  435. IDs.push(node.getID());
  436. if(node.children.length > 0){
  437. for(let i = 0, len = node.children.length; i < len; i++){
  438. getDelIds(node.children[i]);
  439. }
  440. }
  441. }
  442. }
  443. if(me.isDef(selected.preSibling)){
  444. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  445. postData.push(updateObj);
  446. }
  447. if(IDs.length > 0){
  448. for(let i = 0, len = IDs.length; i < len; i++){
  449. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  450. postData.push(delObj);
  451. }
  452. }
  453. if(postData.length > 0){
  454. //ajax
  455. me.sectionTreeAjax(postData, function (rstData) {
  456. $('#delAlert').modal('hide');
  457. me.removeRationsCodes(rationOprObj.currentRations["_SEC_ID_" + selected.data.ID]);
  458. me.controller.delete();
  459. me.refreshBtn(me.tree.selected);
  460. me.initTools(me.tree.selected);
  461. me.initSelection(me.tree.selected);
  462. me.workBook.focus();
  463. });
  464. }
  465. },
  466. removeRationsCodes: function (rations) {
  467. for(let ration of rations){
  468. rationOprObj.rationsCodes.splice(rationOprObj.rationsCodes.indexOf(ration.code), 1);
  469. }
  470. },
  471. getSameDepthNodes: function(){
  472. let rst = [];
  473. let sel = this.sheet.getSelections()[0];
  474. let selectedDepth = this.tree.selected.depth();
  475. for(let i = 0; i < sel.rowCount; i++){
  476. let row = sel.row + i;
  477. if(this.cache[row].depth() === selectedDepth){
  478. rst.push(this.cache[row]);
  479. }
  480. }
  481. return rst;
  482. },
  483. upLevel: function (selected) {
  484. let me = this;
  485. me.upLevelBtn.addClass('disabled');
  486. let postData = [];
  487. let selNodes = me.getSameDepthNodes();
  488. if(selNodes.length <= 0){
  489. return ;
  490. }
  491. let firstParent = selNodes[0].parent;
  492. if(!me.isDef(firstParent)){
  493. return;
  494. }
  495. //更新父节点
  496. postData.push(me.getUpdateObj(me.updateType.update, firstParent.getID(), selNodes[0].getID(), null, null, null));
  497. //更新前节点
  498. if(me.isDef(selNodes[0].preSibling)){
  499. postData.push(me.getUpdateObj(me.updateType.update, selNodes[0].preSibling.getID(), -1, null, null, null));
  500. }
  501. //更新选中节点的后兄弟节点
  502. let lastSelNode = selNodes[selNodes.length - 1];
  503. let nextIDs = [];
  504. getNext(lastSelNode);
  505. function getNext(node){
  506. if(me.isDef(node.nextSibling)){
  507. nextIDs.push(node.getNextSiblingID());
  508. getNext(node.nextSibling);
  509. }
  510. }
  511. for(let nextID of nextIDs){
  512. postData.push(me.getUpdateObj(me.updateType.update, nextID, null, lastSelNode.getID(), null, null));
  513. }
  514. //更新选中节点
  515. for(let i = 0; i < selNodes.length; i++){
  516. let selNode = selNodes[i];
  517. let nid = i === selNodes.length - 1 ? firstParent.getNextSiblingID() : selNode.getNextSiblingID();
  518. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), nid, firstParent.getParentID(), null, null));
  519. }
  520. if(postData.length > 0){
  521. //ajax
  522. me.sectionTreeAjax(postData, function (rstData) {
  523. for(let selNode of selNodes){
  524. me.controller.setTreeSelected(selNode);
  525. me.controller.upLevel();
  526. }
  527. me.refreshBtn(me.tree.selected);
  528. me.workBook.focus();
  529. });
  530. }
  531. },
  532. downLevel: function (selected) {
  533. let me = this;
  534. me.downLevelBtn.addClass('disabled');
  535. let postData = [];
  536. let selNodes = me.getSameDepthNodes();
  537. if(selNodes.length <= 0 ){
  538. return;
  539. }
  540. let firstPreSibling = selNodes[0].preSibling;
  541. if(!me.isDef(firstPreSibling)){
  542. return;
  543. }
  544. //更新前节点
  545. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.getID(), selNodes[selNodes.length - 1].getNextSiblingID(), null, null, null));
  546. //更新前节点最末子节点
  547. if(firstPreSibling.children.length > 0){
  548. postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.children[firstPreSibling.children.length - 1].getID(), selNodes[0].getID(), null, null, null));
  549. }
  550. //更新选中节点
  551. for(let i = 0; i < selNodes.length; i++){
  552. let selNode = selNodes[i];
  553. postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(), firstPreSibling.getID(), null, null));
  554. }
  555. if(postData.length > 0){
  556. //ajax
  557. me.sectionTreeAjax(postData, function (rstData) {
  558. for(let selNode of selNodes){
  559. me.controller.setTreeSelected(selNode);
  560. me.controller.downLevel();
  561. }
  562. me.refreshBtn(me.tree.selected);
  563. me.workBook.focus();
  564. });
  565. }
  566. },
  567. upMove: function (selected) {
  568. let me = this;
  569. me.upMoveBtn.addClass('disabled');
  570. let postData = [];
  571. if(!me.isDef(selected)){
  572. return;
  573. }
  574. if(!me.isDef(selected.preSibling)){
  575. return;
  576. }
  577. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  578. postData.push(updateObj);
  579. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  580. postData.push(updatePre);
  581. if(me.isDef(selected.preSibling.preSibling)){
  582. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  583. postData.push(updatePrepre);
  584. }
  585. if(postData.length > 0){
  586. //ajax
  587. me.sectionTreeAjax(postData, function (rstData) {
  588. me.controller.upMove();
  589. me.refreshBtn(me.tree.selected);
  590. me.workBook.focus();
  591. });
  592. }
  593. },
  594. downMove: function (selected) {
  595. let me = this;
  596. me.downMoveBtn.addClass('disabled');
  597. let postData = [];
  598. if(!me.isDef(selected)){
  599. return;
  600. }
  601. if(!me.isDef(selected.nextSibling)){
  602. return;
  603. }
  604. if(me.isDef(selected.preSibling)){
  605. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  606. postData.push(updatePre);
  607. }
  608. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  609. postData.push(updateObj);
  610. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  611. postData.push(updateNext);
  612. if(postData.length > 0){
  613. //ajax
  614. me.sectionTreeAjax(postData, function (rstData) {
  615. me.controller.downMove();
  616. me.refreshBtn(me.tree.selected);
  617. me.workBook.focus();
  618. });
  619. }
  620. },
  621. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  622. let updateObj = Object.create(null);
  623. updateObj.updateType = '';
  624. updateObj.updateData = Object.create(null);
  625. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  626. if(this.isDef(updateType)){
  627. updateObj.updateType = updateType;
  628. }
  629. if(this.isDef(id)){
  630. updateObj.updateData.ID = id;
  631. }
  632. if(this.isDef(nid)){
  633. updateObj.updateData.NextSiblingID = nid;
  634. }
  635. if(this.isDef(pid)){
  636. updateObj.updateData.ParentID = pid;
  637. }
  638. if(this.isDef(name)){
  639. updateObj.updateData.name = name;
  640. }
  641. if(this.isDef(deleted)){
  642. updateObj.updateData.isDeleted = true;
  643. }
  644. return updateObj;
  645. },
  646. sectionTreeAjax: function (postData, scFunc, errFunc) {
  647. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  648. },
  649. initTools: function (node) {
  650. if(this.isDef(node)){
  651. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  652. //explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
  653. explanatoryOprObj.showText(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor, node.data.explanation, node.data.ruleText);
  654. //job
  655. jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.ALL;
  656. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
  657. jobContentOprObj.clickUpdate($('#txtareaAll'));
  658. //fz
  659. annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.ALL;
  660. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  661. }
  662. },
  663. //模仿默认点击
  664. initSelection: function (node, doAfterGetRation = null) {
  665. if (node && node.tree){
  666. node.tree.selected = node ? node : null;
  667. }
  668. let me = this;
  669. if(!me.isDef(node)){
  670. sheetCommonObj.cleanSheet(rationOprObj.workBook.getActiveSheet(), rationOprObj.setting, -1);
  671. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  672. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  673. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  674. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  675. return;
  676. }
  677. //me.workBook.getActiveSheet().setActiveCell(node.serialNo(), me.workBook.getActiveSheet().getActiveColumnIndex());
  678. me.initTools(node);
  679. me.refreshBtn(node);
  680. if(!me.isDef(node.children) || node.children.length === 0){
  681. //需要根据章节树下是否含有定额数据判断是否可以删除,在异步获取定额数据前将删除按钮无效化
  682. me.removeBtn.addClass('disabled');
  683. rationOprObj.canRations = true;
  684. rationOprObj.workBook.getSheet(0).clearSelection();
  685. //获取定额后的回调操作:1.正常变更章节树节点,则默认获取定额后定位至首行定额 2.搜索定额后,获取定额后定位至匹配到的定额
  686. if (doAfterGetRation && typeof doAfterGetRation === 'function') {
  687. rationOprObj.doAfterGetRation = doAfterGetRation;
  688. } else {
  689. rationOprObj.doAfterGetRation = function (rations) {
  690. rationOprObj.workBook.getActiveSheet().setActiveCell(0, 0);
  691. rationOprObj.rationSelInit(0, true);
  692. rationOprObj.workBook.getActiveSheet().showRow(0, GC.Spread.Sheets.VerticalPosition.top);
  693. };
  694. }
  695. rationOprObj.getRationItems(node.data.ID, rationOprObj.doAfterGetRation);
  696. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  697. }
  698. else {
  699. rationOprObj.canRations = false;
  700. rationOprObj.currentSectionId = node.data.ID;
  701. rationOprObj.workBook.getSheet(0).setRowCount(30);
  702. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  703. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  704. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  705. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  706. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  707. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  708. rationGLJOprObj.sheet.getParent().focus(false);
  709. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  710. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  711. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  712. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  713. }
  714. me.workBook.focus(true);
  715. },
  716. //根据定额定位至章节树
  717. locateToSection: function (rationCode) {
  718. const me = this;
  719. const $seach = $('#rationSearch');
  720. $seach.val(rationCode);
  721. //去后台搜索该定额
  722. $.bootstrapLoading.start();
  723. CommonAjax.post('/rationRepository/api/getRationItem', {rationLibId: pageOprObj.rationLibId, code: rationCode}, function (rstData) {
  724. if (!rstData) {
  725. alert(`不存在定额${rationCode}`);
  726. $.bootstrapLoading.end();
  727. return;
  728. }
  729. //定位至相关章节
  730. let sectionId = rstData.sectionId;
  731. if (!sectionId) {
  732. $.bootstrapLoading.end();
  733. return;
  734. }
  735. let sectionNode = me.tree.nodes[`id_${sectionId}`];
  736. if (!sectionNode) {
  737. $.bootstrapLoading.end();
  738. return;
  739. }
  740. let sectionRow = sectionNode.serialNo();
  741. me.sheet.setActiveCell(sectionRow, 1);
  742. me.sheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.top);
  743. $.bootstrapLoading.end();
  744. let doAfterGetRation = function (rations) {
  745. let findRation = _.find(rations, {code: rationCode}),
  746. rIdx = rations.indexOf(findRation),
  747. rationSheet = rationOprObj.workBook.getActiveSheet();
  748. rationSheet.setActiveCell(rIdx, 0);
  749. rationOprObj.rationSelInit(rIdx, true);
  750. rationOprObj.workBook.getActiveSheet().showRow(rIdx, GC.Spread.Sheets.VerticalPosition.top);
  751. };
  752. me.initSelection(sectionNode, doAfterGetRation);
  753. }, function () {
  754. $.bootstrapLoading.end();
  755. });
  756. }
  757. };
  758. $(document).ready(function () {
  759. $('#rationSearch').keydown(function (event) {
  760. if(event.keyCode === 13){
  761. $(this).blur();
  762. let rationCode = $(this).val().toUpperCase();
  763. if (rationCode) {
  764. sectionTreeObj.locateToSection(rationCode);
  765. }
  766. }
  767. });
  768. });