measure_compare.js 16 KB

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