measure_compare.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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: 80, 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. autoFlashHeight();
  265. initSpreadSettingWithRoles([]);
  266. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  267. const billsSheet = billsSpread.getActiveSheet();
  268. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  269. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  270. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  271. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  272. const posSheet = posSpread.getActiveSheet();
  273. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  274. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  275. let gclGatherData;
  276. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  277. const gclSheet = gclSpread.getActiveSheet();
  278. sjsSettingObj.setFxTreeStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  279. if (thousandth) sjsSettingObj.setTpThousandthFormat(gclSpreadSetting);
  280. SpreadJsObj.initSheet(gclSheet, gclSpreadSetting);
  281. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  282. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  283. if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
  284. SpreadJsObj.initSheet(leafXmjSheet, leafXmjSpreadSetting);
  285. const chapterSpread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]);
  286. const chapterSheet = chapterSpread.getActiveSheet();
  287. sjsSettingObj.setGridSelectStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  288. if (thousandth) sjsSettingObj.setTpThousandthFormat(chapterSpreadSetting);
  289. SpreadJsObj.initSheet(chapterSheet, chapterSpreadSetting);
  290. $.subMenu({
  291. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  292. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  293. key: 'menu.1.0.0',
  294. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  295. callback: function (info) {
  296. if (info.mini) {
  297. $('.panel-title').addClass('fluid');
  298. $('#sub-menu').removeClass('panel-sidebar');
  299. } else {
  300. $('.panel-title').removeClass('fluid');
  301. $('#sub-menu').addClass('panel-sidebar');
  302. }
  303. autoFlashHeight();
  304. billsSpread.refresh();
  305. posSpread.refresh();
  306. }
  307. });
  308. // 上下窗口resizer
  309. $.divResizer({
  310. select: '#main-resize',
  311. callback: function () {
  312. billsSpread.refresh();
  313. let bcontent = $("#main-bottom").length > 0 ? $("#main-bottom").height() : 0;
  314. $("#pos-spread").height(bcontent-30);
  315. posSpread.refresh();
  316. }
  317. });
  318. $.divResizer({
  319. select: '#gcl-resize',
  320. callback: function () {
  321. gclSpread.refresh();
  322. let bcontent = $("#leafxmj-bottom").length > 0 ? $("#leafxmj-bottom").height() : 0;
  323. $("#leaf-xmj-spread").height(bcontent-30);
  324. leafXmjSpread.refresh();
  325. }
  326. });
  327. const cTree = createNewPathTree('master', {
  328. id: 'ledger_id',
  329. pid: 'ledger_pid',
  330. order: 'order',
  331. level: 'level',
  332. rootId: -1,
  333. keys: ['id', 'tender_id', 'ledger_id'],
  334. masterId: 'id',
  335. minorId: 'lid',
  336. calcFields: ['total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'],
  337. markFoldKey: 'bills-fold',
  338. markFoldSubKey: window.location.pathname.split('/')[2],
  339. });
  340. const cPos = new MasterPosData({
  341. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  342. calcFun: function (pos) {
  343. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  344. }
  345. });
  346. postData(window.location.pathname + '/load', {main: true}, function (result) {
  347. cTree.loadDatas(result.main.ledger);
  348. treeCalc.calculateAll(cTree);
  349. cPos.loadDatas(result.main.pos);
  350. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  351. loadPosData(0);
  352. const checkField = function (x) {
  353. if (x === 'quantity') return true;
  354. if (x === 'total_price') return true;
  355. if (x.indexOf('_qty') >= 0) return true;
  356. if (x.indexOf('_tp') >= 0) return true;
  357. return false;
  358. };
  359. gclGatherModel.loadGatherField(checkField, checkField);
  360. gclGatherModel.loadLedgerData(result.main.ledger);
  361. gclGatherModel.loadPosData(result.main.pos);
  362. gclGatherModel.loadDealBillsData(result.main.deal);
  363. gclGatherData = gclGatherModel.gatherGclData();
  364. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  365. loadLeafXmjData(0);
  366. const chapterData = gclGatherModel.gatherChapterData(chapter, result.spec, ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp']);
  367. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  368. }, null, true);
  369. function loadPosData(iRow) {
  370. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  371. const posRange = node ? (cPos.getLedgerPos(node.id) || []) : [];
  372. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, posRange);
  373. SpreadJsObj.resetTopAndSelect(posSheet);
  374. }
  375. function loadLeafXmjData(iRow) {
  376. const gcl = iRow ? gclSheet.zh_data[iRow] : SpreadJsObj.getSelectObject(gclSheet);
  377. if (gcl) {
  378. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  379. } else {
  380. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  381. }
  382. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  383. }
  384. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  385. console.log(SpreadJsObj.getSelectObject(info.sheet));
  386. if (info.newSelections) {
  387. const iNewRow = info.newSelections[0].row;
  388. if (info.oldSelections) {
  389. const iOldRow = info.oldSelections[0].row;
  390. if (iNewRow !== iOldRow) {
  391. SpreadJsObj.resetTopAndSelect(posSheet);
  392. loadPosData(iNewRow);
  393. }
  394. } else {
  395. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  396. loadPosData(iNewRow);
  397. }
  398. }
  399. });
  400. gclSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  401. if (info.newSelections) {
  402. const iNewRow = info.newSelections[0].row;
  403. if (info.oldSelections) {
  404. const iOldRow = info.oldSelections[0].row;
  405. if (iNewRow !== iOldRow) {
  406. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  407. loadLeafXmjData(iNewRow);
  408. }
  409. } else {
  410. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  411. loadLeafXmjData(iNewRow);
  412. }
  413. }
  414. });
  415. const compareStages = [];
  416. $('#select-qi-ok').click(function () {
  417. function refreshView (data) {
  418. const gatherField = ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'];
  419. compareStages.length = 0;
  420. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  421. const tr = trs[order];
  422. if ($('input', tr)[0].checked) {
  423. compareStages.push(order + 1);
  424. gatherField.push(`contract_tp${order}`, `qc_tp${order}`, `gather_tp${order}`);
  425. }
  426. }
  427. // setLocalCache(cCacheKey, compareStages.join(','));
  428. initSpreadSettingWithRoles(compareStages);
  429. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  430. treeCalc.calculateAll(cTree);
  431. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  432. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  433. loadPosData();
  434. SpreadJsObj.reLoadSheetHeader(gclSheet);
  435. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  436. gclGatherModel.loadLedgerData(cTree.datas);
  437. gclGatherModel.loadPosData(cPos.datas);
  438. gclGatherData = gclGatherModel.gatherGclData();
  439. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  440. loadLeafXmjData(0);
  441. const chapterData = gclGatherModel.gatherChapterData(chapter, data.spec, gatherField);
  442. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  443. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  444. }
  445. let loadData = [], showData = [], trs = $('tr[stage-id]');
  446. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  447. const tr = trs[order];
  448. if ($('input[type=checkbox]', tr)[0].checked) {
  449. if (!cTree.minorData[order + 1]) {
  450. loadData.push(order + 1);
  451. }
  452. showData.push(order + 1);
  453. }
  454. }
  455. if (loadData.length > 0) {
  456. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  457. for (const aData of result.stages) {
  458. calculateStageLedgerData(aData.bills);
  459. cTree.loadMinorData(aData.bills, aData.order + '', ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], ['contract_tp', 'qc_tp', 'gather_tp']);
  460. calculateStagePosData(aData.pos);
  461. cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
  462. }
  463. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  464. treeCalc.calculateAll(cTree);
  465. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  466. refreshView(result);
  467. $('#select-qi').modal('hide');
  468. }, null, true);
  469. } else {
  470. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  471. treeCalc.calculateAll(cTree);
  472. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  473. refreshView();
  474. $('#select-qi').modal('hide');
  475. }
  476. });
  477. (function (select, sheet) {
  478. $(select).click(function () {
  479. if (!sheet.zh_tree) return;
  480. const tag = $(this).attr('tag');
  481. const tree = sheet.zh_tree;
  482. switch (tag) {
  483. case "1":
  484. case "2":
  485. case "3":
  486. case "4":
  487. case "5":
  488. tree.expandByLevel(parseInt(tag));
  489. SpreadJsObj.refreshTreeRowVisible(sheet);
  490. break;
  491. case "last":
  492. tree.expandByCustom(() => { return true; });
  493. SpreadJsObj.refreshTreeRowVisible(sheet);
  494. break;
  495. case "leafXmj":
  496. tree.expandToLeafXmj();
  497. SpreadJsObj.refreshTreeRowVisible(sheet);
  498. break;
  499. }
  500. });
  501. })('a[name=showLevel]', billsSheet);
  502. $('#exportExcel').click(function () {
  503. const exportLedger = function () {
  504. const data = [];
  505. if (!billsSheet.zh_tree) return;
  506. for (const node of billsSheet.zh_tree.nodes) {
  507. data.push(node);
  508. const posRange = cPos.getLedgerPos(node.id);
  509. if (posRange && posRange.length > 0) {
  510. for (const pr of posRange) {
  511. data.push(pr);
  512. }
  513. }
  514. }
  515. SpreadExcelObj.exportSimpleXlsxSheet(exportBillsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  516. };
  517. const exportGcl = function () {
  518. const data = [];
  519. if (!gclSheet.zh_data) return;
  520. for (const node of gclSheet.zh_data) {
  521. data.push(node);
  522. for (const leafXmj of node.leafXmjs) {
  523. data.push(leafXmj);
  524. }
  525. }
  526. SpreadExcelObj.exportSimpleXlsxSheet(exportGclSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  527. };
  528. const exportChapter = function () {
  529. SpreadExcelObj.exportSimpleXlsxSheet(chapterSpreadSetting, chapterSheet.zh_data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  530. };
  531. const cur = $('.active[name=compareType]').attr('href');
  532. if (cur.indexOf('gcl') >= 0) {
  533. exportGcl();
  534. } else if (cur.indexOf('chapter') >= 0) {
  535. exportChapter();
  536. } else {
  537. exportLedger();
  538. }
  539. });
  540. $('[name=compare-data]').click(function () {
  541. initSpreadSettingWithRoles(compareStages);
  542. SpreadJsObj.reLoadSheetHeader(billsSheet);
  543. SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length + billsSpreadSetting.specExtraCols.length);
  544. SpreadJsObj.reLoadSheetHeader(posSheet);
  545. SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length + posSpreadSetting.specExtraCols.length);
  546. SpreadJsObj.reLoadSheetHeader(gclSheet);
  547. SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length + gclSpreadSetting.specExtraCols.length);
  548. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  549. SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.length + leafXmjSpreadSetting.specExtraCols.length);
  550. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  551. SpreadJsObj.reloadColData(chapterSheet, chapterSpreadSetting.baseCols.length, compareStages.length * chapterSpreadSetting.extraCols.length + chapterSpreadSetting.specExtraCols.length);
  552. });
  553. $('[name=compareType]').click(function () {
  554. $('[name=compareType]').removeClass('active');
  555. $(this).addClass('active');
  556. $('#compareType').children().removeClass('active');
  557. $(this.getAttribute('href')).addClass('active');
  558. billsSpread.refresh();
  559. posSpread.refresh();
  560. gclSpread.refresh();
  561. leafXmjSpread.refresh();
  562. chapterSpread.refresh();
  563. });
  564. $('#select-qi-all').click(function() {
  565. const check = this.checked;
  566. $('input', 'tr[stage-id]').each((i, x) => {
  567. x.checked = check;
  568. })
  569. });
  570. });