measure_compare.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. markFoldKey: 'bills-fold',
  143. markFoldSubKey: window.location.pathname.split('/')[2],
  144. });
  145. const cPos = new MasterPosData({
  146. id: 'id', ledgerId: 'lid', masterId: 'id', minorId: 'pid',
  147. calcFun: function (pos) {
  148. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  149. }
  150. });
  151. postData(window.location.pathname + '/load', {main: true}, function (result) {
  152. cTree.loadDatas(result.main.ledger);
  153. cPos.loadDatas(result.main.pos);
  154. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  155. loadPosData(0);
  156. }, null, true);
  157. function loadPosData(iRow) {
  158. const node = iRow ? billsSheet.zh_tree.nodes[iRow] : SpreadJsObj.getSelectObject(billsSheet);
  159. if (node) {
  160. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, cPos.getLedgerPos(node.id));
  161. } else {
  162. SpreadJsObj.loadSheetData(posSheet, SpreadJsObj.DataType.Data, []);
  163. }
  164. SpreadJsObj.resetTopAndSelect(posSheet);
  165. }
  166. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  167. if (info.newSelections) {
  168. const iNewRow = info.newSelections[0].row;
  169. if (info.oldSelections) {
  170. const iOldRow = info.oldSelections[0].row;
  171. if (iNewRow !== iOldRow) {
  172. SpreadJsObj.resetTopAndSelect(posSheet);
  173. loadPosData(iNewRow);
  174. }
  175. } else {
  176. loadPosData(iNewRow);
  177. }
  178. }
  179. });
  180. $('#select-qi-ok').click(function () {
  181. function refreshView () {
  182. const compareStages = [];
  183. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  184. const tr = trs[order];
  185. if ($('input', tr)[0].checked) {
  186. compareStages.push(order + 1);
  187. }
  188. }
  189. //setLocalCache(cCacheKey, compareStages.join(','));
  190. initSpreadSettingWithRoles(compareStages);
  191. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  192. treeCalc.calculateAll(cTree);
  193. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, cTree);
  194. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  195. loadPosData();
  196. }
  197. let loadData = [], showData = [], trs = $('tr[stage-id]');
  198. for (let order = 0, iLength = trs.length; order < iLength; order++) {
  199. const tr = trs[order];
  200. if ($('input[type=checkbox]', tr)[0].checked) {
  201. if (!cTree.minorData[order + 1]) {
  202. loadData.push(order + 1);
  203. }
  204. showData.push(order + 1);
  205. }
  206. }
  207. if (loadData.length > 0) {
  208. postData(window.location.pathname + '/load', {stages: loadData}, function (result) {
  209. for (const aData of result.stages) {
  210. calculateStageLedgerData(aData.bills);
  211. cTree.loadMinorData(aData.bills, aData.order + '', ['gather_qty', 'gather_tp'], ['gather_tp']);
  212. treeCalc.calculateAll(cTree);
  213. calculateStagePosData(aData.pos);
  214. cPos.loadMinorData(aData.pos, aData.order + '', ['gather_qty']);
  215. }
  216. refreshView();
  217. $('#select-qi').modal('hide');
  218. }, null, true);
  219. } else {
  220. refreshView();
  221. $('#select-qi').modal('hide');
  222. }
  223. });
  224. (function (select, sheet) {
  225. $(select).click(function () {
  226. if (!sheet.zh_tree) return;
  227. const tag = $(this).attr('tag');
  228. const tree = sheet.zh_tree;
  229. switch (tag) {
  230. case "1":
  231. case "2":
  232. case "3":
  233. case "4":
  234. case "5":
  235. tree.expandByLevel(parseInt(tag));
  236. SpreadJsObj.refreshTreeRowVisible(sheet);
  237. break;
  238. case "last":
  239. tree.expandByCustom(() => { return true; });
  240. SpreadJsObj.refreshTreeRowVisible(sheet);
  241. break;
  242. case "leafXmj":
  243. tree.expandToLeafXmj();
  244. SpreadJsObj.refreshTreeRowVisible(sheet);
  245. break;
  246. }
  247. });
  248. })('a[name=showLevel]', billsSheet);
  249. $('#exportExcel').click(function () {
  250. const data = [];
  251. if (!billsSheet.zh_tree) return;
  252. for (const node of billsSheet.zh_tree.nodes) {
  253. data.push(node);
  254. const posRange = cPos.getLedgerPos(node.id);
  255. if (posRange && posRange.length > 0) {
  256. for (const pr of posRange) {
  257. data.push(pr);
  258. }
  259. }
  260. }
  261. SpreadExcelObj.exportSimpleXlsxSheet(billsSpreadSetting, data, $('.sidebar-title').attr('data-original-title') + "-多期比较.xlsx");
  262. });
  263. });