revise.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. autoFlashHeight();
  11. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  12. const billsSheet = billsSpread.getActiveSheet();
  13. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  14. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  15. const posSheet = posSpread.getActiveSheet();
  16. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  17. $.divResizer({
  18. select: '#revise-resize',
  19. callback: function () {
  20. billsSpread.refresh();
  21. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  22. $(".sp-wrap").height(bcontent-40);
  23. posSpread.refresh();
  24. }
  25. });
  26. let stdChapter, stdBills;
  27. $.divResizer({
  28. select: '#revise-right-spr',
  29. callback: function () {
  30. billsSpread.refresh();
  31. if (posSpread) {
  32. posSpread.refresh();
  33. }
  34. if (stdChapter) {
  35. stdChapter.spread.refresh();
  36. }
  37. if (stdBills) {
  38. stdBills.spread.refresh();
  39. }
  40. }
  41. });
  42. // 展开收起标准清单
  43. $('a', '#side-menu').bind('click', function (e) {
  44. e.preventDefault();
  45. const tab = $(this), tabPanel = $(tab.attr('content'));
  46. const showSideTools = function (show) {
  47. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  48. if (show) {
  49. right.show();
  50. autoFlashHeight();
  51. /**
  52. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  53. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  54. * 故需要通过最终的parent.width再计算一次left.width
  55. *
  56. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  57. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  58. *
  59. */
  60. //left.css('width', parent.width() - right.outerWidth());
  61. //left.css('width', parent.width() - right.outerWidth());
  62. const percent = 100 - right.outerWidth() /parent.width() * 100;
  63. left.css('width', percent + '%');
  64. } else {
  65. left.width(parent.width());
  66. right.hide();
  67. }
  68. };
  69. // 展开工具栏、切换标签
  70. if (!tab.hasClass('active')) {
  71. const close = $('.active', '#side-menu').length === 0;
  72. $('a', '#side-menu').removeClass('active');
  73. tab.addClass('active');
  74. $('.tab-content .tab-pane').removeClass('active');
  75. tabPanel.addClass('active');
  76. showSideTools(tab.hasClass('active'));
  77. if (tab.attr('content') === '#std-chapter') {
  78. if (!stdChapter) {
  79. stdChapter = new stdLib($('#std-chapter-spread')[0], 'chapter', {
  80. id: 'chapter_id',
  81. pid: 'pid',
  82. order: 'order',
  83. level: 'level',
  84. rootId: -1,
  85. keys: ['id', 'list_id', 'chapter_id'],
  86. }, {
  87. cols: [
  88. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  89. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  90. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  91. ],
  92. treeCol: 0,
  93. emptyRows: 0,
  94. headRows: 1,
  95. headRowHeight: [40],
  96. defaultRowHeight: 21,
  97. });
  98. stdChapter.loadLib(1);
  99. }
  100. stdChapter.spread.refresh();
  101. } else if (tab.attr('content') === '#std-bills') {
  102. if (!stdBills) {
  103. stdBills = new stdLib($('#std-bills-spread')[0], 'bills', {
  104. id: 'bill_id',
  105. pid: 'pid',
  106. order: 'order',
  107. level: 'level',
  108. rootId: -1,
  109. keys: ['id', 'list_id', 'bill_id']
  110. }, {
  111. cols: [
  112. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  113. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  114. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  115. ],
  116. treeCol: 0,
  117. emptyRows: 0,
  118. headRows: 1,
  119. headRowHeight: [40],
  120. defaultRowHeight: 21,
  121. });
  122. stdBills.loadLib(1);
  123. }
  124. stdBills.spread.refresh();
  125. }
  126. }
  127. billsSpread.refresh();
  128. if (posSpread) {
  129. posSpread.refresh();
  130. }
  131. });
  132. class stdLib {
  133. constructor(obj, stdType, treeSetting, spreadSetting) {
  134. this.obj = obj;
  135. this.url = '/std/' + stdType;
  136. this.treeSetting = treeSetting;
  137. treeSetting.preUrl = this.url;
  138. this.spreadSetting = spreadSetting;
  139. this.spread = SpreadJsObj.createNewSpread(this.obj);
  140. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  141. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  142. const stdSheet = info.sheet;
  143. const mainSheet = ledgerSpread.getActiveSheet();
  144. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  145. const stdTree = stdSheet.zh_tree;
  146. const stdNode = stdTree.nodes[info.row];
  147. const mainTree = mainSheet.zh_tree;
  148. const sel = mainSheet.getSelections()[0];
  149. const mainNode = mainTree.nodes[sel.row];
  150. if (!stdNode) { return; }
  151. mainTree.postData('/tender/' + getTenderId() + '/ledger/add-by-std', mainNode, {
  152. tender_id: mainNode.tender_id,
  153. stdType: stdType,
  154. stdLibId: stdNode.list_id,
  155. stdNode: stdTree.getNodeKey(stdNode)
  156. }, function (result) {
  157. treeOperationObj.refreshTree(mainSheet, result);
  158. treeOperationObj.refreshOperationValid(mainSheet);
  159. });
  160. });
  161. this.pathTree = createNewPathTree('base', this.treeSetting);
  162. }
  163. loadLib (listId) {
  164. const self = this;
  165. postData(this.url+'/get-data', {list_id: listId}, function (data) {
  166. self.pathTree.loadDatas(data);
  167. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
  168. });
  169. }
  170. }
  171. // 修订详情 保存
  172. $('#save').click(function () {
  173. const content = $('textarea').val();
  174. postData('save', { content: content });
  175. });
  176. });