ledger_gather.js 14 KB

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