ledger_gather.js 14 KB

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