revise_gcl_compare.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2020/10/28
  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. let compareTag = $('input[name=compareTag]:checked').val();
  34. showTools(true);
  35. autoFlashHeight();
  36. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  37. const gclSpreadSetting = {
  38. cols: [
  39. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 120, formatter: '@'},
  40. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  41. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  42. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  43. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 80, type: 'Number'},
  44. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
  45. {title: '台账修订|数量', colSpan: '2|1', rowSpan: '1|1', field: 'new_quantity', hAlign: 2, width: 80, type: 'Number'},
  46. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'new_total_price', hAlign: 2, width: 80, type: 'Number'},
  47. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'org_quantity', hAlign: 2, width: 80, type: 'Number'},
  48. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'org_total_price', hAlign: 2, width: 80, type: 'Number'},
  49. ],
  50. emptyRows: 0,
  51. headRows: 2,
  52. headRowHeight: [25, 25],
  53. headColWidth: [30],
  54. defaultRowHeight: 21,
  55. headerFont: '12px 微软雅黑',
  56. font: '12px 微软雅黑',
  57. readOnly: true,
  58. localCache: {
  59. key: 'ledger-gather-gcl',
  60. colWidth: true,
  61. },
  62. getColor: function (sheet, data, row, col, defaultColor) {
  63. if (!data) return '#ffffff';
  64. // if ((col.field === 'deal_bills_qty' || col.field === 'deal_bills_tp') && data.deal_differ_qty)
  65. // return '#f8d7da';
  66. // if ((col.field === 'org_quantity' || col.field === 'org_total_price') && data.differ_qty)
  67. // return '#f8d7da';
  68. if (compareTag === 'deal' && data.deal_differ_qty) return '#f8d7da';
  69. if (compareTag === 'org' && data.differ_qty) return '#f8d7da';
  70. return data.differ ? '#FFE699' : '#ffffff';
  71. }
  72. };
  73. if (thousandth) sjsSettingObj.setTpThousandthFormat(gclSpreadSetting);
  74. SpreadJsObj.initSheet(gclSpread.getActiveSheet(), gclSpreadSetting);
  75. const gclSheet = gclSpread.getActiveSheet();
  76. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  77. const leafXmjSpreadSetting = {
  78. cols: [
  79. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  80. {title: '修订台账|数量', colSpan: '1', rowSpan: '1|1', field: 'new_quantity', hAlign: 2, width: 80, type: 'Number'},
  81. {title: '原台账|数量', colSpan: '1', rowSpan: '1|1', field: 'org_quantity', hAlign: 2, width: 80, type: 'Number'},
  82. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  83. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  84. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 100, formatter: '@'},
  85. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  86. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  87. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 120, formatter: '@'},
  88. ],
  89. emptyRows: 0,
  90. headRows: 1,
  91. headRowHeight: [25, 25],
  92. headColWidth: [30],
  93. defaultRowHeight: 21,
  94. headerFont: '12px 微软雅黑',
  95. font: '12px 微软雅黑',
  96. readOnly: true,
  97. localCache: {
  98. key: 'ledger-gather-leafXmj',
  99. colWidth: true,
  100. },
  101. };
  102. if (!isTz) leafXmjSpreadSetting.cols.splice(1, 2);
  103. if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
  104. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  105. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  106. const gatherLeafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-gather-spread')[0]);
  107. const gatherLeafXmjSpreadSetting = {
  108. cols: [
  109. {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@', visible: false},
  110. {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@', visible: false},
  111. {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 100, formatter: '@', visible: false},
  112. {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 100, formatter: '@', visible: false},
  113. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  114. {title: '修订台账', colSpan: '1', rowSpan: '1', field: 'new_quantity', hAlign: 2, width: 80, type: 'Number'},
  115. {title: '原台账', colSpan: '1', rowSpan: '1', field: 'org_quantity', hAlign: 2, width: 80, type: 'Number'},
  116. ],
  117. emptyRows: 0,
  118. headRows: 1,
  119. headRowHeight: [32],
  120. headColWidth: [30],
  121. defaultRowHeight: 21,
  122. headerFont: '12px 微软雅黑',
  123. font: '12px 微软雅黑',
  124. readOnly: true,
  125. localCache: {
  126. key: 'ledger-gather-leafXmj',
  127. colWidth: true,
  128. },
  129. };
  130. if (thousandth) sjsSettingObj.setTpThousandthFormat(gatherLeafXmjSpreadSetting);
  131. const gatherLeafXmjSheet = gatherLeafXmjSpread.getActiveSheet();
  132. SpreadJsObj.initSheet(gatherLeafXmjSheet, gatherLeafXmjSpreadSetting);
  133. let gclData = [];
  134. // 获取项目节数据
  135. function loadLeafXmjData(iGclRow) {
  136. const gcl = gclData[iGclRow];
  137. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  138. if (gcl) {
  139. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  140. } else {
  141. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  142. }
  143. }
  144. function loadGatherLeafXmjData(iGclRow) {
  145. const gcl = iGclRow ? gclData[iGclRow] : SpreadJsObj.getSelectObject(gclSheet);
  146. SpreadJsObj.resetTopAndSelect(gatherLeafXmjSheet);
  147. if (gcl) {
  148. SpreadJsObj.loadSheetData(gatherLeafXmjSheet, SpreadJsObj.DataType.Data, gcl.gatherLeafXmjs);
  149. } else {
  150. SpreadJsObj.loadSheetData(gatherLeafXmjSheet, SpreadJsObj.DataType.Data, []);
  151. }
  152. }
  153. // 切换清单行,读取所属项目节数据
  154. gclSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  155. const iNewRow = info.newSelections[0].row;
  156. if (!info.oldSelections || iNewRow !== info.oldSelections[0].row) {
  157. loadLeafXmjData(iNewRow);
  158. loadGatherLeafXmjData(iNewRow);
  159. }
  160. });
  161. function generateChapterHtml(data) {
  162. const html = [];
  163. if (data) {
  164. for (const d of data) {
  165. if (['1000', '1100', '1200', '1300'].indexOf(d.code) >= 0) {
  166. if (checkZero(d.new_total_price) && checkZero(d.org_total_price) && checkZero(d.deal_bills_tp)) {
  167. continue;
  168. }
  169. }
  170. html.push('<tr>');
  171. if (d.code) {
  172. html.push('<td>', d.code, '</td>');
  173. html.push('<td>', d.name, '</td>');
  174. } else {
  175. html.push('<td colspan="2">', d.name, '</td>');
  176. }
  177. html.push('<td class="text-right">', d.deal_bills_tp ? d.deal_bills_tp : '', '</td>');
  178. html.push('<td class="text-right">', d.new_total_price ? d.new_total_price : '', '</td>');
  179. html.push('<td class="text-right">', d.org_total_price ? d.org_total_price : '', '</td>');
  180. html.push('</tr>');
  181. }
  182. }
  183. $('#chapter-list').html(html.join(''));
  184. }
  185. postData('load', {filter: 'bills;pos;reviseBills;revisePos;dealBills;spec;price'}, function (data) {
  186. const setting = {
  187. tree: {
  188. id: 'ledger_id',
  189. pid: 'ledger_pid',
  190. order: 'order',
  191. level: 'level',
  192. rootId: -1,
  193. keys: ['id', 'tender_id', 'ledger_id'],
  194. stageId: 'id',
  195. },
  196. pos: { id: 'id', ledgerId: 'lid' },
  197. billsFields: ['quantity', 'total_price'],
  198. posFields: ['quantity'],
  199. chapterFields: ['total_price'],
  200. };
  201. gclCompareModel.init(gclData, chapter, data.spec);
  202. setting.prefix = 'new_';
  203. gclCompareModel.gatherReviseLedgerData(data.reviseBills, data.revisePos, setting, data.price, decimal);
  204. setting.prefix = 'org_';
  205. gclCompareModel.gatherLedgerData(data.bills, data.pos, setting);
  206. gclCompareModel.gatherDealBills(data.dealBills);
  207. gclCompareModel.checkDiffer();
  208. gclCompareModel.reGatherLeafXmj();
  209. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclData);
  210. loadLeafXmjData(0);
  211. loadGatherLeafXmjData(0);
  212. const chapterData = gclCompareModel.chapterData();
  213. generateChapterHtml(chapterData);
  214. }, null, true);
  215. // 展开收起附件
  216. $('a', '.right-nav').bind('click', function () {
  217. const tab = $(this), tabPanel = $(tab.attr('content'));
  218. if (!tab.hasClass('active')) {
  219. $('a', '.side-menu').removeClass('active');
  220. $('.tab-content .tab-select-show').removeClass('active');
  221. tab.addClass('active');
  222. tabPanel.addClass('active');
  223. showTools(tab.hasClass('active'));
  224. } else {
  225. tab.removeClass('active');
  226. tabPanel.removeClass('active');
  227. showTools(tab.hasClass('active'));
  228. }
  229. gclSpread.refresh();
  230. leafXmjSpread.refresh();
  231. gatherLeafXmjSpread.refresh();
  232. });
  233. // 下部设置显示相关
  234. $('a', '[name=pos-tab]').click(function() {
  235. const relaTab = this.getAttribute('href');
  236. const optionTab = $('#optionTab').children();
  237. for (const ot of optionTab) {
  238. if (ot.getAttribute('rela-tab') === relaTab) {
  239. $(ot).show();
  240. } else {
  241. $(ot).hide();
  242. }
  243. }
  244. });
  245. $('[name=gather-xmj]').change(function() {
  246. const checkOption = $('[name=gather-xmj]:checked');
  247. if (checkOption.length === 0) {
  248. toastr.warning('请至少选择一个汇总条件');
  249. return;
  250. }
  251. const fields = [];
  252. for (const co of checkOption) {
  253. fields.push(co.value);
  254. }
  255. for (const col of gatherLeafXmjSpreadSetting.cols) {
  256. if (col.formatter !== '@') continue;
  257. col.visible = col.type === 'Number' || fields.indexOf(col.field) >= 0;
  258. }
  259. gclCompareModel.reGatherLeafXmj(fields);
  260. SpreadJsObj.refreshColumnVisible(gatherLeafXmjSheet);
  261. loadGatherLeafXmjData();
  262. });
  263. $.subMenu({
  264. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  265. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  266. key: 'menu.1.0.0',
  267. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  268. callback: function (info) {
  269. if (info.mini) {
  270. $('.panel-title').addClass('fluid');
  271. $('#sub-menu').removeClass('panel-sidebar');
  272. } else {
  273. $('.panel-title').removeClass('fluid');
  274. $('#sub-menu').addClass('panel-sidebar');
  275. }
  276. autoFlashHeight();
  277. gclSpread.refresh();
  278. leafXmjSpread.refresh();
  279. gatherLeafXmjSpread.refresh();
  280. }
  281. });
  282. $.divResizer({
  283. select: '#main-resize',
  284. callback: function () {
  285. gclSpread.refresh();
  286. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  287. $(".sp-wrap").height(bcontent-30);
  288. leafXmjSpread.refresh();
  289. gatherLeafXmjSpread.refresh();
  290. }
  291. });
  292. $('input[name=compareTag]').change(() => {
  293. compareTag = $('input[name=compareTag]:checked').val();
  294. SpreadJsObj.reLoadSheetData(gclSheet);
  295. });
  296. });