measure_compare.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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: 'gather_qty%s', hAlign: 2, width: 60, type: 'Number', },
  21. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp%s', hAlign: 2, width: 60, type: 'Number', },
  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. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  99. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  100. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  101. const posSheet = posSpread.getActiveSheet();
  102. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  103. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  104. $.subMenu({
  105. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  106. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  107. key: 'menu.1.0.0',
  108. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  109. callback: function (info) {
  110. if (info.mini) {
  111. $('.panel-title').addClass('fluid');
  112. $('#sub-menu').removeClass('panel-sidebar');
  113. } else {
  114. $('.panel-title').removeClass('fluid');
  115. $('#sub-menu').addClass('panel-sidebar');
  116. }
  117. autoFlashHeight();
  118. billsSpread.refresh();
  119. posSpread.refresh();
  120. }
  121. });
  122. // 上下窗口resizer
  123. $.divResizer({
  124. select: '#main-resize',
  125. callback: function () {
  126. billsSpread.refresh();
  127. let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  128. $(".sp-wrap").height(bcontent-30);
  129. posSpread.refresh();
  130. }
  131. });
  132. const cTree = createNewPathTree('master', {
  133. id: 'ledger_id',
  134. pid: 'ledger_pid',
  135. order: 'order',
  136. level: 'level',
  137. rootId: -1,
  138. keys: ['id', 'tender_id', 'ledger_id'],
  139. masterId: 'id',
  140. minorId: 'lid',
  141. calcFields: [],
  142. });
  143. const cPos = new MasterPosData({
  144. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  145. calcFun: function (pos) {
  146. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  147. }
  148. });
  149. postData(window.location.pathname + '/load', {main: true}, function (result) {
  150. cTree.loadDatas(result.main.ledger);
  151. cPos.loadDatas(result.main.pos);
  152. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  153. loadPosData(0);
  154. }, null, true);
  155. function loadPosData(iRow) {
  156. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  157. if (node) {
  158. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, cPos.getLedgerPos(node.id));
  159. } else {
  160. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, []);
  161. }
  162. SpreadJsObj.resetTopAndSelect(posSheet);
  163. }
  164. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  165. if (info.newSelections) {
  166. const iNewRow = info.newSelections[0].row;
  167. if (info.oldSelections) {
  168. const iOldRow = info.oldSelections[0].row;
  169. if (iNewRow !== iOldRow) {
  170. SpreadJsObj.resetTopAndSelect(posSheet);
  171. loadPosData(iNewRow);
  172. }
  173. } else {
  174. loadPosData(iNewRow);
  175. }
  176. }
  177. });
  178. $('#select-qi-ok').click(function () {
  179. function refreshView () {
  180. const compareStages = [];
  181. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  182. const tr = trs[order];
  183. if ($('input', tr)[0].checked) {
  184. compareStages.push(order + 1);
  185. }
  186. }
  187. //setLocalCache(cCacheKey, compareStages.join(','));
  188. initSpreadSettingWithRoles(compareStages);
  189. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  190. treeCalc.calculateAll(cTree);
  191. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  192. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  193. loadPosData();
  194. }
  195. let loadData = [], showData = [], trs = $('tr[stage-id]');
  196. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  197. const tr = trs[order];
  198. if ($('input[type=checkbox]', tr)[0].checked) {
  199. if (!cTree.minorData[order + 1]) {
  200. loadData.push(order + 1);
  201. }
  202. showData.push(order + 1);
  203. }
  204. }
  205. if (loadData.length > 0) {
  206. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  207. for (const aData of result.stages) {
  208. calculateStageLedgerData(aData.bills);
  209. cTree.loadMinorData(aData.bills, aData.order + '', ['gather_qty', 'gather_tp'], ['gather_tp']);
  210. treeCalc.calculateAll(cTree);
  211. calculateStagePosData(aData.pos);
  212. cPos.loadMinorData(aData.pos, aData.order + '', ['gather_qty']);
  213. }
  214. refreshView();
  215. $('#select-qi').modal('hide');
  216. }, null, true);
  217. } else {
  218. refreshView();
  219. $('#select-qi').modal('hide');
  220. }
  221. });
  222. (function (select, sheet) {
  223. $(select).click(function () {
  224. if (!sheet.zh_tree) return;
  225. const tag = $(this).attr('tag');
  226. const tree = sheet.zh_tree;
  227. switch (tag) {
  228. case "1":
  229. case "2":
  230. case "3":
  231. case "4":
  232. case "5":
  233. tree.expandByLevel(parseInt(tag));
  234. SpreadJsObj.refreshTreeRowVisible(sheet);
  235. break;
  236. case "last":
  237. tree.expandByCustom(() => { return true; });
  238. SpreadJsObj.refreshTreeRowVisible(sheet);
  239. break;
  240. case "leafXmj":
  241. tree.expandToLeafXmj();
  242. SpreadJsObj.refreshTreeRowVisible(sheet);
  243. break;
  244. }
  245. });
  246. })('a[name=showLevel]', billsSheet);
  247. $('#exportExcel').click(function () {
  248. const data = [];
  249. if (!billsSheet.zh_tree) return;
  250. for (const node of billsSheet.zh_tree.nodes) {
  251. data.push(node);
  252. const posRange = cPos.getLedgerPos(node.id);
  253. if (posRange && posRange.length > 0) {
  254. for (const pr of posRange) {
  255. data.push(pr);
  256. }
  257. }
  258. }
  259. SpreadExcelObj.exportSimpleXlsxSheet(billsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  260. });
  261. });