ledger_gather.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. autoFlashHeight();
  11. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  12. SpreadJsObj.initSheet(gclSpread.getActiveSheet(), {
  13. cols: [
  14. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 120, formatter: '@'},
  15. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  16. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  17. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  18. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 80, type: 'Number'},
  19. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
  20. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  21. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  22. {title: '签约-台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'compare_qty', hAlign: 2, width: 80, type: 'Number'},
  23. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'compare_tp', hAlign: 2, width: 80, type: 'Number'},
  24. ],
  25. emptyRows: 0,
  26. headRows: 2,
  27. headRowHeight: [25, 25],
  28. defaultRowHeight: 21,
  29. headerFont: '12px 微软雅黑',
  30. font: '12px 微软雅黑',
  31. readOnly: true,
  32. getColor: function (sheet, data, col, defaultColor) {
  33. return data && data.differ ? '#FFE699' : defaultColor;
  34. }
  35. });
  36. const gclSheet = gclSpread.getActiveSheet();
  37. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  38. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), {
  39. cols: [
  40. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  41. {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  42. {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  43. {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  44. {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 100, formatter: '@'},
  45. {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  46. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  47. {title: '图册号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 120, formatter: '@'},
  48. ],
  49. emptyRows: 0,
  50. headRows: 1,
  51. headRowHeight: [32],
  52. defaultRowHeight: 21,
  53. headerFont: '12px 微软雅黑',
  54. font: '12px 微软雅黑',
  55. readOnly: true,
  56. });
  57. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  58. let gclGatherData;
  59. // 获取项目节数据
  60. function loadLeafXmjData(iGclRow) {
  61. const gcl = gclGatherData[iGclRow];
  62. if (gcl) {
  63. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  64. } else {
  65. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  66. }
  67. }
  68. // 切换清单行,读取所属项目节数据
  69. gclSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  70. const iNewRow = info.newSelections[0].row;
  71. if (!info.oldSelections || iNewRow !== info.oldSelections[0].row) {
  72. loadLeafXmjData(iNewRow);
  73. }
  74. });
  75. function generateChapterHtml(data) {
  76. const html = [];
  77. if (data) {
  78. for (const d of data) {
  79. html.push('<tr>');
  80. if (d.code) {
  81. html.push('<td>', d.code, '</td>');
  82. html.push('<td>', d.name, '</td>');
  83. } else {
  84. html.push('<td colspan="2">', d.name, '</td>');
  85. }
  86. html.push('<td class="text-right">', d.deal_bills_tp ? d.deal_bills_tp : '', '</td>');
  87. html.push('<td class="text-right">', d.total_price ? d.total_price : '', '</td>');
  88. html.push('<td class="text-right">', d.compare_tp ? d.compare_tp : '', '</td>');
  89. html.push('</tr>');
  90. }
  91. }
  92. $('#chapter-list').html(html.join(''));
  93. }
  94. postData(window.location.pathname + '/load', {}, function (data) {
  95. gclGatherModel.loadLedgerData(data.bills);
  96. gclGatherModel.loadPosData(data.pos);
  97. gclGatherModel.loadDealBillsData(data.dealBills);
  98. gclGatherData = gclGatherModel.gatherGclData();
  99. gclGatherModel.checkDiffer(gclGatherData);
  100. for (const gcl of gclGatherData) {
  101. gcl.compare_qty = ZhCalc.sub(gcl.deal_bills_qty, gcl.quantity);
  102. gcl.compare_tp = ZhCalc.sub(gcl.deal_bills_tp, gcl.total_price);
  103. }
  104. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  105. loadLeafXmjData(0);
  106. const chapterData = gclGatherModel.gatherChapterData(chapter, ['total_price']);
  107. for (const c of chapterData) {
  108. c.compare_tp = ZhCalc.sub(c.deal_bills_tp, c.total_price);
  109. }
  110. generateChapterHtml(chapterData);
  111. }, null, true);
  112. // 展开收起附件
  113. $('a', '.right-nav').bind('click', function () {
  114. const tab = $(this), tabPanel = $(tab.attr('content'));
  115. const showTools = function (show) {
  116. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  117. if (show) {
  118. right.show();
  119. autoFlashHeight();
  120. /**
  121. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  122. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  123. * 故需要通过最终的parent.width再计算一次left.width
  124. *
  125. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  126. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  127. *
  128. */
  129. //left.css('width', parent.width() - right.outerWidth());
  130. //left.css('width', parent.width() - right.outerWidth());
  131. const percent = 100 - right.outerWidth() /parent.width() * 100;
  132. left.css('width', percent + '%');
  133. } else {
  134. right.hide();
  135. left.css('width', '100%');
  136. }
  137. };
  138. if (!tab.hasClass('active')) {
  139. $('a', '.side-menu').removeClass('active');
  140. $('.tab-content .tab-select-show').removeClass('active');
  141. tab.addClass('active');
  142. tabPanel.addClass('active');
  143. showTools(tab.hasClass('active'));
  144. } else {
  145. tab.removeClass('active');
  146. tabPanel.removeClass('active');
  147. showTools(tab.hasClass('active'));
  148. }
  149. gclSpread.refresh();
  150. leafXmjSpread.refresh();
  151. });
  152. $.subMenu({
  153. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  154. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  155. key: 'menu.1.0.0',
  156. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  157. callback: function (info) {
  158. if (info.mini) {
  159. $('.panel-title').addClass('fluid');
  160. $('#sub-menu').removeClass('panel-sidebar');
  161. } else {
  162. $('.panel-title').removeClass('fluid');
  163. $('#sub-menu').addClass('panel-sidebar');
  164. }
  165. autoFlashHeight();
  166. gclSpread.refresh();
  167. leafXmjSpread.refresh();
  168. }
  169. });
  170. $.divResizer({
  171. select: '#main-resize',
  172. callback: function () {
  173. gclSpread.refresh();
  174. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  175. $(".sp-wrap").height(bcontent-40);
  176. leafXmjSpread.refresh();
  177. }
  178. });
  179. $.divResizer({
  180. select: '#right-spr',
  181. callback: function () {
  182. gclSpread.refresh();
  183. leafXmjSpread.refresh();
  184. }
  185. });
  186. });