ledger_gather.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. ? spreadColor.gcl.calc_differ
  65. : (data.differ ? spreadColor.gcl.differ : defaultColor)
  66. : defaultColor;
  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 (!isTz) leafXmjSpreadSetting.cols.splice(1, 1);
  98. if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
  99. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  100. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  101. const gatherLeafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-gather-spread')[0]);
  102. const gatherLeafXmjSpreadSetting = {
  103. cols: [
  104. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  105. {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  106. {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  107. {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  108. {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 100, formatter: '@'},
  109. {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  110. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  111. {title: '图册号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 120, formatter: '@'},
  112. ],
  113. emptyRows: 0,
  114. headRows: 1,
  115. headRowHeight: [32],
  116. headColWidth: [30],
  117. defaultRowHeight: 21,
  118. headerFont: '12px 微软雅黑',
  119. font: '12px 微软雅黑',
  120. readOnly: true,
  121. localCache: {
  122. key: 'ledger-gather-leafXmj',
  123. colWidth: true,
  124. },
  125. };
  126. if (!isTz) gatherLeafXmjSpreadSetting.cols.splice(1, 1);
  127. if (thousandth) sjsSettingObj.setTpThousandthFormat(gatherLeafXmjSpreadSetting);
  128. const gatherLeafXmjSheet = gatherLeafXmjSpread.getActiveSheet();
  129. SpreadJsObj.initSheet(gatherLeafXmjSheet, gatherLeafXmjSpreadSetting);
  130. let gclGatherData;
  131. // 获取项目节数据
  132. function loadLeafXmjData(iGclRow) {
  133. const gcl = iGclRow ? gclGatherData[iGclRow] : SpreadJsObj.getSelectObject(gclSheet);
  134. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  135. if (gcl) {
  136. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  137. } else {
  138. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  139. }
  140. }
  141. function loadGatherLeafXmjData(iGclRow) {
  142. const gcl = iGclRow ? gclGatherData[iGclRow] : SpreadJsObj.getSelectObject(gclSheet);
  143. SpreadJsObj.resetTopAndSelect(gatherLeafXmjSheet);
  144. console.log(gcl.gatherLeafXmjs);
  145. if (gcl) {
  146. SpreadJsObj.loadSheetData(gatherLeafXmjSheet, SpreadJsObj.DataType.Data, gcl.gatherLeafXmjs);
  147. } else {
  148. SpreadJsObj.loadSheetData(gatherLeafXmjSheet, SpreadJsObj.DataType.Data, []);
  149. }
  150. }
  151. // 标红显示 签约-台账≠0
  152. function checkCompareData() {
  153. const sheet = gclSheet;
  154. const bCompare = $('#compare-tag')[0].checked;
  155. SpreadJsObj.beginMassOperation(gclSheet);
  156. for (let iRow = 0, iLength = gclSheet.getRowCount(); iRow < iLength; iRow++) {
  157. const node = gclSheet.zh_data[iRow];
  158. if (node) {
  159. const bDiffer = node.compare_qty ? !checkZero(Math.abs(node.compare_qty)) : !checkZero(Math.abs(node.compare_tp));
  160. const color = bCompare && bDiffer ? '#f8d7da' : '';
  161. sheet.getRange(iRow, -1, 1, -1).backColor(color);
  162. }
  163. }
  164. SpreadJsObj.endMassOperation(gclSheet);
  165. }
  166. // 切换清单行,读取所属项目节数据
  167. gclSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  168. const iNewRow = info.newSelections[0].row;
  169. if (!info.oldSelections || iNewRow !== info.oldSelections[0].row) {
  170. loadLeafXmjData(iNewRow);
  171. loadGatherLeafXmjData(iNewRow);
  172. }
  173. });
  174. function generateChapterHtml(data) {
  175. const html = [];
  176. if (data) {
  177. for (const d of data) {
  178. if (['1000', '1100', '1200', '1300'].indexOf(d.code) >= 0) {
  179. if (checkZero(d.total_price) && checkZero(d.deal_bills_tp)) {
  180. continue;
  181. }
  182. }
  183. html.push('<tr>');
  184. if (d.code) {
  185. html.push('<td>', d.code, '</td>');
  186. html.push('<td>', d.name, '</td>');
  187. } else {
  188. html.push('<td colspan="2">', d.name, '</td>');
  189. }
  190. html.push('<td class="text-right">', d.deal_bills_tp ? d.deal_bills_tp : '', '</td>');
  191. html.push('<td class="text-right">', d.total_price ? d.total_price : '', '</td>');
  192. html.push('<td class="text-right">', d.compare_tp ? d.compare_tp : '', '</td>');
  193. html.push('</tr>');
  194. }
  195. }
  196. $('#chapter-list').html(html.join(''));
  197. }
  198. postData(window.location.pathname + '/load', {}, function (data) {
  199. gclGatherModel.loadLedgerData(data.bills);
  200. gclGatherModel.loadPosData(data.pos);
  201. gclGatherModel.loadDealBillsData(data.dealBills);
  202. gclGatherData = gclGatherModel.gatherGclData();
  203. gclGatherModel.checkDiffer(gclGatherData);
  204. gclGatherModel.reGatherLeafXmj();
  205. for (const gcl of gclGatherData) {
  206. gcl.compare_qty = ZhCalc.sub(gcl.quantity, gcl.deal_bills_qty);
  207. gcl.compare_tp = ZhCalc.sub(gcl.total_price, gcl.deal_bills_tp);
  208. gcl.compare_differ = !checkZero(gcl.compare_qty) || !checkZero(gcl.compare_tp);
  209. }
  210. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  211. checkCompareData();
  212. loadLeafXmjData(0);
  213. loadGatherLeafXmjData(0);
  214. const chapterData = gclGatherModel.gatherChapterData(chapter, data.spec, ['total_price']);
  215. for (const c of chapterData) {
  216. c.compare_tp = ZhCalc.sub(c.total_price, c.deal_bills_tp);
  217. }
  218. generateChapterHtml(chapterData);
  219. }, null, true);
  220. $('#compare-tag').click(() => {
  221. // const rows = [];
  222. // for (let i = 0; i< gclSheet.getRowCount(); ++i) {
  223. // rows.push(i);
  224. // }
  225. // SpreadJsObj.reloadRowsBackColor(gclSheet, rows);
  226. SpreadJsObj.reLoadSheetData(gclSheet);
  227. });
  228. const searchBills = $.listSearch({
  229. selector: '#search',
  230. searchSpread: gclSpread,
  231. searchRangeStr: '清单编号/名称',
  232. resultSpreadSetting: {
  233. cols: [
  234. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  235. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  236. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  237. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  238. {title: '台账数量', field: 'quantity', hAlign: 2, width: 60},
  239. {title: '台账金额', field: 'total_price', hAlign: 2, width: 60},
  240. ],
  241. emptyRows: 0,
  242. headRows: 1,
  243. headRowHeight: [32],
  244. headColWidth: [30],
  245. defaultRowHeight: 21,
  246. headerFont: '12px 微软雅黑',
  247. font: '12px 微软雅黑',
  248. selectedBackColor: '#fffacd',
  249. readOnly: true,
  250. },
  251. check: function(data, keyword) {
  252. return !keyword ||
  253. (data.b_code && data.b_code.indexOf(keyword) > -1) ||
  254. (data.name && data.name.indexOf(keyword) > -1);
  255. },
  256. afterLocated: function () {
  257. loadLeafXmjData();
  258. loadGatherLeafXmjData();
  259. },
  260. calcSum: function (result) {
  261. const sum = { name: '合计', searchIndex: -1 };
  262. for (const r of result) {
  263. sum.quantity = ZhCalc.add(r.quantity, sum.quantity);
  264. sum.total_price = ZhCalc.add(r.total_price, sum.total_price);
  265. }
  266. return sum;
  267. }
  268. });
  269. // 展开收起附件
  270. $('a', '#side-menu').bind('click', function (e) {
  271. e.preventDefault();
  272. const tab = $(this), tabPanel = $(tab.attr('content'));
  273. if (!tab.hasClass('active')) {
  274. $('a', '#side-menu').removeClass('active');
  275. $('#right-view .tab-content .tab-pane.active').removeClass('active');
  276. tab.addClass('active');
  277. tabPanel.addClass('active');
  278. showTools(tab.hasClass('active'));
  279. if (tab.attr('content') === '#search') searchBills.spread.refresh();
  280. } else {
  281. tab.removeClass('active');
  282. tabPanel.removeClass('active');
  283. showTools(tab.hasClass('active'));
  284. }
  285. gclSpread.refresh();
  286. leafXmjSpread.refresh();
  287. });
  288. $('[name=gather-xmj]').change(function() {
  289. const checkOption = $('[name=gather-xmj]:checked');
  290. if (checkOption.length === 0) {
  291. toastr.warning('请至少选择一个汇总条件');
  292. return;
  293. }
  294. const fields = [];
  295. for (const co of checkOption) {
  296. fields.push(co.value);
  297. }
  298. gclGatherModel.reGatherLeafXmj(fields);
  299. loadGatherLeafXmjData();
  300. });
  301. $.subMenu({
  302. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  303. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  304. key: 'menu.1.0.0',
  305. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  306. callback: function (info) {
  307. if (info.mini) {
  308. $('.panel-title').addClass('fluid');
  309. $('#sub-menu').removeClass('panel-sidebar');
  310. } else {
  311. $('.panel-title').removeClass('fluid');
  312. $('#sub-menu').addClass('panel-sidebar');
  313. }
  314. autoFlashHeight();
  315. gclSpread.refresh();
  316. leafXmjSpread.refresh();
  317. gatherLeafXmjSpread.refresh();
  318. }
  319. });
  320. $.divResizer({
  321. select: '#main-resize',
  322. callback: function () {
  323. gclSpread.refresh();
  324. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  325. $(".sp-wrap").height(bcontent-30);
  326. leafXmjSpread.refresh();
  327. gatherLeafXmjSpread.refresh();
  328. }
  329. });
  330. $.divResizer({
  331. select: '#right-spr',
  332. callback: function () {
  333. gclSpread.refresh();
  334. leafXmjSpread.refresh();
  335. gatherLeafXmjSpread.refresh();
  336. }
  337. });
  338. $('#exportExcel').click(function () {
  339. const data = [];
  340. const setting = {
  341. cols: [
  342. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  343. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  344. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  345. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  346. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  347. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 80, type: 'Number'},
  348. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
  349. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  350. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  351. {title: '台账-签约|数量', colSpan: '2|1', rowSpan: '1|1', field: 'compare_qty', hAlign: 2, width: 80, type: 'Number'},
  352. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'compare_tp', hAlign: 2, width: 80, type: 'Number'},
  353. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  354. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  355. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  356. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  357. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  358. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  359. ],
  360. headRows: 2,
  361. headRowHeight: [25, 25],
  362. defaultRowHeight: 21,
  363. headerFont: 'bold 10px 微软雅黑',
  364. font: '10px 微软雅黑'
  365. };
  366. if (!gclSheet.zh_data || gclSheet.zh_data.length === 0) return;
  367. for (const gcl of gclSheet.zh_data) {
  368. data.push({
  369. b_code: gcl.b_code, name: gcl.name, unit: gcl.unit,
  370. unit_price: gcl.unit_price,
  371. deal_bills_qty: gcl.deal_bills_qty, deal_bills_tp: gcl.deal_bills_tp,
  372. quantity: gcl.quantity, total_price: gcl.total_price,
  373. compare_qty: gcl.compare_qty, compare_tp: gcl.compare_tp,
  374. });
  375. if (gcl.leafXmjs && gcl.leafXmjs.length > 0) {
  376. for (const xmj of gcl.leafXmjs) {
  377. data.push({
  378. code: xmj.code,
  379. quantity: xmj.quantity,
  380. dwgc: xmj.dwgc, fbgc: xmj.fbgc, fxgc: xmj.fxgc,
  381. jldy: xmj.jldy, bwmx: xmj.bwmx, drawing_code: xmj.drawing_code,
  382. });
  383. }
  384. }
  385. }
  386. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "-清单对比.xlsx");
  387. });
  388. });