measure_compare.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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, ledgerSearch, gclSearch;
  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. // 工具栏resizer
  329. $.divResizer({
  330. select: '#tz-right-spr',
  331. callback: function () {
  332. billsSpread.refresh();
  333. posSpread.refresh();
  334. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  335. if (ledgerSearch) ledgerSearch.spread.refresh();
  336. }
  337. });
  338. $.divResizer({
  339. select: '#gcl-right-spr',
  340. callback: function () {
  341. gclSpread.refresh();
  342. leafXmjSpread.refresh();
  343. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  344. if (gclSearch) gclSearch.spread.refresh();
  345. }
  346. });
  347. const cTree = createNewPathTree('master', {
  348. id: 'ledger_id',
  349. pid: 'ledger_pid',
  350. order: 'order',
  351. level: 'level',
  352. rootId: -1,
  353. keys: ['id', 'tender_id', 'ledger_id'],
  354. masterId: 'id',
  355. minorId: 'lid',
  356. calcFields: ['total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'],
  357. markFoldKey: 'bills-fold',
  358. markFoldSubKey: window.location.pathname.split('/')[2],
  359. });
  360. const cPos = new MasterPosData({
  361. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  362. calcFun: function (pos) {
  363. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  364. }
  365. });
  366. postData(window.location.pathname + '/load', {main: true}, function (result) {
  367. cTree.loadDatas(result.main.ledger);
  368. treeCalc.calculateAll(cTree);
  369. cPos.loadDatas(result.main.pos);
  370. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  371. loadPosData(0);
  372. const checkField = function (x) {
  373. if (x === 'quantity') return true;
  374. if (x === 'total_price') return true;
  375. if (x.indexOf('_qty') >= 0) return true;
  376. if (x.indexOf('_tp') >= 0) return true;
  377. return false;
  378. };
  379. gclGatherModel.loadGatherField(checkField, checkField);
  380. gclGatherModel.loadLedgerData(result.main.ledger);
  381. gclGatherModel.loadPosData(result.main.pos);
  382. gclGatherModel.loadDealBillsData(result.main.deal);
  383. gclGatherData = gclGatherModel.gatherGclData();
  384. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  385. loadLeafXmjData(0);
  386. spec = result.spec;
  387. const chapterData = gclGatherModel.gatherChapterData(chapter, spec, ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp']);
  388. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  389. }, null, true);
  390. function loadPosData(iRow) {
  391. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  392. const posRange = node ? (cPos.getLedgerPos(node.id) || []) : [];
  393. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, posRange);
  394. SpreadJsObj.resetTopAndSelect(posSheet);
  395. }
  396. function loadLeafXmjData(iRow) {
  397. const gcl = iRow ? gclSheet.zh_data[iRow] : SpreadJsObj.getSelectObject(gclSheet);
  398. if (gcl) {
  399. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  400. } else {
  401. SpreadJsObj.loadSheetData(leafXmjSheet, SpreadJsObj.DataType.Data, []);
  402. }
  403. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  404. }
  405. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  406. if (info.newSelections) {
  407. const iNewRow = info.newSelections[0].row;
  408. if (info.oldSelections) {
  409. const iOldRow = info.oldSelections[0].row;
  410. if (iNewRow !== iOldRow) {
  411. SpreadJsObj.resetTopAndSelect(posSheet);
  412. loadPosData(iNewRow);
  413. }
  414. } else {
  415. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  416. loadPosData(iNewRow);
  417. }
  418. }
  419. });
  420. gclSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  421. if (info.newSelections) {
  422. const iNewRow = info.newSelections[0].row;
  423. if (info.oldSelections) {
  424. const iOldRow = info.oldSelections[0].row;
  425. if (iNewRow !== iOldRow) {
  426. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  427. loadLeafXmjData(iNewRow);
  428. }
  429. } else {
  430. SpreadJsObj.resetTopAndSelect(leafXmjSheet);
  431. loadLeafXmjData(iNewRow);
  432. }
  433. }
  434. });
  435. const compareStages = [];
  436. $('#select-qi-ok').click(function () {
  437. function refreshView () {
  438. const gatherField = ['deal_tp', 'total_price', 'sum_contract_tp', 'sum_qc_tp', 'sum_gather_tp'];
  439. compareStages.length = 0;
  440. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  441. const tr = trs[order];
  442. if ($('input', tr)[0].checked) {
  443. compareStages.push(order + 1);
  444. gatherField.push(`contract_tp${order + 1}`, `qc_tp${order + 1}`, `gather_tp${order + 1}`);
  445. }
  446. }
  447. // setLocalCache(cCacheKey, compareStages.join(','));
  448. initSpreadSettingWithRoles(compareStages);
  449. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  450. treeCalc.calculateAll(cTree);
  451. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  452. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  453. loadPosData();
  454. SpreadJsObj.reLoadSheetHeader(gclSheet);
  455. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  456. gclGatherModel.loadLedgerData(cTree.datas);
  457. gclGatherModel.loadPosData(cPos.datas);
  458. gclGatherData = gclGatherModel.gatherGclData();
  459. SpreadJsObj.loadSheetData(gclSheet, SpreadJsObj.DataType.Data, gclGatherData);
  460. loadLeafXmjData(0);
  461. const chapterData = gclGatherModel.gatherChapterData(chapter, spec, gatherField);
  462. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  463. SpreadJsObj.loadSheetData(chapterSheet, SpreadJsObj.DataType.Data, chapterData);
  464. }
  465. let loadData = [], showData = [], trs = $('tr[stage-id]');
  466. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  467. const tr = trs[order];
  468. if ($('input[type=checkbox]', tr)[0].checked) {
  469. if (!cTree.minorData[order + 1]) {
  470. loadData.push(order + 1);
  471. }
  472. showData.push(order + 1);
  473. }
  474. }
  475. if (loadData.length > 0) {
  476. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  477. spec = result.spec;
  478. for (const aData of result.stages) {
  479. calculateStageLedgerData(aData.bills);
  480. cTree.loadMinorData(aData.bills, aData.order + '', ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], ['contract_tp', 'qc_tp', 'gather_tp']);
  481. calculateStagePosData(aData.pos);
  482. cPos.loadMinorData(aData.pos, aData.order + '', ['contract_qty', 'qc_qty', 'gather_qty']);
  483. }
  484. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  485. treeCalc.calculateAll(cTree);
  486. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  487. refreshView();
  488. $('#select-qi').modal('hide');
  489. }, null, true);
  490. } else {
  491. cTree.reCalcSumData(['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp'], showData);
  492. treeCalc.calculateAll(cTree);
  493. cPos.reCalcSumData(['contract_qty', 'qc_qty', 'gather_qty'], showData);
  494. refreshView();
  495. $('#select-qi').modal('hide');
  496. }
  497. });
  498. (function (select, sheet) {
  499. $(select).click(function () {
  500. if (!sheet.zh_tree) return;
  501. const tag = $(this).attr('tag');
  502. const tree = sheet.zh_tree;
  503. switch (tag) {
  504. case "1":
  505. case "2":
  506. case "3":
  507. case "4":
  508. case "5":
  509. tree.expandByLevel(parseInt(tag));
  510. SpreadJsObj.refreshTreeRowVisible(sheet);
  511. break;
  512. case "last":
  513. tree.expandByCustom(() => { return true; });
  514. SpreadJsObj.refreshTreeRowVisible(sheet);
  515. break;
  516. case "leafXmj":
  517. tree.expandToLeafXmj();
  518. SpreadJsObj.refreshTreeRowVisible(sheet);
  519. break;
  520. }
  521. });
  522. })('a[name=showLevel]', billsSheet);
  523. // 展开收起工具栏
  524. const showTzSideTools = function (show) {
  525. const left = $('#tz-left-view'), right = $('#tz-right-view'), parent = left.parent();
  526. if (show) {
  527. right.show();
  528. autoFlashHeight();
  529. /**
  530. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  531. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  532. * 故需要通过最终的parent.width再计算一次left.width
  533. *
  534. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  535. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  536. *
  537. */
  538. //left.css('width', parent.width() - right.outerWidth());
  539. //left.css('width', parent.width() - right.outerWidth());
  540. const percent = 100 - right.outerWidth() /parent.width() * 100;
  541. left.css('width', percent + '%');
  542. } else {
  543. left.width(parent.width());
  544. right.hide();
  545. }
  546. };
  547. const showGclSideTools = function (show) {
  548. const left = $('#gcl-left-view'), right = $('#gcl-right-view'), parent = left.parent();
  549. if (show) {
  550. right.show();
  551. autoFlashHeight();
  552. /**
  553. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  554. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  555. * 故需要通过最终的parent.width再计算一次left.width
  556. *
  557. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  558. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  559. *
  560. */
  561. //left.css('width', parent.width() - right.outerWidth());
  562. //left.css('width', parent.width() - right.outerWidth());
  563. const percent = 100 - right.outerWidth() /parent.width() * 100;
  564. left.css('width', percent + '%');
  565. } else {
  566. left.width(parent.width());
  567. right.hide();
  568. }
  569. };
  570. $('a', '#tz-side-menu').bind('click', function (e) {
  571. e.preventDefault();
  572. const tab = $(this), tabPanel = $(tab.attr('content'));
  573. // 展开工具栏、切换标签
  574. if (!tab.hasClass('active')) {
  575. // const close = $('.active', '#side-menu').length === 0;
  576. $('a', '#tz-side-menu').removeClass('active');
  577. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  578. tab.addClass('active');
  579. tabPanel.addClass('active');
  580. // $('.tab-content .tab-pane').removeClass('active');
  581. showTzSideTools(tab.hasClass('active'));
  582. if (tab.attr('content') === '#tz-search') {
  583. if (!ledgerSearch) {
  584. ledgerSearch = $.ledgerSearch({
  585. selector: '#tz-search',
  586. ledger: { billsTree: cTree, pos: cPos },
  587. resultSpreadSetting: {
  588. cols: [
  589. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  590. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  591. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  592. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  593. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  594. ],
  595. emptyRows: 0,
  596. headRows: 1,
  597. headRowHeight: [32],
  598. headColWidth: [30],
  599. defaultRowHeight: 21,
  600. headerFont: '12px 微软雅黑',
  601. font: '12px 微软雅黑',
  602. selectedBackColor: '#fffacd',
  603. readOnly: true,
  604. },
  605. locate: function(cur) {
  606. if (!cur.lid) return;
  607. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  608. loadPosData();
  609. if (cur.pid && cur.pid !== -1) {
  610. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  611. SpreadJsObj.locateRow(posSheet, pIndex);
  612. }
  613. },
  614. });
  615. }
  616. ledgerSearch.spread.refresh();
  617. }
  618. } else { // 收起工具栏
  619. tab.removeClass('active');
  620. tabPanel.removeClass('active');
  621. showTzSideTools(tab.hasClass('active'));
  622. }
  623. billsSpread.refresh();
  624. posSpread.refresh();
  625. });
  626. $('a', '#gcl-side-menu').bind('click', function (e) {
  627. e.preventDefault();
  628. const tab = $(this), tabPanel = $(tab.attr('content'));
  629. // 展开工具栏、切换标签
  630. if (!tab.hasClass('active')) {
  631. // const close = $('.active', '#side-menu').length === 0;
  632. $('a', '#gcl-side-menu').removeClass('active');
  633. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  634. tab.addClass('active');
  635. tabPanel.addClass('active');
  636. // $('.tab-content .tab-pane').removeClass('active');
  637. showGclSideTools(tab.hasClass('active'));
  638. if (tab.attr('content') === '#gcl-search') {
  639. if (!gclSearch) {
  640. gclSearch = $.gclSearch({
  641. selector: '#gcl-search',
  642. gcl: { bills: gclGatherData, getBillsXmj: function(node){ return node.leafXmjs; } },
  643. searchField: { bills: ['b_code', 'name'], xmj: ['code', 'dwgc', 'fbgc', 'fxgc', 'jldy', 'bwmx'], },
  644. resultSpreadSetting: {
  645. cols: [
  646. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  647. {title: '项目节编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  648. {title: '名称', field: 'name', width: 120, hAlign: 0, formatter: '@'},
  649. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  650. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  651. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  652. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  653. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  654. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  655. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  656. ],
  657. emptyRows: 0,
  658. headRows: 1,
  659. headRowHeight: [32],
  660. headColWidth: [30],
  661. defaultRowHeight: 21,
  662. headerFont: '12px 微软雅黑',
  663. font: '12px 微软雅黑',
  664. selectedBackColor: '#fffacd',
  665. readOnly: true,
  666. },
  667. locate: function(cur) {
  668. if (!cur.bid) return;
  669. const bIndex = gclSheet.zh_data.findIndex(x => { return x.id === cur.bid; });
  670. SpreadJsObj.locateRow(gclSheet, bIndex);
  671. loadLeafXmjData();
  672. if (cur.xid && cur.xid !== -1) {
  673. const xIndex = leafXmjSheet.zh_data.findIndex(x => { return x.id === cur.xid; });
  674. SpreadJsObj.locateRow(leafXmjSheet, xIndex);
  675. }
  676. },
  677. });
  678. }
  679. gclSearch.spread.refresh();
  680. }
  681. } else { // 收起工具栏
  682. tab.removeClass('active');
  683. tabPanel.removeClass('active');
  684. showGclSideTools(tab.hasClass('active'));
  685. }
  686. gclSpread.refresh();
  687. leafXmjSpread.refresh();
  688. });
  689. $('#exportExcel').click(function () {
  690. const exportLedger = function () {
  691. const data = [], groupData = [];
  692. if (!billsSheet.zh_tree) return;
  693. billsSheet.zh_tree.recursiveExe(function(node) {
  694. if (node.children && node.children.length > 0) {
  695. node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
  696. } else {
  697. const posRange = cPos.getLedgerPos(node.id);
  698. node._export_group = posRange ? posRange.length : 0;
  699. }
  700. });
  701. for (const node of billsSheet.zh_tree.nodes) {
  702. data.push(node);
  703. const posRange = cPos.getLedgerPos(node.id);
  704. if (posRange && posRange.length > 0) {
  705. if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
  706. for (const pr of posRange) {
  707. data.push(pr);
  708. }
  709. }
  710. }
  711. SpreadExcelObj.exportSimpleXlsxSheet(exportBillsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx", groupData);
  712. };
  713. const exportGcl = function () {
  714. const data = [];
  715. if (!gclSheet.zh_data) return;
  716. for (const node of gclSheet.zh_data) {
  717. data.push(node);
  718. for (const leafXmj of node.leafXmjs) {
  719. data.push(leafXmj);
  720. }
  721. }
  722. SpreadExcelObj.exportSimpleXlsxSheet(exportGclSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  723. };
  724. const exportChapter = function () {
  725. SpreadExcelObj.exportSimpleXlsxSheet(chapterSpreadSetting, chapterSheet.zh_data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  726. };
  727. const cur = $('.active[name=compareType]').attr('href');
  728. if (cur.indexOf('gcl') >= 0) {
  729. exportGcl();
  730. } else if (cur.indexOf('chapter') >= 0) {
  731. exportChapter();
  732. } else {
  733. exportLedger();
  734. }
  735. });
  736. $('[name=compare-data]').click(function () {
  737. initSpreadSettingWithRoles(compareStages);
  738. SpreadJsObj.reLoadSheetHeader(billsSheet);
  739. SpreadJsObj.reloadColData(billsSheet, billsSpreadSetting.baseCols.length, compareStages.length * billsSpreadSetting.extraCols.length + billsSpreadSetting.specExtraCols.length);
  740. SpreadJsObj.reLoadSheetHeader(posSheet);
  741. SpreadJsObj.reloadColData(posSheet, posSpreadSetting.baseCols.length, compareStages.length * posSpreadSetting.extraCols.length + posSpreadSetting.specExtraCols.length);
  742. SpreadJsObj.reLoadSheetHeader(gclSheet);
  743. SpreadJsObj.reloadColData(gclSheet, gclSpreadSetting.baseCols.length, compareStages.length * gclSpreadSetting.extraCols.length + gclSpreadSetting.specExtraCols.length);
  744. SpreadJsObj.reLoadSheetHeader(leafXmjSheet);
  745. SpreadJsObj.reloadColData(leafXmjSheet, leafXmjSpreadSetting.baseCols.length, compareStages.length * leafXmjSpreadSetting.extraCols.length + leafXmjSpreadSetting.specExtraCols.length);
  746. SpreadJsObj.reLoadSheetHeader(chapterSheet);
  747. SpreadJsObj.reloadColData(chapterSheet, chapterSpreadSetting.baseCols.length, compareStages.length * chapterSpreadSetting.extraCols.length + chapterSpreadSetting.specExtraCols.length);
  748. });
  749. $('[name=compareType]').click(function () {
  750. $('[name=compareType]').removeClass('active');
  751. $(this).addClass('active');
  752. $('#compareType').children().removeClass('active');
  753. $(this.getAttribute('href')).addClass('active');
  754. billsSpread.refresh();
  755. posSpread.refresh();
  756. gclSpread.refresh();
  757. leafXmjSpread.refresh();
  758. chapterSpread.refresh();
  759. });
  760. $('#select-qi-all').click(function() {
  761. const check = this.checked;
  762. $('input', 'tr[stage-id]').each((i, x) => {
  763. x.checked = check;
  764. })
  765. });
  766. });