revise_gcl_compare.js 14 KB

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