section_tree.js 34 KB

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