ledger_gather.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. if (['1000', '1100', '1200', '1300'].indexOf(d.code) >= 0) {
  80. if (checkZero(d.total_price) && checkZero(d.deal_bills_tp)) {
  81. continue;
  82. }
  83. }
  84. html.push('<tr>');
  85. if (d.code) {
  86. html.push('<td>', d.code, '</td>');
  87. html.push('<td>', d.name, '</td>');
  88. } else {
  89. html.push('<td colspan="2">', d.name, '</td>');
  90. }
  91. html.push('<td class="text-right">', d.deal_bills_tp ? d.deal_bills_tp : '', '</td>');
  92. html.push('<td class="text-right">', d.total_price ? d.total_price : '', '</td>');
  93. html.push('<td class="text-right">', d.compare_tp ? d.compare_tp : '', '</td>');
  94. html.push('</tr>');
  95. }
  96. }
  97. $('#chapter-list').html(html.join(''));
  98. }
  99. postData(window.location.pathname + '/load', {}, function (data) {
  100. gclGatherModel.loadLedgerData(data.bills);
  101. gclGatherModel.loadPosData(data.pos);
  102. gclGatherModel.loadDealBillsData(data.dealBills);
  103. gclGatherData = gclGatherModel.gatherGclData();
  104. gclGatherModel.checkDiffer(gclGatherData);
  105. for (const gcl of gclGatherData) {
  106. gcl.compare_qty = ZhCalc.sub(gcl.deal_bills_qty, gcl.quantity);
  107. gcl.compare_tp = ZhCalc.sub(gcl.deal_bills_tp, gcl.total_price);
  108. }
  109. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  110. loadLeafXmjData(0);
  111. const chapterData = gclGatherModel.gatherChapterData(chapter, ['total_price']);
  112. for (const c of chapterData) {
  113. c.compare_tp = ZhCalc.sub(c.deal_bills_tp, c.total_price);
  114. }
  115. generateChapterHtml(chapterData);
  116. }, null, true);
  117. // 展开收起附件
  118. $('a', '.right-nav').bind('click', function () {
  119. const tab = $(this), tabPanel = $(tab.attr('content'));
  120. const showTools = function (show) {
  121. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  122. if (show) {
  123. right.show();
  124. autoFlashHeight();
  125. /**
  126. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  127. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  128. * 故需要通过最终的parent.width再计算一次left.width
  129. *
  130. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  131. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  132. *
  133. */
  134. //left.css('width', parent.width() - right.outerWidth());
  135. //left.css('width', parent.width() - right.outerWidth());
  136. const percent = 100 - right.outerWidth() /parent.width() * 100;
  137. left.css('width', percent + '%');
  138. } else {
  139. right.hide();
  140. left.css('width', '100%');
  141. }
  142. };
  143. if (!tab.hasClass('active')) {
  144. $('a', '.side-menu').removeClass('active');
  145. $('.tab-content .tab-select-show').removeClass('active');
  146. tab.addClass('active');
  147. tabPanel.addClass('active');
  148. showTools(tab.hasClass('active'));
  149. } else {
  150. tab.removeClass('active');
  151. tabPanel.removeClass('active');
  152. showTools(tab.hasClass('active'));
  153. }
  154. gclSpread.refresh();
  155. leafXmjSpread.refresh();
  156. });
  157. $.subMenu({
  158. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  159. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  160. key: 'menu.1.0.0',
  161. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  162. callback: function (info) {
  163. if (info.mini) {
  164. $('.panel-title').addClass('fluid');
  165. $('#sub-menu').removeClass('panel-sidebar');
  166. } else {
  167. $('.panel-title').removeClass('fluid');
  168. $('#sub-menu').addClass('panel-sidebar');
  169. }
  170. autoFlashHeight();
  171. gclSpread.refresh();
  172. leafXmjSpread.refresh();
  173. }
  174. });
  175. $.divResizer({
  176. select: '#main-resize',
  177. callback: function () {
  178. gclSpread.refresh();
  179. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  180. $(".sp-wrap").height(bcontent-40);
  181. leafXmjSpread.refresh();
  182. }
  183. });
  184. $.divResizer({
  185. select: '#right-spr',
  186. callback: function () {
  187. gclSpread.refresh();
  188. leafXmjSpread.refresh();
  189. }
  190. });
  191. });