section_tree.js 34 KB

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