measure_compare.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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, formatter: '@'},
  17. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, formatter: '@'},
  18. ],
  19. extraCols: [
  20. {title: '%s|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty%s', hAlign: 2, width: 60, formatter: '@'},
  21. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp%s', hAlign: 2, width: 60, formatter: '@'},
  22. ],
  23. emptyRows: 3,
  24. headRows: 2,
  25. headRowHeight: [25, 25],
  26. headerFont: '12px 微软雅黑',
  27. font: '12px 微软雅黑',
  28. defaultRowHeight: 21,
  29. readOnly: true,
  30. };
  31. const posSpreadSetting = {
  32. baseCols: [
  33. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  34. {title: '台账数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 60},
  35. ],
  36. extraCols: [
  37. {title: '%s数量', colSpan: '1', rowSpan: '1', field: 'gather_qty%s', hAlign: 2, width: 60},
  38. ],
  39. emptyRows: 3,
  40. headRows: 1,
  41. headRowHeight: [32],
  42. defaultRowHeight: 21,
  43. headerFont: '12px 微软雅黑',
  44. font: '12px 微软雅黑',
  45. readOnly: true,
  46. };
  47. function initSpreadSettingWithRoles(compareRoles) {
  48. function setSpreadSettingCols(setting, fieldSufs, Roles) {
  49. function addExtraCols(fieldSuf, Role) {
  50. for (const ec of setting.extraCols) {
  51. const col = JSON.parse(JSON.stringify(ec));
  52. col.title = _.replace(col.title, '%s', Role);
  53. col.field = _.replace(col.field, '%s', fieldSuf);
  54. setting.cols.push(col);
  55. }
  56. }
  57. setting.cols = [];
  58. for (const col of setting.baseCols) {
  59. setting.cols.push(col);
  60. }
  61. for (const index in fieldSufs) {
  62. addExtraCols(fieldSufs[index], Roles[index]);
  63. }
  64. }
  65. const fieldSufs = [], roles = [], trs = $('tr[stage-id]');
  66. for (let r of compareRoles) {
  67. if (r > 0) {
  68. const tr = trs[r-1];
  69. if (tr) {
  70. fieldSufs.push(r + '');
  71. roles.push(tr.children[0].textContent);
  72. }
  73. }
  74. }
  75. setSpreadSettingCols(billsSpreadSetting, fieldSufs, roles);
  76. setSpreadSettingCols(posSpreadSetting, fieldSufs, roles);
  77. }
  78. function calculateStageLedgerData(datas) {
  79. for (const d of datas) {
  80. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  81. d.gather_tp = ZhCalc.add(d.contract_tp, d.qc_tp);
  82. }
  83. }
  84. function calculateStagePosData(datas) {
  85. for (const d of datas) {
  86. d.gather_qty = ZhCalc.add(d.contract_qty, d.qc_qty);
  87. }
  88. }
  89. $(document).ready(() => {
  90. autoFlashHeight();
  91. initSpreadSettingWithRoles([]);
  92. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  93. const billsSheet = billsSpread.getActiveSheet();
  94. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  95. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  96. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  97. const posSheet = posSpread.getActiveSheet();
  98. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  99. $.subMenu({
  100. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  101. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  102. key: 'menu.1.0.0',
  103. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  104. callback: function (info) {
  105. if (info.mini) {
  106. $('.panel-title').addClass('fluid');
  107. $('#sub-menu').removeClass('panel-sidebar');
  108. } else {
  109. $('.panel-title').removeClass('fluid');
  110. $('#sub-menu').addClass('panel-sidebar');
  111. }
  112. autoFlashHeight();
  113. billsSpread.refresh();
  114. posSpread.refresh();
  115. }
  116. });
  117. // 上下窗口resizer
  118. $.divResizer({
  119. select: '#main-resize',
  120. callback: function () {
  121. billsSpread.refresh();
  122. let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  123. $(".sp-wrap").height(bcontent-30);
  124. posSpread.refresh();
  125. }
  126. });
  127. const cTree = createNewPathTree('master', {
  128. id: 'ledger_id',
  129. pid: 'ledger_pid',
  130. order: 'order',
  131. level: 'level',
  132. rootId: -1,
  133. keys: ['id', 'tender_id', 'ledger_id'],
  134. masterId: 'id',
  135. minorId: 'lid',
  136. calcFields: [],
  137. });
  138. const cPos = new MasterPosData({
  139. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  140. calcFun: function (pos) {
  141. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  142. }
  143. });
  144. postData(window.location.pathname + '/load', {main: true}, function (result) {
  145. cTree.loadDatas(result.main.ledger);
  146. cPos.loadDatas(result.main.pos);
  147. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  148. loadPosData(0);
  149. }, null, true);
  150. function loadPosData(iRow) {
  151. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  152. if (node) {
  153. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, cPos.getLedgerPos(node.id));
  154. } else {
  155. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, []);
  156. }
  157. SpreadJsObj.resetTopAndSelect(posSheet);
  158. }
  159. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  160. if (info.newSelections) {
  161. const iNewRow = info.newSelections[0].row;
  162. if (info.oldSelections) {
  163. const iOldRow = info.oldSelections[0].row;
  164. if (iNewRow !== iOldRow) {
  165. loadPosData(iNewRow);
  166. }
  167. } else {
  168. loadPosData(iNewRow);
  169. }
  170. }
  171. });
  172. $('#select-qi-ok').click(function () {
  173. function refreshView () {
  174. const compareStages = [];
  175. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  176. const tr = trs[order];
  177. if ($('input', tr)[0].checked) {
  178. compareStages.push(order + 1);
  179. }
  180. }
  181. //setLocalCache(cCacheKey, compareStages.join(','));
  182. initSpreadSettingWithRoles(compareStages);
  183. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  184. treeCalc.calculateAll(cTree);
  185. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  186. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  187. loadPosData();
  188. }
  189. let loadData = [], showData = [], trs = $('tr[stage-id]');
  190. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  191. const tr = trs[order];
  192. if ($('input[type=checkbox]', tr)[0].checked) {
  193. if (!cTree.minorData[order + 1]) {
  194. loadData.push(order + 1);
  195. }
  196. showData.push(order + 1);
  197. }
  198. }
  199. if (loadData.length > 0) {
  200. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  201. for (const aData of result.stages) {
  202. calculateStageLedgerData(aData.bills);
  203. cTree.loadMinorData(aData.bills, aData.order + '', ['gather_qty', 'gather_tp'], ['gather_tp']);
  204. treeCalc.calculateAll(cTree);
  205. calculateStagePosData(aData.pos);
  206. cPos.loadMinorData(aData.pos, aData.order + '', ['gather_qty']);
  207. }
  208. refreshView();
  209. $('#select-qi').modal('hide');
  210. }, null, true);
  211. } else {
  212. refreshView();
  213. $('#select-qi').modal('hide');
  214. }
  215. });
  216. (function (select, sheet) {
  217. $(select).click(function () {
  218. if (!sheet.zh_tree) return;
  219. const tag = $(this).attr('tag');
  220. const tree = sheet.zh_tree;
  221. switch (tag) {
  222. case "1":
  223. case "2":
  224. case "3":
  225. case "4":
  226. case "5":
  227. tree.expandByLevel(parseInt(tag));
  228. SpreadJsObj.refreshTreeRowVisible(sheet);
  229. break;
  230. case "last":
  231. tree.expandByCustom(() => { return true; });
  232. SpreadJsObj.refreshTreeRowVisible(sheet);
  233. break;
  234. case "leafXmj":
  235. tree.expandToLeafXmj();
  236. SpreadJsObj.refreshTreeRowVisible(sheet);
  237. break;
  238. }
  239. });
  240. })('a[name=showLevel]', billsSheet);
  241. $('#exportExcel').click(function () {
  242. const data = [];
  243. if (!billsSheet.zh_tree) return;
  244. for (const node of billsSheet.zh_tree.nodes) {
  245. data.push(node);
  246. const posRange = cPos.getLedgerPos(node.id);
  247. if (posRange && posRange.length > 0) {
  248. for (const pr of posRange) {
  249. data.push(pr);
  250. }
  251. }
  252. }
  253. SpreadExcelObj.exportSimpleXlsxSheet(billsSpreadSetting, data, $('h2')[0].innerHTML + "-多期比较.xlsx");
  254. });
  255. });