measure_compare.js 9.9 KB

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