section_tree.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /**
  2. * Created by Zhong on 2017/12/18.
  3. */
  4. let pageOprObj = {
  5. rationLibName : null,
  6. rationLibId : null,
  7. gljLibId: null,
  8. initPage : function() {
  9. let me = this, rationLibId = getQueryString("repository");
  10. me.getRationLibInfo(rationLibId, function (rstData) {
  11. if(rstData.length > 0){
  12. me.rationLibName = rstData[0].dispName;
  13. me.gljLibId = rstData[0].gljLib;
  14. if(!me.gljLibId || typeof me.gljLibId === 'undefined' || me.gljLibId == -1){
  15. alert("没有引用工料机库!");
  16. window.location.href = "/rationRepository/main";
  17. }
  18. if (me.rationLibName) {
  19. var html = $("#rationname")[0].outerHTML;
  20. html = html.replace("XXX定额库", me.rationLibName);
  21. $("#rationname")[0].outerHTML = html;
  22. me.rationLibId = rationLibId;
  23. sectionTreeObj.getSectionTree(rationLibId);
  24. //job
  25. jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
  26. $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
  27. $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
  28. jobContentOprObj.bindAllEvents($('#txtareaAll'));
  29. //fz
  30. annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
  31. $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
  32. $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
  33. annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
  34. }
  35. }
  36. });
  37. },
  38. getRationLibInfo: function (rationLibId, callback) {
  39. CommonAjax.post('api/getRationLib', {libId: rationLibId}, callback);
  40. }
  41. }
  42. let sectionTreeObj = {
  43. cache: null,//ref to tree.items
  44. tree: null,
  45. controller: null,
  46. workBook: null,
  47. sheet: null,
  48. updateType: {new: 'new', update: 'update'},
  49. insertBtn: $('#tree_Insert'),
  50. removeBtn: $('#tree_remove'),
  51. upLevelBtn: $('#tree_upLevel'),
  52. downLevelBtn: $('#tree_downLevel'),
  53. downMoveBtn: $('#tree_downMove'),
  54. upMoveBtn: $('#tree_upMove'),
  55. setting: {
  56. sheet: {
  57. cols:[
  58. {
  59. head: {
  60. titleNames: ['名称'],
  61. spanCols: [1],
  62. spanRows: [2],
  63. vAlign: [1, 1],
  64. hAlign: [1, 1],
  65. font: 'Arial'
  66. },
  67. data: {
  68. field: 'name',
  69. vAlign: 1,
  70. hAlign: 0,
  71. font: 'Arial'
  72. },
  73. width: 400
  74. }
  75. ],
  76. headRows: 1,
  77. headRowHeight: [47],
  78. emptyRows: 0,
  79. treeCol: 0
  80. },
  81. tree: {
  82. id: 'ID',
  83. pid: 'ParentID',
  84. nid: 'NextSiblingID',
  85. rootId: -1
  86. },
  87. options: {
  88. tabStripVisible: false,
  89. allowCopyPasteExcelStyle : false,
  90. allowExtendPasteRange: false,
  91. allowUserDragDrop : false,
  92. allowUserDragFill: false,
  93. scrollbarMaxAlign : true
  94. }
  95. },
  96. isDef: function (v) {
  97. return v !== undefined && v !== null;
  98. },
  99. isFunc: function (v) {
  100. return this.isDef(v) && typeof v === 'function';
  101. },
  102. //sheet things
  103. setOptions: function (workbook, opts) {
  104. for(let opt in opts){
  105. workbook.options[opt] = opts[opt];
  106. }
  107. },
  108. renderFunc: function (sheet, func) {
  109. sheet.suspendPaint();
  110. sheet.suspendEvent();
  111. if(this.isFunc(func)){
  112. func();
  113. }
  114. sheet.resumePaint();
  115. sheet.resumeEvent();
  116. },
  117. buildSheet: function () {
  118. if(!this.isDef(this.workBook)){
  119. this.workBook = new GC.Spread.Sheets.Workbook($('#sectionSpread')[0], {sheetCount: 1});
  120. this.sheet = this.workBook.getActiveSheet();
  121. this.setOptions(this.workBook, this.setting.options);
  122. this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  123. this.bindEvents(this.sheet);
  124. }
  125. },
  126. bindEvents: function (sheet) {
  127. let me = sectionTreeObj;
  128. const Events = GC.Spread.Sheets.Events;
  129. sheet.bind(Events.SelectionChanged, me.onSelectionChanged);
  130. sheet.bind(Events.EditEnded, me.onEditEnded);
  131. sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);
  132. },
  133. onSelectionChanged: function (sender, info) {
  134. let me = sectionTreeObj;
  135. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  136. let row = info.newSelections[0].row;
  137. let section = me.cache[row];
  138. me.initSelection(section);
  139. }
  140. else {
  141. me.refreshBtn(null);
  142. }
  143. },
  144. onEditEnded: function (sender, args) {
  145. let me = sectionTreeObj;
  146. let postData = [];
  147. let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : '';
  148. let node = me.cache[args.row];
  149. if(me.isDef(node) && node.data.name !== v){
  150. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, v, null);
  151. postData.push(updateObj);
  152. //ajax
  153. //update
  154. me.sectionTreeAjax(postData, function (rstData) {
  155. node.data.name = v;
  156. }, function () {
  157. args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : '');
  158. });
  159. }
  160. },
  161. onClipboardPasted: function (sender, info) {
  162. let me = sectionTreeObj;
  163. let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'name'}]}, info);
  164. let postData = [];
  165. let frontData = [];
  166. for(let i = 0, len = items.length; i < len; i++){
  167. let row = info.cellRange.row + i;
  168. let node = me.cache[row];
  169. if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){
  170. let updateObj = me.getUpdateObj(me.updateType.update, node.getID(), null, null, items[i].name, null);
  171. postData.push(updateObj);
  172. frontData.push({row: row, name: items[i].name});
  173. node.data.name = items[i].name;
  174. }
  175. }
  176. if(postData.length > 0){
  177. //ajax
  178. me.sectionTreeAjax(postData, function (rstData) {
  179. for(let i = 0, len = frontData.length; i < len; i++){
  180. let node = me.cache[frontData[i]['row']];
  181. if(me.isDef(node)){
  182. node.data.name = frontData[i]['name'];
  183. }
  184. }
  185. }, function () {
  186. for(let i = 0, len = frontData.length; i < len; i++){
  187. let node = me.cache[frontData[i]['row']];
  188. me.sheet.setValue(frontData[i]['row'], 0, me.isDef(node) ? node.data.name : '');
  189. }
  190. });
  191. }
  192. },
  193. getSectionTree: function (repId) {
  194. let me = sectionTreeObj;
  195. let url = 'api/getRationTree';
  196. let postData = {rationLibId: repId};
  197. let sucFunc = function (rstData) {
  198. if(rstData.length > 0){
  199. storageUtil.setSessionCache("RationGrp","repositoryID",rstData[0].rationRepId);
  200. }
  201. //init
  202. me.buildSheet();
  203. me.initTree(rstData);
  204. me.cache = me.tree.items;
  205. me.bindBtn();
  206. me.initController(me.tree, me.sheet, me.setting.sheet);
  207. me.controller.showTreeData();
  208. me.sheet.setFormatter(-1, 0, '@');
  209. me.initSelection(me.tree.selected);
  210. explanatoryOprObj.bindEvents($('#explanationShow'), $('#ruleTextShow'));
  211. };
  212. let errFunc = function () {
  213. };
  214. CommonAjax.post(url, postData, sucFunc, errFunc);
  215. },
  216. initTree: function (datas) {
  217. this.tree = idTree.createNew(this.setting.tree);
  218. this.tree.loadDatas(datas);
  219. this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;
  220. },
  221. initController: function (tree, sheet, setting) {
  222. this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);
  223. },
  224. refreshBtn: function (selected) {
  225. let me = this;
  226. me.insertBtn.removeClass('disabled');
  227. me.removeBtn.removeClass('disabled');
  228. me.upLevelBtn.removeClass('disabled');
  229. me.downLevelBtn.removeClass('disabled');
  230. me.downMoveBtn.removeClass('disabled');
  231. me.upMoveBtn.removeClass('disabled');
  232. if(!me.isDef(selected)){
  233. me.removeBtn.addClass('disabled');
  234. me.upLevelBtn.addClass('disabled');
  235. me.downLevelBtn.addClass('disabled');
  236. me.downMoveBtn.addClass('disabled');
  237. me.upMoveBtn.addClass('disabled');
  238. }
  239. else {
  240. if(!me.isDef(selected.preSibling)){
  241. me.downLevelBtn.addClass('disabled');
  242. me.upMoveBtn.addClass('disabled');
  243. }
  244. if(!me.isDef(selected.nextSibling)){
  245. me.downMoveBtn.addClass('disabled');
  246. }
  247. if(!me.isDef(selected.parent)){
  248. me.upLevelBtn.addClass('disabled');
  249. }
  250. }
  251. },
  252. bindBtn: function () {
  253. let me = this;
  254. me.insertBtn.click(function () {
  255. me.insert();
  256. });
  257. me.removeBtn.click(function () {
  258. me.remove(me.tree.selected);
  259. });
  260. me.upLevelBtn.click(function () {
  261. me.upLevel(me.tree.selected);
  262. });
  263. me.downLevelBtn.click(function () {
  264. me.downLevel(me.tree.selected);
  265. });
  266. me.downMoveBtn.click(function () {
  267. me.downMove(me.tree.selected);
  268. });
  269. me.upMoveBtn.click(function () {
  270. me.upMove(me.tree.selected);
  271. });
  272. },
  273. insert: function () {
  274. let me = this;
  275. me.insertBtn.addClass('disabled');
  276. let postData = [];
  277. CommonAjax.post('api/getNewRationTreeID', {}, function (newID) {
  278. if(!me.isDef(newID)){
  279. return;
  280. }
  281. me.tree.maxNodeID(newID - 1);
  282. let selected = me.tree.selected;
  283. let insertObj = me.getUpdateObj(me.updateType.new, newID, -1, -1, '', null);
  284. if(me.isDef(selected)) {
  285. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), newID, null, null, null);
  286. postData.push(updateObj);
  287. insertObj.updateData.ParentID = selected.getParentID();
  288. if(me.isDef(selected.nextSibling)){
  289. insertObj.updateData.NextSiblingID = selected.getNextSiblingID();
  290. }
  291. }
  292. postData.push(insertObj);
  293. if(postData.length > 0){
  294. //ajax
  295. me.sectionTreeAjax(postData, function (rstData) {
  296. me.controller.insert();
  297. me.refreshBtn(me.tree.selected);
  298. //fresh tools
  299. me.initTools(me.tree.selected);
  300. me.workBook.focus();
  301. });
  302. }
  303. });
  304. },
  305. remove: function (selected) {
  306. let me = this;
  307. me.removeBtn.addClass('disabled');
  308. let postData = [], IDs = [];
  309. if(!selected){
  310. return;
  311. }
  312. getDelIds(selected);
  313. function getDelIds(node){
  314. if(me.isDef(node)){
  315. IDs.push(node.getID());
  316. if(node.children.length > 0){
  317. for(let i = 0, len = node.children.length; i < len; i++){
  318. getDelIds(node.children[i]);
  319. }
  320. }
  321. }
  322. }
  323. if(me.isDef(selected.preSibling)){
  324. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  325. postData.push(updateObj);
  326. }
  327. if(IDs.length > 0){
  328. for(let i = 0, len = IDs.length; i < len; i++){
  329. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  330. postData.push(delObj);
  331. }
  332. }
  333. if(postData.length > 0){
  334. //ajax
  335. me.sectionTreeAjax(postData, function (rstData) {
  336. me.controller.delete();
  337. me.refreshBtn(me.tree.selected);
  338. me.initTools(me.tree.selected);
  339. me.workBook.focus();
  340. });
  341. }
  342. },
  343. upLevel: function (selected) {
  344. let me = this;
  345. me.upLevelBtn.addClass('disabled');
  346. let postData = [];
  347. if(!me.isDef(selected)){
  348. return;
  349. }
  350. if(!me.isDef(selected.parent)){
  351. return;
  352. }
  353. if(me.isDef(selected.preSibling)){
  354. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), -1, null, null, null);
  355. postData.push(updateObj);
  356. }
  357. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.parent.getNextSiblingID(), selected.parent.getParentID(), null, null);
  358. postData.push(updateObj);
  359. let updateParent = me.getUpdateObj(me.updateType.update, selected.getParentID(), selected.getID(), null, null, null);
  360. postData.push(updateParent);
  361. let nextIDs = [];
  362. getNext(selected);
  363. function getNext(node){
  364. if(me.isDef(node.nextSibling)){
  365. nextIDs.push(node.getNextSiblingID());
  366. getNext(node.nextSibling);
  367. }
  368. }
  369. for(let i = 0, len = nextIDs.length; i < len; i++){
  370. postData.push(me.getUpdateObj(me.updateType.update, nextIDs[i], null, selected.getID(), null, null));
  371. }
  372. if(postData.length > 0){
  373. //ajax
  374. me.sectionTreeAjax(postData, function (rstData) {
  375. me.controller.upLevel();
  376. me.refreshBtn(me.tree.selected);
  377. me.workBook.focus();
  378. });
  379. }
  380. },
  381. downLevel: function (selected) {
  382. let me = this;
  383. me.downLevelBtn.addClass('disabled');
  384. let postData = [];
  385. if(!me.isDef(selected)){
  386. return;
  387. }
  388. if(!me.isDef(selected.preSibling)){
  389. return;
  390. }
  391. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  392. postData.push(updatePre);
  393. if(selected.preSibling.children.length > 0){
  394. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.children[selected.preSibling.children.length - 1].getID(), selected.getID(), null, null, null);
  395. postData.push(updateObj);
  396. }
  397. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), -1, selected.preSibling.getID(), null, null);
  398. postData.push(updateObj);
  399. if(postData.length > 0){
  400. //ajax
  401. me.sectionTreeAjax(postData, function (rstData) {
  402. me.controller.downLevel();
  403. me.refreshBtn(me.tree.selected);
  404. me.workBook.focus();
  405. });
  406. }
  407. },
  408. upMove: function (selected) {
  409. let me = this;
  410. me.upMoveBtn.addClass('disabled');
  411. let postData = [];
  412. if(!me.isDef(selected)){
  413. return;
  414. }
  415. if(!me.isDef(selected.preSibling)){
  416. return;
  417. }
  418. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  419. postData.push(updateObj);
  420. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  421. postData.push(updatePre);
  422. if(me.isDef(selected.preSibling.preSibling)){
  423. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  424. postData.push(updatePrepre);
  425. }
  426. if(postData.length > 0){
  427. //ajax
  428. me.sectionTreeAjax(postData, function (rstData) {
  429. me.controller.upMove();
  430. me.refreshBtn(me.tree.selected);
  431. me.workBook.focus();
  432. });
  433. }
  434. },
  435. downMove: function (selected) {
  436. let me = this;
  437. me.downMoveBtn.addClass('disabled');
  438. let postData = [];
  439. if(!me.isDef(selected)){
  440. return;
  441. }
  442. if(!me.isDef(selected.nextSibling)){
  443. return;
  444. }
  445. if(me.isDef(selected.preSibling)){
  446. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  447. postData.push(updatePre);
  448. }
  449. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  450. postData.push(updateObj);
  451. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  452. postData.push(updateNext);
  453. if(postData.length > 0){
  454. //ajax
  455. me.sectionTreeAjax(postData, function (rstData) {
  456. me.controller.downMove();
  457. me.refreshBtn(me.tree.selected);
  458. me.workBook.focus();
  459. });
  460. }
  461. },
  462. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  463. let updateObj = Object.create(null);
  464. updateObj.updateType = '';
  465. updateObj.updateData = Object.create(null);
  466. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  467. if(this.isDef(updateType)){
  468. updateObj.updateType = updateType;
  469. }
  470. if(this.isDef(id)){
  471. updateObj.updateData.ID = id;
  472. }
  473. if(this.isDef(nid)){
  474. updateObj.updateData.NextSiblingID = nid;
  475. }
  476. if(this.isDef(pid)){
  477. updateObj.updateData.ParentID = pid;
  478. }
  479. if(this.isDef(name)){
  480. updateObj.updateData.name = name;
  481. }
  482. if(this.isDef(deleted)){
  483. updateObj.updateData.isDeleted = true;
  484. }
  485. return updateObj;
  486. },
  487. sectionTreeAjax: function (postData, scFunc, errFunc) {
  488. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  489. },
  490. initTools: function (node) {
  491. if(this.isDef(node)){
  492. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  493. explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
  494. explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), node.data.explanation, node.data.ruleText);
  495. //job
  496. jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.NONE;
  497. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
  498. jobContentOprObj.clickUpdate($('#txtareaAll'));
  499. //fz
  500. annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.NONE;
  501. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  502. }
  503. },
  504. //模仿默认点击
  505. initSelection: function (node) {
  506. let me = this;
  507. if(!me.isDef(node)){
  508. return;
  509. }
  510. me.initTools(node);
  511. me.refreshBtn(node);
  512. if(!me.isDef(node.children) || node.children.length === 0){
  513. rationOprObj.canRations = true;
  514. rationOprObj.workBook.getSheet(0).clearSelection();
  515. rationOprObj.getRationItems(node.data.ID);
  516. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  517. }
  518. else {
  519. rationOprObj.canRations = false;
  520. rationOprObj.currentSectionId = node.data.ID;
  521. rationOprObj.workBook.getSheet(0).setRowCount(30);
  522. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  523. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  524. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  525. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  526. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  527. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  528. rationGLJOprObj.sheet.getParent().focus(false);
  529. }
  530. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  531. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  532. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  533. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  534. me.workBook.focus(true);
  535. }
  536. };