ledger_gather.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. // 标红显示 签约-台账≠0
  69. function checkCompareData() {
  70. const sheet = gclSheet;
  71. const bCompare = $('#compare-tag')[0].checked;
  72. SpreadJsObj.beginMassOperation(gclSheet);
  73. for (let iRow = 0, iLength = gclSheet.getRowCount(); iRow < iLength; iRow++) {
  74. const node = gclSheet.zh_data[iRow];
  75. if (node) {
  76. const bDiffer = node.compare_qty ? !checkZero(Math.abs(node.compare_qty)) : !checkZero(Math.abs(node.compare_tp));
  77. const color = bCompare && bDiffer ? '#f8d7da' : '';
  78. sheet.getRange(iRow, -1, 1, -1).backColor(color);
  79. }
  80. }
  81. SpreadJsObj.endMassOperation(gclSheet);
  82. }
  83. // 切换清单行,读取所属项目节数据
  84. gclSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  85. const iNewRow = info.newSelections[0].row;
  86. if (!info.oldSelections || iNewRow !== info.oldSelections[0].row) {
  87. loadLeafXmjData(iNewRow);
  88. }
  89. });
  90. function generateChapterHtml(data) {
  91. const html = [];
  92. if (data) {
  93. for (const d of data) {
  94. if (['1000', '1100', '1200', '1300'].indexOf(d.code) >= 0) {
  95. if (checkZero(d.total_price) && checkZero(d.deal_bills_tp)) {
  96. continue;
  97. }
  98. }
  99. html.push('<tr>');
  100. if (d.code) {
  101. html.push('<td>', d.code, '</td>');
  102. html.push('<td>', d.name, '</td>');
  103. } else {
  104. html.push('<td colspan="2">', d.name, '</td>');
  105. }
  106. html.push('<td class="text-right">', d.deal_bills_tp ? d.deal_bills_tp : '', '</td>');
  107. html.push('<td class="text-right">', d.total_price ? d.total_price : '', '</td>');
  108. html.push('<td class="text-right">', d.compare_tp ? d.compare_tp : '', '</td>');
  109. html.push('</tr>');
  110. }
  111. }
  112. $('#chapter-list').html(html.join(''));
  113. }
  114. postData(window.location.pathname + '/load', {}, function (data) {
  115. gclGatherModel.loadLedgerData(data.bills);
  116. gclGatherModel.loadPosData(data.pos);
  117. gclGatherModel.loadDealBillsData(data.dealBills);
  118. gclGatherData = gclGatherModel.gatherGclData();
  119. gclGatherModel.checkDiffer(gclGatherData);
  120. for (const gcl of gclGatherData) {
  121. gcl.compare_qty = ZhCalc.sub(gcl.deal_bills_qty, gcl.quantity);
  122. gcl.compare_tp = ZhCalc.sub(gcl.deal_bills_tp, gcl.total_price);
  123. gcl.compare_differ = checkZero(gcl.compare_qty) && checkZero(gcl.compare_tp);
  124. }
  125. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  126. checkCompareData();
  127. loadLeafXmjData(0);
  128. const chapterData = gclGatherModel.gatherChapterData(chapter, ['total_price']);
  129. for (const c of chapterData) {
  130. c.compare_tp = ZhCalc.sub(c.deal_bills_tp, c.total_price);
  131. }
  132. generateChapterHtml(chapterData);
  133. }, null, true);
  134. $('#compare-tag').click(checkCompareData);
  135. // 展开收起附件
  136. $('a', '.right-nav').bind('click', function () {
  137. const tab = $(this), tabPanel = $(tab.attr('content'));
  138. const showTools = function (show) {
  139. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  140. if (show) {
  141. right.show();
  142. autoFlashHeight();
  143. /**
  144. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  145. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  146. * 故需要通过最终的parent.width再计算一次left.width
  147. *
  148. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  149. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  150. *
  151. */
  152. //left.css('width', parent.width() - right.outerWidth());
  153. //left.css('width', parent.width() - right.outerWidth());
  154. const percent = 100 - right.outerWidth() /parent.width() * 100;
  155. left.css('width', percent + '%');
  156. } else {
  157. right.hide();
  158. left.css('width', '100%');
  159. }
  160. };
  161. if (!tab.hasClass('active')) {
  162. $('a', '.side-menu').removeClass('active');
  163. $('.tab-content .tab-select-show').removeClass('active');
  164. tab.addClass('active');
  165. tabPanel.addClass('active');
  166. showTools(tab.hasClass('active'));
  167. } else {
  168. tab.removeClass('active');
  169. tabPanel.removeClass('active');
  170. showTools(tab.hasClass('active'));
  171. }
  172. gclSpread.refresh();
  173. leafXmjSpread.refresh();
  174. });
  175. $.subMenu({
  176. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  177. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  178. key: 'menu.1.0.0',
  179. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  180. callback: function (info) {
  181. if (info.mini) {
  182. $('.panel-title').addClass('fluid');
  183. $('#sub-menu').removeClass('panel-sidebar');
  184. } else {
  185. $('.panel-title').removeClass('fluid');
  186. $('#sub-menu').addClass('panel-sidebar');
  187. }
  188. autoFlashHeight();
  189. gclSpread.refresh();
  190. leafXmjSpread.refresh();
  191. }
  192. });
  193. $.divResizer({
  194. select: '#main-resize',
  195. callback: function () {
  196. gclSpread.refresh();
  197. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  198. $(".sp-wrap").height(bcontent-30);
  199. leafXmjSpread.refresh();
  200. }
  201. });
  202. $.divResizer({
  203. select: '#right-spr',
  204. callback: function () {
  205. gclSpread.refresh();
  206. leafXmjSpread.refresh();
  207. }
  208. });
  209. });