measure_compare.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. 'use strict';
  2. /**
  3. * 多期比较
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const billsSpreadSetting = {
  10. baseCols: [
  11. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  12. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  13. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  14. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
  15. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  16. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', },
  17. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', },
  18. ],
  19. extraCols: [
  20. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
  21. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
  22. ],
  23. emptyRows: 3,
  24. headRows: 2,
  25. headRowHeight: [25, 25],
  26. headerFont: '12px 微软雅黑',
  27. font: '12px 微软雅黑',
  28. defaultRowHeight: 21,
  29. readOnly: true,
  30. selectedBackColor: '#fffacd',
  31. };
  32. const posSpreadSetting = {
  33. baseCols: [
  34. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  35. {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 60},
  36. ],
  37. extraCols: [
  38. {title: '%s数量', colSpan: '1', rowSpan: '1', field: '{%s}_qty{%d}', hAlign: 2, width: 60},
  39. ],
  40. emptyRows: 3,
  41. headRows: 1,
  42. headRowHeight: [32],
  43. headColWidth: [30],
  44. defaultRowHeight: 21,
  45. headerFont: '12px 微软雅黑',
  46. font: '12px 微软雅黑',
  47. readOnly: true,
  48. selectedBackColor: '#fffacd',
  49. };
  50. const gclSpreadSetting = {
  51. baseCols: [
  52. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  53. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  54. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  55. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  56. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 60, type: 'Number'},
  57. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 60, type: 'Number'},
  58. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  59. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  60. ],
  61. extraCols: [
  62. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
  63. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
  64. ],
  65. emptyRows: 0,
  66. headRows: 2,
  67. headRowHeight: [25, 25],
  68. headColWidth: [30],
  69. defaultRowHeight: 21,
  70. headerFont: '12px 微软雅黑',
  71. font: '12px 微软雅黑',
  72. readOnly: true,
  73. };
  74. const leafXmjSpreadSetting = {
  75. baseCols: [
  76. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  77. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  78. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  79. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  80. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  81. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  82. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  83. {title: '台账数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  84. ],
  85. extraCols: [
  86. {title: '%s数量', colSpan: '1', rowSpan: '2', field: '{%s}_qty{%d}', hAlign: 2, width: 60},
  87. ],
  88. emptyRows: 0,
  89. headRows: 2,
  90. headRowHeight: [25, 25],
  91. headColWidth: [30],
  92. defaultRowHeight: 21,
  93. headerFont: '12px 微软雅黑',
  94. font: '12px 微软雅黑',
  95. readOnly: true,
  96. };
  97. function initSpreadSettingWithRoles(compareRoles) {
  98. function setSpreadSettingCols(setting, fieldSufs, Roles) {
  99. function addExtraCols(fieldSuf, Role) {
  100. const sourceType = $('[name=compare-data]:checked').val();
  101. for (const ec of setting.extraCols) {
  102. const col = JSON.parse(JSON.stringify(ec));
  103. col.title = _.replace(col.title, '%s', Role);
  104. col.field = _.replace(_.replace(col.field, '{%s}', sourceType), '{%d}', fieldSuf);
  105. setting.cols.push(col);
  106. }
  107. }
  108. setting.cols = [];
  109. for (const col of setting.baseCols) {
  110. setting.cols.push(col);
  111. }
  112. setting.frozenColCount = setting.baseCols.length;
  113. setting.frozenLineColor = '#93b5e4';
  114. for (const index in fieldSufs) {
  115. addExtraCols(fieldSufs[index], Roles[index]);
  116. }
  117. }
  118. const fieldSufs = [], roles = [], trs = $('tr[stage-id]');
  119. for (let r of compareRoles) {
  120. if (r > 0) {
  121. const tr = trs[r-1];
  122. if (tr) {
  123. fieldSufs.push(r + '');
  124. roles.push(tr.children[0].textContent);
  125. }
  126. }
  127. }
  128. setSpreadSettingCols(billsSpreadSetting, fieldSufs, roles);
  129. setSpreadSettingCols(posSpreadSetting, fieldSufs, roles);
  130. setSpreadSettingCols(gclSpreadSetting, fieldSufs, roles);
  131. setSpreadSettingCols(leafXmjSpreadSetting, fieldSufs, roles);
  132. }
  133. function calculateStageLedgerData(datas) {
  134. for (const d of datas) {
  135. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  136. d.gather_tp = ZhCalc.sum([d.contract_tp, d.qc_tp, d.pc_tp]);
  137. // d.pc_tp = ZhCalc.add(d.qc_tp, d.qc_pc_tp);
  138. // d.contract_tp = ZhCalc.add(d.contract_tp, d.contract_pc_tp);
  139. }
  140. }
  141. function calculateStagePosData(datas) {
  142. for (const d of datas) {
  143. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  144. }
  145. }
  146. $(document).ready(() => {
  147. autoFlashHeight();
  148. initSpreadSettingWithRoles([]);
  149. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  150. const billsSheet = billsSpread.getActiveSheet();
  151. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  152. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  153. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  154. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  155. const posSheet = posSpread.getActiveSheet();
  156. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  157. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  158. let gclGatherData;
  159. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  160. const gclSheet = gclSpread.getActiveSheet();
  161. sjsSettingObj.setFxTreeStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  162. if (thousandth) sjsSettingObj.setTpThousandthFormat(gclSpreadSetting);
  163. SpreadJsObj.initSheet(gclSheet, gclSpreadSetting);
  164. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  165. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  166. if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
  167. SpreadJsObj.initSheet(leafXmjSheet, leafXmjSpreadSetting);
  168. $.subMenu({
  169. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  170. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  171. key: 'menu.1.0.0',
  172. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  173. callback: function (info) {
  174. if (info.mini) {
  175. $('.panel-title').addClass('fluid');
  176. $('#sub-menu').removeClass('panel-sidebar');
  177. } else {
  178. $('.panel-title').removeClass('fluid');
  179. $('#sub-menu').addClass('panel-sidebar');
  180. }
  181. autoFlashHeight();
  182. billsSpread.refresh();
  183. posSpread.refresh();
  184. }
  185. });
  186. // 上下窗口resizer
  187. $.divResizer({
  188. select: '#main-resize',
  189. callback: function () {
  190. billsSpread.refresh();
  191. let bcontent = $("#main-bottom").length > 0 ? $("#main-bottom").height() : 0;
  192. $("#pos-spread").height(bcontent-30);
  193. posSpread.refresh();
  194. }
  195. });
  196. $.divResizer({
  197. select: '#gcl-resize',
  198. callback: function () {
  199. gclSpread.refresh();
  200. let bcontent = $("#leafxmj-bottom").length > 0 ? $("#leafxmj-bottom").height() : 0;
  201. $("#leaf-xmj-spread").height(bcontent-30);
  202. leafXmjSpread.refresh();
  203. }
  204. });
  205. const cTree = createNewPathTree('master', {
  206. id: 'ledger_id',
  207. pid: 'ledger_pid',
  208. order: 'order',
  209. level: 'level',
  210. rootId: -1,
  211. keys: ['id', 'tender_id', 'ledger_id'],
  212. masterId: 'id',
  213. minorId: 'lid',
  214. calcFields: [],
  215. markFoldKey: 'bills-fold',
  216. markFoldSubKey: window.location.pathname.split('/')[2],
  217. });
  218. const cPos = new MasterPosData({
  219. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  220. calcFun: function (pos) {
  221. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  222. }
  223. });
  224. postData(window.location.pathname + '/load', {main: true}, function (result) {
  225. cTree.loadDatas(result.main.ledger);
  226. cPos.loadDatas(result.main.pos);
  227. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  228. loadPosData(0);
  229. const checkField = function (x) {
  230. if (x === 'quantity') return true;
  231. if (x === 'total_price') return true;
  232. if (x.indexOf('_qty') >= 0) return true;
  233. if (x.indexOf('_tp') >= 0) return true;
  234. return false;
  235. };
  236. gclGatherModel.loadGatherField(checkField, checkField);
  237. gclGatherModel.loadLedgerData(result.main.ledger);
  238. gclGatherModel.loadPosData(result.main.pos);
  239. gclGatherData = gclGatherModel.gatherGclData();
  240. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  241. loadLeafXmjData(0);
  242. }, null, true);
  243. function loadPosData(iRow) {
  244. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  245. const posRange = node ? (cPos.getLedgerPos(node.id) || []) : [];
  246. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, posRange);
  247. SpreadJsObj.resetTopAndSelect(posSheet);
  248. }
  249. function loadLeafXmjData(iRow) {
  250. const gcl = iRow ? gclSheet.zh_data[iRow] : SpreadJsObj.getSelectObject(gclSheet);
  251. if (gcl) {
  252. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  253. } else {
  254. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  255. }
  256. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  257. }
  258. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  259. console.log(SpreadJsObj.getSelectObject(info.sheet));
  260. if (info.newSelections) {
  261. const iNewRow = info.newSelections[0].row;
  262. if (info.oldSelections) {
  263. const iOldRow = info.oldSelections[0].row;
  264. if (iNewRow !== iOldRow) {
  265. SpreadJsObj.resetTopAndSelect(posSheet);
  266. loadPosData(iNewRow);
  267. }
  268. } else {
  269. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  270. loadPosData(iNewRow);
  271. }
  272. }
  273. });
  274. gclSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  275. if (info.newSelections) {
  276. const iNewRow = info.newSelections[0].row;
  277. if (info.oldSelections) {
  278. const iOldRow = info.oldSelections[0].row;
  279. if (iNewRow !== iOldRow) {
  280. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  281. loadLeafXmjData(iNewRow);
  282. }
  283. } else {
  284. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  285. loadLeafXmjData(iNewRow);
  286. }
  287. }
  288. });
  289. const compareStages = [];
  290. $('#select-qi-ok').click(function () {
  291. function refreshView () {
  292. compareStages.length = 0;
  293. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  294. const tr = trs[order];
  295. if ($('input', tr)[0].checked) {
  296. compareStages.push(order + 1);
  297. }
  298. }
  299. // setLocalCache(cCacheKey, compareStages.join(','));
  300. initSpreadSettingWithRoles(compareStages);
  301. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  302. treeCalc.calculateAll(cTree);
  303. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  304. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  305. loadPosData();
  306. SpreadJsObj.reLoadSheetHeader(gclSheet);
  307. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  308. gclGatherModel.loadLedgerData(cTree.datas);
  309. gclGatherModel.loadPosData(cPos.datas);
  310. gclGatherData = gclGatherModel.gatherGclData();
  311. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  312. loadLeafXmjData(0);
  313. }
  314. let loadData = [], showData = [], trs = $('tr[stage-id]');
  315. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  316. const tr = trs[order];
  317. if ($('input[type=checkbox]', tr)[0].checked) {
  318. if (!cTree.minorData[order + 1]) {
  319. loadData.push(order + 1);
  320. }
  321. showData.push(order + 1);
  322. }
  323. }
  324. if (loadData.length > 0) {
  325. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  326. for (const aData of result.stages) {
  327. calculateStageLedgerData(aData.bills);
  328. cTree.loadMinorData(aData.bills, aData.order + '', ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], ['contract_tp', 'qc_tp', 'gather_tp']);
  329. treeCalc.calculateAll(cTree);
  330. calculateStagePosData(aData.pos);
  331. cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
  332. }
  333. refreshView();
  334. $('#select-qi').modal('hide');
  335. }, null, true);
  336. } else {
  337. refreshView();
  338. $('#select-qi').modal('hide');
  339. }
  340. });
  341. (function (select, sheet) {
  342. $(select).click(function () {
  343. if (!sheet.zh_tree) return;
  344. const tag = $(this).attr('tag');
  345. const tree = sheet.zh_tree;
  346. switch (tag) {
  347. case "1":
  348. case "2":
  349. case "3":
  350. case "4":
  351. case "5":
  352. tree.expandByLevel(parseInt(tag));
  353. SpreadJsObj.refreshTreeRowVisible(sheet);
  354. break;
  355. case "last":
  356. tree.expandByCustom(() => { return true; });
  357. SpreadJsObj.refreshTreeRowVisible(sheet);
  358. break;
  359. case "leafXmj":
  360. tree.expandToLeafXmj();
  361. SpreadJsObj.refreshTreeRowVisible(sheet);
  362. break;
  363. }
  364. });
  365. })('a[name=showLevel]', billsSheet);
  366. $('#exportExcel').click(function () {
  367. const data = [];
  368. if (!billsSheet.zh_tree) return;
  369. for (const node of billsSheet.zh_tree.nodes) {
  370. data.push(node);
  371. const posRange = cPos.getLedgerPos(node.id);
  372. if (posRange && posRange.length > 0) {
  373. for (const pr of posRange) {
  374. data.push(pr);
  375. }
  376. }
  377. }
  378. SpreadExcelObj.exportSimpleXlsxSheet(billsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  379. });
  380. $('[name=compare-data]').click(function () {
  381. initSpreadSettingWithRoles(compareStages);
  382. SpreadJsObj.reLoadSheetHeader(billsSheet);
  383. SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length);
  384. SpreadJsObj.reLoadSheetHeader(posSheet);
  385. SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length);
  386. SpreadJsObj.reLoadSheetHeader(gclSheet);
  387. SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length);
  388. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  389. SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.length);
  390. });
  391. $('[name=compareType]').click(function () {
  392. $('[name=compareType]').removeClass('active');
  393. $(this).addClass('active');
  394. $('#compareType').children().removeClass('active');
  395. $(this.getAttribute('href')).addClass('active');
  396. billsSpread.refresh();
  397. posSpread.refresh();
  398. gclSpread.refresh();
  399. leafXmjSpread.refresh();
  400. });
  401. });