ledger_gather.js 14 KB

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