measure_compare.js 25 KB

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