ledger_gather.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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, row, col, defaultColor) {
  33. return data
  34. ? $('#compare-tag')[0].checked && data.compare_differ
  35. ? '#f8d7da'
  36. : (data.differ ? '#FFE699' : defaultColor)
  37. : defaultColor;
  38. //return data && data.differ ? '#FFE699' : defaultColor;
  39. }
  40. });
  41. const gclSheet = gclSpread.getActiveSheet();
  42. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  43. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), {
  44. cols: [
  45. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  46. {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  47. {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  48. {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  49. {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 100, formatter: '@'},
  50. {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  51. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  52. {title: '图册号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 120, formatter: '@'},
  53. ],
  54. emptyRows: 0,
  55. headRows: 1,
  56. headRowHeight: [32],
  57. defaultRowHeight: 21,
  58. headerFont: '12px 微软雅黑',
  59. font: '12px 微软雅黑',
  60. readOnly: true,
  61. });
  62. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  63. let gclGatherData;
  64. // 获取项目节数据
  65. function loadLeafXmjData(iGclRow) {
  66. const gcl = gclGatherData[iGclRow];
  67. if (gcl) {
  68. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  69. } else {
  70. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  71. }
  72. }
  73. // 标红显示 签约-台账≠0
  74. function checkCompareData() {
  75. const sheet = gclSheet;
  76. const bCompare = $('#compare-tag')[0].checked;
  77. SpreadJsObj.beginMassOperation(gclSheet);
  78. for (let iRow = 0, iLength = gclSheet.getRowCount(); iRow < iLength; iRow++) {
  79. const node = gclSheet.zh_data[iRow];
  80. if (node) {
  81. const bDiffer = node.compare_qty ? !checkZero(Math.abs(node.compare_qty)) : !checkZero(Math.abs(node.compare_tp));
  82. const color = bCompare && bDiffer ? '#f8d7da' : '';
  83. sheet.getRange(iRow, -1, 1, -1).backColor(color);
  84. }
  85. }
  86. SpreadJsObj.endMassOperation(gclSheet);
  87. }
  88. // 切换清单行,读取所属项目节数据
  89. gclSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  90. const iNewRow = info.newSelections[0].row;
  91. if (!info.oldSelections || iNewRow !== info.oldSelections[0].row) {
  92. loadLeafXmjData(iNewRow);
  93. }
  94. });
  95. function generateChapterHtml(data) {
  96. const html = [];
  97. if (data) {
  98. for (const d of data) {
  99. if (['1000', '1100', '1200', '1300'].indexOf(d.code) >= 0) {
  100. if (checkZero(d.total_price) && checkZero(d.deal_bills_tp)) {
  101. continue;
  102. }
  103. }
  104. html.push('<tr>');
  105. if (d.code) {
  106. html.push('<td>', d.code, '</td>');
  107. html.push('<td>', d.name, '</td>');
  108. } else {
  109. html.push('<td colspan="2">', d.name, '</td>');
  110. }
  111. html.push('<td class="text-right">', d.deal_bills_tp ? d.deal_bills_tp : '', '</td>');
  112. html.push('<td class="text-right">', d.total_price ? d.total_price : '', '</td>');
  113. html.push('<td class="text-right">', d.compare_tp ? d.compare_tp : '', '</td>');
  114. html.push('</tr>');
  115. }
  116. }
  117. $('#chapter-list').html(html.join(''));
  118. }
  119. postData(window.location.pathname + '/load', {}, function (data) {
  120. gclGatherModel.loadLedgerData(data.bills);
  121. gclGatherModel.loadPosData(data.pos);
  122. gclGatherModel.loadDealBillsData(data.dealBills);
  123. gclGatherData = gclGatherModel.gatherGclData();
  124. gclGatherModel.checkDiffer(gclGatherData);
  125. for (const gcl of gclGatherData) {
  126. gcl.compare_qty = ZhCalc.sub(gcl.deal_bills_qty, gcl.quantity);
  127. gcl.compare_tp = ZhCalc.sub(gcl.deal_bills_tp, gcl.total_price);
  128. gcl.compare_differ = !checkZero(gcl.compare_qty) || !checkZero(gcl.compare_tp);
  129. }
  130. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  131. checkCompareData();
  132. loadLeafXmjData(0);
  133. const chapterData = gclGatherModel.gatherChapterData(chapter, ['total_price']);
  134. for (const c of chapterData) {
  135. c.compare_tp = ZhCalc.sub(c.deal_bills_tp, c.total_price);
  136. }
  137. generateChapterHtml(chapterData);
  138. }, null, true);
  139. $('#compare-tag').click(() => {
  140. SpreadJsObj.reLoadSheetData(gclSheet);
  141. });
  142. // 展开收起附件
  143. $('a', '.right-nav').bind('click', function () {
  144. const tab = $(this), tabPanel = $(tab.attr('content'));
  145. const showTools = function (show) {
  146. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  147. if (show) {
  148. right.show();
  149. autoFlashHeight();
  150. /**
  151. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  152. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  153. * 故需要通过最终的parent.width再计算一次left.width
  154. *
  155. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  156. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  157. *
  158. */
  159. //left.css('width', parent.width() - right.outerWidth());
  160. //left.css('width', parent.width() - right.outerWidth());
  161. const percent = 100 - right.outerWidth() /parent.width() * 100;
  162. left.css('width', percent + '%');
  163. } else {
  164. right.hide();
  165. left.css('width', '100%');
  166. }
  167. };
  168. if (!tab.hasClass('active')) {
  169. $('a', '.side-menu').removeClass('active');
  170. $('.tab-content .tab-select-show').removeClass('active');
  171. tab.addClass('active');
  172. tabPanel.addClass('active');
  173. showTools(tab.hasClass('active'));
  174. } else {
  175. tab.removeClass('active');
  176. tabPanel.removeClass('active');
  177. showTools(tab.hasClass('active'));
  178. }
  179. gclSpread.refresh();
  180. leafXmjSpread.refresh();
  181. });
  182. $.subMenu({
  183. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  184. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  185. key: 'menu.1.0.0',
  186. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  187. callback: function (info) {
  188. if (info.mini) {
  189. $('.panel-title').addClass('fluid');
  190. $('#sub-menu').removeClass('panel-sidebar');
  191. } else {
  192. $('.panel-title').removeClass('fluid');
  193. $('#sub-menu').addClass('panel-sidebar');
  194. }
  195. autoFlashHeight();
  196. gclSpread.refresh();
  197. leafXmjSpread.refresh();
  198. }
  199. });
  200. $.divResizer({
  201. select: '#main-resize',
  202. callback: function () {
  203. gclSpread.refresh();
  204. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  205. $(".sp-wrap").height(bcontent-30);
  206. leafXmjSpread.refresh();
  207. }
  208. });
  209. $.divResizer({
  210. select: '#right-spr',
  211. callback: function () {
  212. gclSpread.refresh();
  213. leafXmjSpread.refresh();
  214. }
  215. });
  216. $('#exportExcel').click(function () {
  217. const data = [];
  218. const setting = {
  219. cols: [
  220. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  221. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  222. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  223. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  224. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  225. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 80, type: 'Number'},
  226. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
  227. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  228. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  229. {title: '签约-台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'compare_qty', hAlign: 2, width: 80, type: 'Number'},
  230. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'compare_tp', hAlign: 2, width: 80, type: 'Number'},
  231. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  232. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  233. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  234. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  235. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  236. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  237. ],
  238. headRows: 2,
  239. headRowHeight: [25, 25],
  240. defaultRowHeight: 21,
  241. headerFont: 'bold 10px 微软雅黑',
  242. font: '10px 微软雅黑'
  243. };
  244. if (!gclSheet.zh_data || gclSheet.zh_data.length === 0) return;
  245. for (const gcl of gclSheet.zh_data) {
  246. data.push({
  247. b_code: gcl.b_code, name: gcl.name, unit: gcl.unit,
  248. unit_price: gcl.unit_price,
  249. deal_bills_qty: gcl.deal_bills_qty, deal_bills_tp: gcl.deal_bills_tp,
  250. quantity: gcl.quantity, total_price: gcl.total_price,
  251. compare_qty: gcl.compare_qty, compare_tp: gcl.compare_tp,
  252. });
  253. if (gcl.leafXmjs && gcl.leafXmjs.length > 0) {
  254. for (const xmj of gcl.leafXmjs) {
  255. data.push({
  256. code: xmj.code,
  257. quantity: xmj.quantity,
  258. dwgc: xmj.dwgc, fbgc: xmj.fbgc, fxgc: xmj.fxgc,
  259. jldy: xmj.jldy, bwmx: xmj.bwmx, drawing_code: xmj.drawing_code,
  260. });
  261. }
  262. }
  263. }
  264. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('h2')[0].innerHTML + "-清单汇总.xlsx");
  265. });
  266. });