measure_compare.js 9.2 KB

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