measure_compare.js 10 KB

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