measure_compare.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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: 80, type: 'Number'},
  40. ],
  41. extraCols: [
  42. {title: '%s\n数量', colSpan: '1', rowSpan: '1', field: '{%s}_qty{%d}', hAlign: 2, width: 80, type: 'Number'},
  43. ],
  44. specExtraCols: [
  45. {title: '合计数量', colSpan: '1', rowSpan: '1', field: 'sum_{%s}_qty', hAlign: 2, width: 80, 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: 80, type: 'Number'},
  123. ],
  124. extraCols: [
  125. {title: '%s\n数量', colSpan: '1', rowSpan: '2', field: '{%s}_qty{%d}', hAlign: 2, width: 80},
  126. ],
  127. specExtraCols: [
  128. {title: '合计数量', colSpan: '1', rowSpan: '2', field: 'sum_{%s}_qty', hAlign: 2, width: 80, 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. const chapterSpreadSetting = {
  177. baseCols: [
  178. {title: '章节', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  179. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  180. {title: '签约金额', colSpan: '1', rowSpan: '1', field: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
  181. {title: '台账金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  182. ],
  183. extraCols: [
  184. {title: '%s\n金额', colSpan: '1', rowSpan: '1', field: '{%s}_tp{%d}', hAlign: 2, width: 100, type: 'Number', },
  185. ],
  186. specExtraCols: [
  187. {title: '合计金额', colSpan: '1', rowSpan: '1', field: 'sum_{%s}_tp', hAlign: 2, width: 80, type: 'Number', },
  188. ],
  189. emptyRows: 0,
  190. headRows: 1,
  191. headRowHeight: [38],
  192. headColWidth: [30],
  193. defaultRowHeight: 21,
  194. headerFont: '12px 微软雅黑',
  195. font: '12px 微软雅黑',
  196. readOnly: true,
  197. };
  198. function initSpreadSettingWithRoles(compareRoles) {
  199. function setSpreadSettingCols(setting, fieldSufs, Roles) {
  200. function addExtraCols(fieldSuf, Role) {
  201. const sourceType = $('[name=compare-data]:checked').val();
  202. for (const ec of setting.extraCols) {
  203. const col = JSON.parse(JSON.stringify(ec));
  204. col.title = _.replace(col.title, '%s', Role);
  205. col.field = _.replace(_.replace(col.field, '{%s}', sourceType), '{%d}', fieldSuf);
  206. setting.cols.push(col);
  207. }
  208. }
  209. setting.cols = [];
  210. for (const col of setting.baseCols) {
  211. setting.cols.push(col);
  212. }
  213. setting.frozenColCount = setting.baseCols.length;
  214. setting.frozenLineColor = '#93b5e4';
  215. for (const index in fieldSufs) {
  216. addExtraCols(fieldSufs[index], Roles[index]);
  217. }
  218. if (setting.specExtraCols) {
  219. const sourceType = $('[name=compare-data]:checked').val();
  220. for (const col of setting.specExtraCols) {
  221. const eCol = JSON.parse(JSON.stringify(col));
  222. eCol.field = _.replace(eCol.field, '{%s}', sourceType);
  223. setting.cols.push(eCol);
  224. }
  225. }
  226. if (setting.endCols) {
  227. for (const col of setting.endCols) {
  228. setting.cols.push(col);
  229. }
  230. }
  231. }
  232. const fieldSufs = [], roles = [], trs = $('tr[stage-id]');
  233. for (let r of compareRoles) {
  234. if (r > 0) {
  235. const tr = trs[r-1];
  236. if (tr) {
  237. fieldSufs.push(r + '');
  238. roles.push(`${tr.children[0].textContent}(${tr.children[1].textContent})`);
  239. }
  240. }
  241. }
  242. setSpreadSettingCols(billsSpreadSetting, fieldSufs, roles);
  243. setSpreadSettingCols(posSpreadSetting, fieldSufs, roles);
  244. setSpreadSettingCols(exportBillsSpreadSetting, fieldSufs, roles);
  245. setSpreadSettingCols(gclSpreadSetting, fieldSufs, roles);
  246. setSpreadSettingCols(leafXmjSpreadSetting, fieldSufs, roles);
  247. setSpreadSettingCols(exportGclSpreadSetting, fieldSufs, roles);
  248. setSpreadSettingCols(chapterSpreadSetting, fieldSufs, roles);
  249. }
  250. function calculateStageLedgerData(datas) {
  251. for (const d of datas) {
  252. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  253. d.gather_tp = ZhCalc.sum([d.contract_tp, d.qc_tp, d.pc_tp]);
  254. // d.pc_tp = ZhCalc.add(d.qc_tp, d.qc_pc_tp);
  255. // d.contract_tp = ZhCalc.add(d.contract_tp, d.contract_pc_tp);
  256. }
  257. }
  258. function calculateStagePosData(datas) {
  259. for (const d of datas) {
  260. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  261. }
  262. }
  263. $(document).ready(() => {
  264. let spec;
  265. autoFlashHeight();
  266. initSpreadSettingWithRoles([]);
  267. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  268. const billsSheet = billsSpread.getActiveSheet();
  269. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  270. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  271. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  272. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  273. const posSheet = posSpread.getActiveSheet();
  274. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  275. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  276. let gclGatherData;
  277. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  278. const gclSheet = gclSpread.getActiveSheet();
  279. sjsSettingObj.setFxTreeStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  280. if (thousandth) sjsSettingObj.setTpThousandthFormat(gclSpreadSetting);
  281. SpreadJsObj.initSheet(gclSheet, gclSpreadSetting);
  282. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  283. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  284. if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
  285. SpreadJsObj.initSheet(leafXmjSheet, leafXmjSpreadSetting);
  286. const chapterSpread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]);
  287. const chapterSheet = chapterSpread.getActiveSheet();
  288. sjsSettingObj.setGridSelectStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  289. if (thousandth) sjsSettingObj.setTpThousandthFormat(chapterSpreadSetting);
  290. SpreadJsObj.initSheet(chapterSheet, chapterSpreadSetting);
  291. $.subMenu({
  292. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  293. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  294. key: 'menu.1.0.0',
  295. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  296. callback: function (info) {
  297. if (info.mini) {
  298. $('.panel-title').addClass('fluid');
  299. $('#sub-menu').removeClass('panel-sidebar');
  300. } else {
  301. $('.panel-title').removeClass('fluid');
  302. $('#sub-menu').addClass('panel-sidebar');
  303. }
  304. autoFlashHeight();
  305. billsSpread.refresh();
  306. posSpread.refresh();
  307. }
  308. });
  309. // 上下窗口resizer
  310. $.divResizer({
  311. select: '#main-resize',
  312. callback: function () {
  313. billsSpread.refresh();
  314. let bcontent = $("#main-bottom").length > 0 ? $("#main-bottom").height() : 0;
  315. $("#pos-spread").height(bcontent-30);
  316. posSpread.refresh();
  317. }
  318. });
  319. $.divResizer({
  320. select: '#gcl-resize',
  321. callback: function () {
  322. gclSpread.refresh();
  323. let bcontent = $("#leafxmj-bottom").length > 0 ? $("#leafxmj-bottom").height() : 0;
  324. $("#leaf-xmj-spread").height(bcontent-30);
  325. leafXmjSpread.refresh();
  326. }
  327. });
  328. const cTree = createNewPathTree('master', {
  329. id: 'ledger_id',
  330. pid: 'ledger_pid',
  331. order: 'order',
  332. level: 'level',
  333. rootId: -1,
  334. keys: ['id', 'tender_id', 'ledger_id'],
  335. masterId: 'id',
  336. minorId: 'lid',
  337. calcFields: ['total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'],
  338. markFoldKey: 'bills-fold',
  339. markFoldSubKey: window.location.pathname.split('/')[2],
  340. });
  341. const cPos = new MasterPosData({
  342. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  343. calcFun: function (pos) {
  344. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  345. }
  346. });
  347. postData(window.location.pathname + '/load', {main: true}, function (result) {
  348. cTree.loadDatas(result.main.ledger);
  349. treeCalc.calculateAll(cTree);
  350. cPos.loadDatas(result.main.pos);
  351. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  352. loadPosData(0);
  353. const checkField = function (x) {
  354. if (x === 'quantity') return true;
  355. if (x === 'total_price') return true;
  356. if (x.indexOf('_qty') >= 0) return true;
  357. if (x.indexOf('_tp') >= 0) return true;
  358. return false;
  359. };
  360. gclGatherModel.loadGatherField(checkField, checkField);
  361. gclGatherModel.loadLedgerData(result.main.ledger);
  362. gclGatherModel.loadPosData(result.main.pos);
  363. gclGatherModel.loadDealBillsData(result.main.deal);
  364. gclGatherData = gclGatherModel.gatherGclData();
  365. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  366. loadLeafXmjData(0);
  367. spec = result.spec;
  368. const chapterData = gclGatherModel.gatherChapterData(chapter, spec, ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp']);
  369. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  370. }, null, true);
  371. function loadPosData(iRow) {
  372. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  373. const posRange = node ? (cPos.getLedgerPos(node.id) || []) : [];
  374. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, posRange);
  375. SpreadJsObj.resetTopAndSelect(posSheet);
  376. }
  377. function loadLeafXmjData(iRow) {
  378. const gcl = iRow ? gclSheet.zh_data[iRow] : SpreadJsObj.getSelectObject(gclSheet);
  379. if (gcl) {
  380. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  381. } else {
  382. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  383. }
  384. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  385. }
  386. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  387. if (info.newSelections) {
  388. const iNewRow = info.newSelections[0].row;
  389. if (info.oldSelections) {
  390. const iOldRow = info.oldSelections[0].row;
  391. if (iNewRow !== iOldRow) {
  392. SpreadJsObj.resetTopAndSelect(posSheet);
  393. loadPosData(iNewRow);
  394. }
  395. } else {
  396. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  397. loadPosData(iNewRow);
  398. }
  399. }
  400. });
  401. gclSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  402. if (info.newSelections) {
  403. const iNewRow = info.newSelections[0].row;
  404. if (info.oldSelections) {
  405. const iOldRow = info.oldSelections[0].row;
  406. if (iNewRow !== iOldRow) {
  407. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  408. loadLeafXmjData(iNewRow);
  409. }
  410. } else {
  411. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  412. loadLeafXmjData(iNewRow);
  413. }
  414. }
  415. });
  416. const compareStages = [];
  417. $('#select-qi-ok').click(function () {
  418. function refreshView () {
  419. const gatherField = ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'];
  420. compareStages.length = 0;
  421. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  422. const tr = trs[order];
  423. if ($('input', tr)[0].checked) {
  424. compareStages.push(order + 1);
  425. gatherField.push(`contract_tp${order + 1}`, `qc_tp${order + 1}`, `gather_tp${order + 1}`);
  426. }
  427. }
  428. // setLocalCache(cCacheKey, compareStages.join(','));
  429. initSpreadSettingWithRoles(compareStages);
  430. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  431. treeCalc.calculateAll(cTree);
  432. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  433. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  434. loadPosData();
  435. SpreadJsObj.reLoadSheetHeader(gclSheet);
  436. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  437. gclGatherModel.loadLedgerData(cTree.datas);
  438. gclGatherModel.loadPosData(cPos.datas);
  439. gclGatherData = gclGatherModel.gatherGclData();
  440. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  441. loadLeafXmjData(0);
  442. const chapterData = gclGatherModel.gatherChapterData(chapter, spec, gatherField);
  443. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  444. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  445. }
  446. let loadData = [], showData = [], trs = $('tr[stage-id]');
  447. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  448. const tr = trs[order];
  449. if ($('input[type=checkbox]', tr)[0].checked) {
  450. if (!cTree.minorData[order + 1]) {
  451. loadData.push(order + 1);
  452. }
  453. showData.push(order + 1);
  454. }
  455. }
  456. if (loadData.length > 0) {
  457. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  458. spec = result.spec;
  459. for (const aData of result.stages) {
  460. calculateStageLedgerData(aData.bills);
  461. cTree.loadMinorData(aData.bills, aData.order + '', ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], ['contract_tp', 'qc_tp', 'gather_tp']);
  462. calculateStagePosData(aData.pos);
  463. cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
  464. }
  465. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  466. treeCalc.calculateAll(cTree);
  467. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  468. refreshView();
  469. $('#select-qi').modal('hide');
  470. }, null, true);
  471. } else {
  472. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  473. treeCalc.calculateAll(cTree);
  474. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  475. refreshView();
  476. $('#select-qi').modal('hide');
  477. }
  478. });
  479. (function (select, sheet) {
  480. $(select).click(function () {
  481. if (!sheet.zh_tree) return;
  482. const tag = $(this).attr('tag');
  483. const tree = sheet.zh_tree;
  484. switch (tag) {
  485. case "1":
  486. case "2":
  487. case "3":
  488. case "4":
  489. case "5":
  490. tree.expandByLevel(parseInt(tag));
  491. SpreadJsObj.refreshTreeRowVisible(sheet);
  492. break;
  493. case "last":
  494. tree.expandByCustom(() => { return true; });
  495. SpreadJsObj.refreshTreeRowVisible(sheet);
  496. break;
  497. case "leafXmj":
  498. tree.expandToLeafXmj();
  499. SpreadJsObj.refreshTreeRowVisible(sheet);
  500. break;
  501. }
  502. });
  503. })('a[name=showLevel]', billsSheet);
  504. $('#exportExcel').click(function () {
  505. const exportLedger = function () {
  506. const data = [];
  507. if (!billsSheet.zh_tree) return;
  508. for (const node of billsSheet.zh_tree.nodes) {
  509. data.push(node);
  510. const posRange = cPos.getLedgerPos(node.id);
  511. if (posRange && posRange.length > 0) {
  512. for (const pr of posRange) {
  513. data.push(pr);
  514. }
  515. }
  516. }
  517. SpreadExcelObj.exportSimpleXlsxSheet(exportBillsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  518. };
  519. const exportGcl = function () {
  520. const data = [];
  521. if (!gclSheet.zh_data) return;
  522. for (const node of gclSheet.zh_data) {
  523. data.push(node);
  524. for (const leafXmj of node.leafXmjs) {
  525. data.push(leafXmj);
  526. }
  527. }
  528. SpreadExcelObj.exportSimpleXlsxSheet(exportGclSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  529. };
  530. const exportChapter = function () {
  531. SpreadExcelObj.exportSimpleXlsxSheet(chapterSpreadSetting, chapterSheet.zh_data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  532. };
  533. const cur = $('.active[name=compareType]').attr('href');
  534. if (cur.indexOf('gcl') >= 0) {
  535. exportGcl();
  536. } else if (cur.indexOf('chapter') >= 0) {
  537. exportChapter();
  538. } else {
  539. exportLedger();
  540. }
  541. });
  542. $('[name=compare-data]').click(function () {
  543. initSpreadSettingWithRoles(compareStages);
  544. SpreadJsObj.reLoadSheetHeader(billsSheet);
  545. SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length + billsSpreadSetting.specExtraCols.length);
  546. SpreadJsObj.reLoadSheetHeader(posSheet);
  547. SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length + posSpreadSetting.specExtraCols.length);
  548. SpreadJsObj.reLoadSheetHeader(gclSheet);
  549. SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length + gclSpreadSetting.specExtraCols.length);
  550. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  551. SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.length + leafXmjSpreadSetting.specExtraCols.length);
  552. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  553. SpreadJsObj.reloadColData(chapterSheet, chapterSpreadSetting.baseCols.length, compareStages.length * chapterSpreadSetting.extraCols.length + chapterSpreadSetting.specExtraCols.length);
  554. });
  555. $('[name=compareType]').click(function () {
  556. $('[name=compareType]').removeClass('active');
  557. $(this).addClass('active');
  558. $('#compareType').children().removeClass('active');
  559. $(this.getAttribute('href')).addClass('active');
  560. billsSpread.refresh();
  561. posSpread.refresh();
  562. gclSpread.refresh();
  563. leafXmjSpread.refresh();
  564. chapterSpread.refresh();
  565. });
  566. $('#select-qi-all').click(function() {
  567. const check = this.checked;
  568. $('input', 'tr[stage-id]').each((i, x) => {
  569. x.checked = check;
  570. })
  571. });
  572. });