measure_compare.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. tipsSum: true,
  36. };
  37. const posSpreadSetting = {
  38. baseCols: [
  39. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  40. {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  41. ],
  42. extraCols: [
  43. {title: '%s\n数量', colSpan: '1', rowSpan: '1', field: '{%s}_qty{%d}', hAlign: 2, width: 80, type: 'Number'},
  44. ],
  45. specExtraCols: [
  46. {title: '合计数量', colSpan: '1', rowSpan: '1', field: 'sum_{%s}_qty', hAlign: 2, width: 80, type: 'Number', },
  47. ],
  48. emptyRows: 3,
  49. headRows: 1,
  50. headRowHeight: [32],
  51. headColWidth: [30],
  52. defaultRowHeight: 21,
  53. headerFont: '12px 微软雅黑',
  54. font: '12px 微软雅黑',
  55. readOnly: true,
  56. selectedBackColor: '#fffacd',
  57. tipsSum: true,
  58. };
  59. const exportBillsSpreadSetting = {
  60. baseCols: [
  61. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  62. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  63. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  64. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
  65. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  66. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', },
  67. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number', },
  68. ],
  69. extraCols: [
  70. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
  71. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
  72. ],
  73. specExtraCols: [
  74. {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
  75. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
  76. ],
  77. endCols: [],
  78. emptyRows: 3,
  79. headRows: 2,
  80. headRowHeight: [25, 25],
  81. headerFont: '12px 微软雅黑',
  82. font: '12px 微软雅黑',
  83. defaultRowHeight: 21,
  84. readOnly: true,
  85. selectedBackColor: '#fffacd',
  86. };
  87. const gclSpreadSetting = {
  88. baseCols: [
  89. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  90. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  91. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  92. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  93. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 60, type: 'Number'},
  94. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 60, type: 'Number'},
  95. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  96. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  97. ],
  98. extraCols: [
  99. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
  100. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
  101. ],
  102. specExtraCols: [
  103. {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
  104. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
  105. ],
  106. emptyRows: 0,
  107. headRows: 2,
  108. headRowHeight: [25, 25],
  109. headColWidth: [30],
  110. defaultRowHeight: 21,
  111. headerFont: '12px 微软雅黑',
  112. font: '12px 微软雅黑',
  113. readOnly: true,
  114. tipsSum: true,
  115. };
  116. const leafXmjSpreadSetting = {
  117. baseCols: [
  118. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  119. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  120. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  121. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  122. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  123. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  124. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  125. {title: '台账数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  126. ],
  127. extraCols: [
  128. {title: '%s\n数量', colSpan: '1', rowSpan: '2', field: '{%s}_qty{%d}', hAlign: 2, width: 80},
  129. ],
  130. specExtraCols: [
  131. {title: '合计数量', colSpan: '1', rowSpan: '2', field: 'sum_{%s}_qty', hAlign: 2, width: 80, type: 'Number', },
  132. ],
  133. emptyRows: 0,
  134. headRows: 2,
  135. headRowHeight: [25, 25],
  136. headColWidth: [30],
  137. defaultRowHeight: 21,
  138. headerFont: '12px 微软雅黑',
  139. font: '12px 微软雅黑',
  140. readOnly: true,
  141. tipsSum: true,
  142. };
  143. const exportGclSpreadSetting = {
  144. baseCols: [
  145. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  146. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  147. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  148. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  149. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  150. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  151. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  152. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  153. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  154. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  155. {title: '签约清单|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deal_bills_qty', hAlign: 2, width: 60, type: 'Number'},
  156. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deal_bills_tp', hAlign: 2, width: 60, type: 'Number'},
  157. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  158. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  159. ],
  160. extraCols: [
  161. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: '{%s}_qty{%d}', hAlign: 2, width: 60, type: 'Number', },
  162. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: '{%s}_tp{%d}', hAlign: 2, width: 60, type: 'Number', },
  163. ],
  164. specExtraCols: [
  165. {title: '合计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'sum_{%s}_qty', hAlign: 2, width: 60, type: 'Number', },
  166. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sum_{%s}_tp', hAlign: 2, width: 60, type: 'Number', },
  167. ],
  168. endCols: [
  169. {title: '图册号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  170. ],
  171. emptyRows: 0,
  172. headRows: 2,
  173. headRowHeight: [25, 25],
  174. headColWidth: [30],
  175. defaultRowHeight: 21,
  176. headerFont: '12px 微软雅黑',
  177. font: '12px 微软雅黑',
  178. readOnly: true,
  179. };
  180. const chapterSpreadSetting = {
  181. baseCols: [
  182. {title: '章节', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  183. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  184. {title: '签约金额', colSpan: '1', rowSpan: '1', field: 'deal_bills_tp', hAlign: 2, width: 80, type: 'Number'},
  185. {title: '台账金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  186. ],
  187. extraCols: [
  188. {title: '%s\n金额', colSpan: '1', rowSpan: '1', field: '{%s}_tp{%d}', hAlign: 2, width: 100, type: 'Number', },
  189. ],
  190. specExtraCols: [
  191. {title: '合计金额', colSpan: '1', rowSpan: '1', field: 'sum_{%s}_tp', hAlign: 2, width: 80, type: 'Number', },
  192. ],
  193. emptyRows: 0,
  194. headRows: 1,
  195. headRowHeight: [38],
  196. headColWidth: [30],
  197. defaultRowHeight: 21,
  198. headerFont: '12px 微软雅黑',
  199. font: '12px 微软雅黑',
  200. readOnly: true,
  201. };
  202. function initSpreadSettingWithRoles(compareRoles) {
  203. function setSpreadSettingCols(setting, fieldSufs, Roles) {
  204. function addExtraCols(fieldSuf, Role) {
  205. const sourceType = $('[name=compare-data]:checked').val();
  206. for (const ec of setting.extraCols) {
  207. const col = JSON.parse(JSON.stringify(ec));
  208. col.title = _.replace(col.title, '%s', Role);
  209. col.field = _.replace(_.replace(col.field, '{%s}', sourceType), '{%d}', fieldSuf);
  210. setting.cols.push(col);
  211. }
  212. }
  213. setting.cols = [];
  214. for (const col of setting.baseCols) {
  215. setting.cols.push(col);
  216. }
  217. setting.frozenColCount = setting.baseCols.length;
  218. setting.frozenLineColor = '#93b5e4';
  219. for (const index in fieldSufs) {
  220. addExtraCols(fieldSufs[index], Roles[index]);
  221. }
  222. if (setting.specExtraCols) {
  223. const sourceType = $('[name=compare-data]:checked').val();
  224. for (const col of setting.specExtraCols) {
  225. const eCol = JSON.parse(JSON.stringify(col));
  226. eCol.field = _.replace(eCol.field, '{%s}', sourceType);
  227. setting.cols.push(eCol);
  228. }
  229. }
  230. if (setting.endCols) {
  231. for (const col of setting.endCols) {
  232. setting.cols.push(col);
  233. }
  234. }
  235. }
  236. const fieldSufs = [], roles = [], trs = $('tr[stage-id]');
  237. for (let r of compareRoles) {
  238. if (r > 0) {
  239. const tr = trs[r-1];
  240. if (tr) {
  241. fieldSufs.push(r + '');
  242. roles.push(`${tr.children[0].textContent}(${tr.children[1].textContent})`);
  243. }
  244. }
  245. }
  246. setSpreadSettingCols(billsSpreadSetting, fieldSufs, roles);
  247. setSpreadSettingCols(posSpreadSetting, fieldSufs, roles);
  248. setSpreadSettingCols(exportBillsSpreadSetting, fieldSufs, roles);
  249. setSpreadSettingCols(gclSpreadSetting, fieldSufs, roles);
  250. setSpreadSettingCols(leafXmjSpreadSetting, fieldSufs, roles);
  251. setSpreadSettingCols(exportGclSpreadSetting, fieldSufs, roles);
  252. setSpreadSettingCols(chapterSpreadSetting, fieldSufs, roles);
  253. }
  254. function calculateStageLedgerData(datas) {
  255. for (const d of datas) {
  256. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  257. d.gather_tp = ZhCalc.sum([d.contract_tp, d.qc_tp, d.pc_tp]);
  258. // d.pc_tp = ZhCalc.add(d.qc_tp, d.qc_pc_tp);
  259. // d.contract_tp = ZhCalc.add(d.contract_tp, d.contract_pc_tp);
  260. }
  261. }
  262. function calculateStagePosData(datas) {
  263. for (const d of datas) {
  264. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  265. }
  266. }
  267. $(document).ready(() => {
  268. let spec, ledgerSearch, gclSearch;
  269. autoFlashHeight();
  270. initSpreadSettingWithRoles([]);
  271. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  272. const billsSheet = billsSpread.getActiveSheet();
  273. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  274. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  275. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  276. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  277. const posSheet = posSpread.getActiveSheet();
  278. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  279. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  280. let gclGatherData;
  281. const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
  282. const gclSheet = gclSpread.getActiveSheet();
  283. sjsSettingObj.setFxTreeStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  284. if (thousandth) sjsSettingObj.setTpThousandthFormat(gclSpreadSetting);
  285. SpreadJsObj.initSheet(gclSheet, gclSpreadSetting);
  286. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  287. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  288. if (thousandth) sjsSettingObj.setTpThousandthFormat(leafXmjSpreadSetting);
  289. SpreadJsObj.initSheet(leafXmjSheet, leafXmjSpreadSetting);
  290. const chapterSpread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]);
  291. const chapterSheet = chapterSpread.getActiveSheet();
  292. sjsSettingObj.setGridSelectStyle(gclSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  293. if (thousandth) sjsSettingObj.setTpThousandthFormat(chapterSpreadSetting);
  294. SpreadJsObj.initSheet(chapterSheet, chapterSpreadSetting);
  295. $.subMenu({
  296. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  297. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  298. key: 'menu.1.0.0',
  299. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  300. callback: function (info) {
  301. if (info.mini) {
  302. $('.panel-title').addClass('fluid');
  303. $('#sub-menu').removeClass('panel-sidebar');
  304. } else {
  305. $('.panel-title').removeClass('fluid');
  306. $('#sub-menu').addClass('panel-sidebar');
  307. }
  308. autoFlashHeight();
  309. billsSpread.refresh();
  310. posSpread.refresh();
  311. }
  312. });
  313. // 上下窗口resizer
  314. $.divResizer({
  315. select: '#main-resize',
  316. callback: function () {
  317. billsSpread.refresh();
  318. let bcontent = $("#main-bottom").length > 0 ? $("#main-bottom").height() : 0;
  319. $("#pos-spread").height(bcontent-30);
  320. posSpread.refresh();
  321. }
  322. });
  323. $.divResizer({
  324. select: '#gcl-resize',
  325. callback: function () {
  326. gclSpread.refresh();
  327. let bcontent = $("#leafxmj-bottom").length > 0 ? $("#leafxmj-bottom").height() : 0;
  328. $("#leaf-xmj-spread").height(bcontent-30);
  329. leafXmjSpread.refresh();
  330. }
  331. });
  332. // 工具栏resizer
  333. $.divResizer({
  334. select: '#tz-right-spr',
  335. callback: function () {
  336. billsSpread.refresh();
  337. posSpread.refresh();
  338. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  339. if (ledgerSearch) ledgerSearch.spread.refresh();
  340. }
  341. });
  342. $.divResizer({
  343. select: '#gcl-right-spr',
  344. callback: function () {
  345. gclSpread.refresh();
  346. leafXmjSpread.refresh();
  347. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  348. if (gclSearch) gclSearch.spread.refresh();
  349. }
  350. });
  351. const cTree = createNewPathTree('master', {
  352. id: 'ledger_id',
  353. pid: 'ledger_pid',
  354. order: 'order',
  355. level: 'level',
  356. rootId: -1,
  357. keys: ['id', 'tender_id', 'ledger_id'],
  358. masterId: 'id',
  359. minorId: 'lid',
  360. calcFields: ['total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'],
  361. markFoldKey: 'bills-fold',
  362. markFoldSubKey: window.location.pathname.split('/')[2],
  363. });
  364. const cPos = new MasterPosData({
  365. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  366. calcFun: function (pos) {
  367. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  368. }
  369. });
  370. postData(window.location.pathname + '/load', {main: true}, function (result) {
  371. cTree.loadDatas(result.main.ledger);
  372. treeCalc.calculateAll(cTree);
  373. cPos.loadDatas(result.main.pos);
  374. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  375. loadPosData(0);
  376. const checkField = function (x) {
  377. if (x === 'quantity') return true;
  378. if (x === 'total_price') return true;
  379. if (x.indexOf('_qty') >= 0) return true;
  380. if (x.indexOf('_tp') >= 0) return true;
  381. return false;
  382. };
  383. gclGatherModel.loadGatherField(checkField, checkField);
  384. gclGatherModel.loadLedgerData(result.main.ledger);
  385. gclGatherModel.loadPosData(result.main.pos);
  386. gclGatherModel.loadDealBillsData(result.main.deal);
  387. gclGatherData = gclGatherModel.gatherGclData();
  388. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  389. loadLeafXmjData(0);
  390. spec = result.spec;
  391. const chapterData = gclGatherModel.gatherChapterData(chapter, spec, ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp']);
  392. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  393. }, null, true);
  394. function loadPosData(iRow) {
  395. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  396. const posRange = node ? (cPos.getLedgerPos(node.id) || []) : [];
  397. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, posRange);
  398. SpreadJsObj.resetTopAndSelect(posSheet);
  399. }
  400. function loadLeafXmjData(iRow) {
  401. const gcl = iRow ? gclSheet.zh_data[iRow] : SpreadJsObj.getSelectObject(gclSheet);
  402. if (gcl) {
  403. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  404. } else {
  405. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  406. }
  407. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  408. }
  409. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  410. if (info.newSelections) {
  411. const iNewRow = info.newSelections[0].row;
  412. if (info.oldSelections) {
  413. const iOldRow = info.oldSelections[0].row;
  414. if (iNewRow !== iOldRow) {
  415. SpreadJsObj.resetTopAndSelect(posSheet);
  416. loadPosData(iNewRow);
  417. }
  418. } else {
  419. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  420. loadPosData(iNewRow);
  421. }
  422. }
  423. });
  424. gclSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  425. if (info.newSelections) {
  426. const iNewRow = info.newSelections[0].row;
  427. if (info.oldSelections) {
  428. const iOldRow = info.oldSelections[0].row;
  429. if (iNewRow !== iOldRow) {
  430. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  431. loadLeafXmjData(iNewRow);
  432. }
  433. } else {
  434. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  435. loadLeafXmjData(iNewRow);
  436. }
  437. }
  438. });
  439. const compareStages = [];
  440. $('#select-qi-ok').click(function () {
  441. function refreshView () {
  442. const gatherField = ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'];
  443. compareStages.length = 0;
  444. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  445. const tr = trs[order];
  446. if ($('input', tr)[0].checked) {
  447. compareStages.push(order + 1);
  448. gatherField.push(`contract_tp${order + 1}`, `qc_tp${order + 1}`, `gather_tp${order + 1}`);
  449. }
  450. }
  451. // setLocalCache(cCacheKey, compareStages.join(','));
  452. initSpreadSettingWithRoles(compareStages);
  453. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  454. treeCalc.calculateAll(cTree);
  455. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  456. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  457. loadPosData();
  458. SpreadJsObj.reLoadSheetHeader(gclSheet);
  459. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  460. gclGatherModel.loadLedgerData(cTree.datas);
  461. gclGatherModel.loadPosData(cPos.datas);
  462. gclGatherData = gclGatherModel.gatherGclData();
  463. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  464. loadLeafXmjData(0);
  465. const chapterData = gclGatherModel.gatherChapterData(chapter, spec, gatherField);
  466. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  467. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  468. }
  469. let loadData = [], showData = [], trs = $('tr[stage-id]');
  470. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  471. const tr = trs[order];
  472. if ($('input[type=checkbox]', tr)[0].checked) {
  473. if (!cTree.minorData[order + 1]) {
  474. loadData.push(order + 1);
  475. }
  476. showData.push(order + 1);
  477. }
  478. }
  479. if (loadData.length > 0) {
  480. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  481. spec = result.spec;
  482. for (const aData of result.stages) {
  483. calculateStageLedgerData(aData.bills);
  484. cTree.loadMinorData(aData.bills, aData.order + '', ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], ['contract_tp', 'qc_tp', 'gather_tp']);
  485. calculateStagePosData(aData.pos);
  486. cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
  487. }
  488. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  489. treeCalc.calculateAll(cTree);
  490. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  491. refreshView();
  492. $('#select-qi').modal('hide');
  493. }, null, true);
  494. } else {
  495. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  496. treeCalc.calculateAll(cTree);
  497. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  498. refreshView();
  499. $('#select-qi').modal('hide');
  500. }
  501. });
  502. (function (select, sheet) {
  503. $(select).click(function () {
  504. if (!sheet.zh_tree) return;
  505. const tag = $(this).attr('tag');
  506. const tree = sheet.zh_tree;
  507. switch (tag) {
  508. case "1":
  509. case "2":
  510. case "3":
  511. case "4":
  512. case "5":
  513. tree.expandByLevel(parseInt(tag));
  514. SpreadJsObj.refreshTreeRowVisible(sheet);
  515. break;
  516. case "last":
  517. tree.expandByCustom(() => { return true; });
  518. SpreadJsObj.refreshTreeRowVisible(sheet);
  519. break;
  520. case "leafXmj":
  521. tree.expandToLeafXmj();
  522. SpreadJsObj.refreshTreeRowVisible(sheet);
  523. break;
  524. }
  525. });
  526. })('a[name=showLevel]', billsSheet);
  527. // 展开收起工具栏
  528. const showTzSideTools = function (show) {
  529. const left = $('#tz-left-view'), right = $('#tz-right-view'), parent = left.parent();
  530. if (show) {
  531. right.show();
  532. autoFlashHeight();
  533. /**
  534. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  535. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  536. * 故需要通过最终的parent.width再计算一次left.width
  537. *
  538. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  539. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  540. *
  541. */
  542. //left.css('width', parent.width() - right.outerWidth());
  543. //left.css('width', parent.width() - right.outerWidth());
  544. const percent = 100 - right.outerWidth() /parent.width() * 100;
  545. left.css('width', percent + '%');
  546. } else {
  547. left.width(parent.width());
  548. right.hide();
  549. }
  550. };
  551. const showGclSideTools = function (show) {
  552. const left = $('#gcl-left-view'), right = $('#gcl-right-view'), parent = left.parent();
  553. if (show) {
  554. right.show();
  555. autoFlashHeight();
  556. /**
  557. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  558. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  559. * 故需要通过最终的parent.width再计算一次left.width
  560. *
  561. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  562. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  563. *
  564. */
  565. //left.css('width', parent.width() - right.outerWidth());
  566. //left.css('width', parent.width() - right.outerWidth());
  567. const percent = 100 - right.outerWidth() /parent.width() * 100;
  568. left.css('width', percent + '%');
  569. } else {
  570. left.width(parent.width());
  571. right.hide();
  572. }
  573. };
  574. $('a', '#tz-side-menu').bind('click', function (e) {
  575. e.preventDefault();
  576. const tab = $(this), tabPanel = $(tab.attr('content'));
  577. // 展开工具栏、切换标签
  578. if (!tab.hasClass('active')) {
  579. // const close = $('.active', '#side-menu').length === 0;
  580. $('a', '#tz-side-menu').removeClass('active');
  581. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  582. tab.addClass('active');
  583. tabPanel.addClass('active');
  584. // $('.tab-content .tab-pane').removeClass('active');
  585. showTzSideTools(tab.hasClass('active'));
  586. if (tab.attr('content') === '#tz-search') {
  587. if (!ledgerSearch) {
  588. ledgerSearch = $.ledgerSearch({
  589. selector: '#tz-search',
  590. ledger: { billsTree: cTree, pos: cPos },
  591. resultSpreadSetting: {
  592. cols: [
  593. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  594. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  595. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  596. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  597. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  598. ],
  599. emptyRows: 0,
  600. headRows: 1,
  601. headRowHeight: [32],
  602. headColWidth: [30],
  603. defaultRowHeight: 21,
  604. headerFont: '12px 微软雅黑',
  605. font: '12px 微软雅黑',
  606. selectedBackColor: '#fffacd',
  607. readOnly: true,
  608. },
  609. locate: function(cur) {
  610. if (!cur.lid) return;
  611. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  612. loadPosData();
  613. if (cur.pid && cur.pid !== -1) {
  614. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  615. SpreadJsObj.locateRow(posSheet, pIndex);
  616. }
  617. },
  618. });
  619. }
  620. ledgerSearch.spread.refresh();
  621. }
  622. } else { // 收起工具栏
  623. tab.removeClass('active');
  624. tabPanel.removeClass('active');
  625. showTzSideTools(tab.hasClass('active'));
  626. }
  627. billsSpread.refresh();
  628. posSpread.refresh();
  629. });
  630. $('a', '#gcl-side-menu').bind('click', function (e) {
  631. e.preventDefault();
  632. const tab = $(this), tabPanel = $(tab.attr('content'));
  633. // 展开工具栏、切换标签
  634. if (!tab.hasClass('active')) {
  635. // const close = $('.active', '#side-menu').length === 0;
  636. $('a', '#gcl-side-menu').removeClass('active');
  637. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  638. tab.addClass('active');
  639. tabPanel.addClass('active');
  640. // $('.tab-content .tab-pane').removeClass('active');
  641. showGclSideTools(tab.hasClass('active'));
  642. if (tab.attr('content') === '#gcl-search') {
  643. if (!gclSearch) {
  644. gclSearch = $.gclSearch({
  645. selector: '#gcl-search',
  646. gcl: { bills: gclGatherData, getBillsXmj: function(node){ return node.leafXmjs; } },
  647. searchField: { bills: ['b_code', 'name'], xmj: ['code', 'dwgc', 'fbgc', 'fxgc', 'jldy', 'bwmx'], },
  648. resultSpreadSetting: {
  649. cols: [
  650. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  651. {title: '项目节编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  652. {title: '名称', field: 'name', width: 120, hAlign: 0, formatter: '@'},
  653. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  654. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  655. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  656. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  657. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  658. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  659. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  660. ],
  661. emptyRows: 0,
  662. headRows: 1,
  663. headRowHeight: [32],
  664. headColWidth: [30],
  665. defaultRowHeight: 21,
  666. headerFont: '12px 微软雅黑',
  667. font: '12px 微软雅黑',
  668. selectedBackColor: '#fffacd',
  669. readOnly: true,
  670. },
  671. locate: function(cur) {
  672. if (!cur.bid) return;
  673. const bIndex = gclSheet.zh_data.findIndex(x => { return x.id === cur.bid; });
  674. SpreadJsObj.locateRow(gclSheet, bIndex);
  675. loadLeafXmjData();
  676. if (cur.xid && cur.xid !== -1) {
  677. const xIndex = leafXmjSheet.zh_data.findIndex(x => { return x.mx_id === cur.xid; });
  678. SpreadJsObj.locateRow(leafXmjSheet, xIndex);
  679. }
  680. },
  681. });
  682. }
  683. gclSearch.spread.refresh();
  684. }
  685. } else { // 收起工具栏
  686. tab.removeClass('active');
  687. tabPanel.removeClass('active');
  688. showGclSideTools(tab.hasClass('active'));
  689. }
  690. gclSpread.refresh();
  691. leafXmjSpread.refresh();
  692. });
  693. $('#exportExcel').click(function () {
  694. const exportLedger = function () {
  695. const data = [], groupData = [];
  696. if (!billsSheet.zh_tree) return;
  697. billsSheet.zh_tree.recursiveExe(function(node) {
  698. if (node.children && node.children.length > 0) {
  699. node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
  700. } else {
  701. const posRange = cPos.getLedgerPos(node.id);
  702. node._export_group = posRange ? posRange.length : 0;
  703. }
  704. });
  705. for (const node of billsSheet.zh_tree.nodes) {
  706. data.push(node);
  707. const posRange = cPos.getLedgerPos(node.id);
  708. if (posRange && posRange.length > 0) {
  709. if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
  710. for (const pr of posRange) {
  711. data.push(pr);
  712. }
  713. }
  714. }
  715. SpreadExcelObj.exportSimpleXlsxSheet(exportBillsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx", groupData);
  716. };
  717. const exportGcl = function () {
  718. const data = [];
  719. if (!gclSheet.zh_data) return;
  720. for (const node of gclSheet.zh_data) {
  721. data.push(node);
  722. for (const leafXmj of node.leafXmjs) {
  723. data.push(leafXmj);
  724. }
  725. }
  726. SpreadExcelObj.exportSimpleXlsxSheet(exportGclSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  727. };
  728. const exportChapter = function () {
  729. SpreadExcelObj.exportSimpleXlsxSheet(chapterSpreadSetting, chapterSheet.zh_data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  730. };
  731. const cur = $('.active[name=compareType]').attr('href');
  732. if (cur.indexOf('gcl') >= 0) {
  733. exportGcl();
  734. } else if (cur.indexOf('chapter') >= 0) {
  735. exportChapter();
  736. } else {
  737. exportLedger();
  738. }
  739. });
  740. $('[name=compare-data]').click(function () {
  741. initSpreadSettingWithRoles(compareStages);
  742. SpreadJsObj.reLoadSheetHeader(billsSheet);
  743. SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length + billsSpreadSetting.specExtraCols.length);
  744. SpreadJsObj.reLoadSheetHeader(posSheet);
  745. SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length + posSpreadSetting.specExtraCols.length);
  746. SpreadJsObj.reLoadSheetHeader(gclSheet);
  747. SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length + gclSpreadSetting.specExtraCols.length);
  748. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  749. SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.length + leafXmjSpreadSetting.specExtraCols.length);
  750. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  751. SpreadJsObj.reloadColData(chapterSheet, chapterSpreadSetting.baseCols.length, compareStages.length * chapterSpreadSetting.extraCols.length + chapterSpreadSetting.specExtraCols.length);
  752. });
  753. $('[name=compareType]').click(function () {
  754. $('[name=compareType]').removeClass('active');
  755. $(this).addClass('active');
  756. $('#compareType').children().removeClass('active');
  757. $(this.getAttribute('href')).addClass('active');
  758. billsSpread.refresh();
  759. posSpread.refresh();
  760. gclSpread.refresh();
  761. leafXmjSpread.refresh();
  762. chapterSpread.refresh();
  763. });
  764. $('#select-qi-all').click(function() {
  765. const check = this.checked;
  766. $('input', 'tr[stage-id]').each((i, x) => {
  767. x.checked = check;
  768. })
  769. });
  770. });