measure_compare.js 9.3 KB

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