section_tree.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. });
  301. }
  302. });
  303. },
  304. remove: function (selected) {
  305. let me = this;
  306. me.removeBtn.addClass('disabled');
  307. let postData = [], IDs = [];
  308. if(!selected){
  309. return;
  310. }
  311. getDelIds(selected);
  312. function getDelIds(node){
  313. if(me.isDef(node)){
  314. IDs.push(node.getID());
  315. if(node.children.length > 0){
  316. for(let i = 0, len = node.children.length; i < len; i++){
  317. getDelIds(node.children[i]);
  318. }
  319. }
  320. }
  321. }
  322. if(me.isDef(selected.preSibling)){
  323. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  324. postData.push(updateObj);
  325. }
  326. if(IDs.length > 0){
  327. for(let i = 0, len = IDs.length; i < len; i++){
  328. let delObj = me.getUpdateObj(me.updateType.update, IDs[i], null, null, null, true);
  329. postData.push(delObj);
  330. }
  331. }
  332. if(postData.length > 0){
  333. //ajax
  334. me.sectionTreeAjax(postData, function (rstData) {
  335. me.controller.delete();
  336. me.refreshBtn(me.tree.selected);
  337. me.initTools(me.tree.selected);
  338. });
  339. }
  340. },
  341. upLevel: function (selected) {
  342. let me = this;
  343. me.upLevelBtn.addClass('disabled');
  344. let postData = [];
  345. if(!me.isDef(selected)){
  346. return;
  347. }
  348. if(!me.isDef(selected.parent)){
  349. return;
  350. }
  351. if(me.isDef(selected.preSibling)){
  352. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), -1, null, null, null);
  353. postData.push(updateObj);
  354. }
  355. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.parent.getNextSiblingID(), selected.parent.getParentID(), null, null);
  356. postData.push(updateObj);
  357. let updateParent = me.getUpdateObj(me.updateType.update, selected.getParentID(), selected.getID(), null, null, null);
  358. postData.push(updateParent);
  359. let nextIDs = [];
  360. getNext(selected);
  361. function getNext(node){
  362. if(me.isDef(node.nextSibling)){
  363. nextIDs.push(node.getNextSiblingID());
  364. getNext(node.nextSibling);
  365. }
  366. }
  367. for(let i = 0, len = nextIDs.length; i < len; i++){
  368. postData.push(me.getUpdateObj(me.updateType.update, nextIDs[i], null, selected.getID(), null, null));
  369. }
  370. if(postData.length > 0){
  371. //ajax
  372. me.sectionTreeAjax(postData, function (rstData) {
  373. me.controller.upLevel();
  374. me.refreshBtn(me.tree.selected);
  375. });
  376. }
  377. },
  378. downLevel: function (selected) {
  379. let me = this;
  380. me.downLevelBtn.addClass('disabled');
  381. let postData = [];
  382. if(!me.isDef(selected)){
  383. return;
  384. }
  385. if(!me.isDef(selected.preSibling)){
  386. return;
  387. }
  388. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  389. postData.push(updatePre);
  390. if(selected.preSibling.children.length > 0){
  391. let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.children[selected.preSibling.children.length - 1].getID(), selected.getID(), null, null, null);
  392. postData.push(updateObj);
  393. }
  394. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), -1, selected.preSibling.getID(), null, null);
  395. postData.push(updateObj);
  396. if(postData.length > 0){
  397. //ajax
  398. me.sectionTreeAjax(postData, function (rstData) {
  399. me.controller.downLevel();
  400. me.refreshBtn(me.tree.selected);
  401. });
  402. }
  403. },
  404. upMove: function (selected) {
  405. let me = this;
  406. me.upMoveBtn.addClass('disabled');
  407. let postData = [];
  408. if(!me.isDef(selected)){
  409. return;
  410. }
  411. if(!me.isDef(selected.preSibling)){
  412. return;
  413. }
  414. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.preSibling.getID(), null, null, null);
  415. postData.push(updateObj);
  416. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  417. postData.push(updatePre);
  418. if(me.isDef(selected.preSibling.preSibling)){
  419. let updatePrepre = me.getUpdateObj(me.updateType.update, selected.preSibling.preSibling.getID(), selected.getID(), null, null, null);
  420. postData.push(updatePrepre);
  421. }
  422. if(postData.length > 0){
  423. //ajax
  424. me.sectionTreeAjax(postData, function (rstData) {
  425. me.controller.upMove();
  426. me.refreshBtn(me.tree.selected);
  427. });
  428. }
  429. },
  430. downMove: function (selected) {
  431. let me = this;
  432. me.downMoveBtn.addClass('disabled');
  433. let postData = [];
  434. if(!me.isDef(selected)){
  435. return;
  436. }
  437. if(!me.isDef(selected.nextSibling)){
  438. return;
  439. }
  440. if(me.isDef(selected.preSibling)){
  441. let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
  442. postData.push(updatePre);
  443. }
  444. let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.nextSibling.getNextSiblingID(), null, null, null);
  445. postData.push(updateObj);
  446. let updateNext = me.getUpdateObj(me.updateType.update, selected.getNextSiblingID(), selected.getID(), null, null, null);
  447. postData.push(updateNext);
  448. if(postData.length > 0){
  449. //ajax
  450. me.sectionTreeAjax(postData, function (rstData) {
  451. me.controller.downMove();
  452. me.refreshBtn(me.tree.selected);
  453. });
  454. }
  455. },
  456. getUpdateObj: function (updateType, id, nid, pid, name, deleted) {
  457. let updateObj = Object.create(null);
  458. updateObj.updateType = '';
  459. updateObj.updateData = Object.create(null);
  460. updateObj.updateData.rationRepId = pageOprObj.rationLibId;
  461. if(this.isDef(updateType)){
  462. updateObj.updateType = updateType;
  463. }
  464. if(this.isDef(id)){
  465. updateObj.updateData.ID = id;
  466. }
  467. if(this.isDef(nid)){
  468. updateObj.updateData.NextSiblingID = nid;
  469. }
  470. if(this.isDef(pid)){
  471. updateObj.updateData.ParentID = pid;
  472. }
  473. if(this.isDef(name)){
  474. updateObj.updateData.name = name;
  475. }
  476. if(this.isDef(deleted)){
  477. updateObj.updateData.isDeleted = true;
  478. }
  479. return updateObj;
  480. },
  481. sectionTreeAjax: function (postData, scFunc, errFunc) {
  482. CommonAjax.post('api/updateNodes', {updateData: postData, lastOpr: userAccount}, scFunc, errFunc);
  483. },
  484. initTools: function (node) {
  485. if(this.isDef(node)){
  486. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
  487. explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
  488. explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), node.data.explanation, node.data.ruleText);
  489. //job
  490. jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.NONE;
  491. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);
  492. jobContentOprObj.clickUpdate($('#txtareaAll'));
  493. //fz
  494. annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.NONE;
  495. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  496. }
  497. },
  498. //模仿默认点击
  499. initSelection: function (node) {
  500. let me = this;
  501. if(!me.isDef(node)){
  502. return;
  503. }
  504. me.initTools(node);
  505. me.refreshBtn(node);
  506. if(!me.isDef(node.children) || node.children.length === 0){
  507. rationOprObj.canRations = true;
  508. rationOprObj.workBook.getSheet(0).clearSelection();
  509. rationOprObj.getRationItems(node.data.ID);
  510. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');
  511. }
  512. else {
  513. rationOprObj.canRations = false;
  514. rationOprObj.currentSectionId = node.data.ID;
  515. rationOprObj.workBook.getSheet(0).setRowCount(30);
  516. rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);
  517. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  518. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  519. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  520. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  521. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  522. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  523. sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);
  524. sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);
  525. sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);
  526. rationGLJOprObj.sheet.getParent().focus(false);
  527. }
  528. me.workBook.focus(true);
  529. }
  530. };