section_tree.js 30 KB

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