section_tree.js 30 KB

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