section_tree.js 33 KB

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