revise_history.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. $(document).ready(() => {
  11. autoFlashHeight();
  12. // 初始化spread
  13. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  14. const billsSheet = billsSpread.getActiveSheet();
  15. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  16. const posSpread = isTz ? SpreadJsObj.createNewSpread($('#pos-spread')[0]) : null;
  17. const posSheet = isTz ? posSpread.getActiveSheet() : null;
  18. if (isTz) SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  19. const posSearch = isTz ? $.posSearch({selector: '#pos-search', searchSpread: posSpread}) : null;
  20. $.subMenu({
  21. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  22. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  23. key: 'revise.history.memu.1.0.0',
  24. callback: function (info) {
  25. if (info.mini) {
  26. $('.panel-title').addClass('fluid');
  27. $('#sub-menu').removeClass('panel-sidebar');
  28. } else {
  29. $('.panel-title').removeClass('fluid');
  30. $('#sub-menu').addClass('panel-sidebar');
  31. }
  32. autoFlashHeight();
  33. billsSpread.refresh();
  34. if (isTz) posSpread.refresh();
  35. }
  36. });
  37. // 初始化 清单树结构
  38. const treeSetting = {
  39. id: 'ledger_id',
  40. pid: 'ledger_pid',
  41. order: 'order',
  42. level: 'level',
  43. rootId: -1,
  44. keys: ['id', 'tender_id', 'ledger_id'],
  45. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  46. };
  47. if (!isTz) {
  48. treeSetting.calcFields.push('deal_tp');
  49. }
  50. treeSetting.calcFun = function (node) {
  51. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  52. };
  53. const billsTree = createNewPathTree('revise', treeSetting);
  54. billsTree.loadDatas(billsData);
  55. treeCalc.calculateAll(billsTree);
  56. // 加载至spread
  57. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  58. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  59. // 初始化 部位明细
  60. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  61. pos.loadDatas(posData);
  62. const billsTreeSpreadObj = {
  63. /**
  64. *
  65. * @param sheet
  66. * @param data
  67. */
  68. refreshTree: function (sheet, data) {
  69. SpreadJsObj.massOperationSheet(sheet, function () {
  70. const tree = sheet.zh_tree;
  71. // 处理删除
  72. if (data.delete) {
  73. data.delete.sort(function (a, b) {
  74. return b.deleteIndex - a.deleteIndex;
  75. });
  76. for (const d of data.delete) {
  77. sheet.deleteRows(d.deleteIndex, 1);
  78. }
  79. }
  80. // 处理新增
  81. if (data.create) {
  82. const newNodes = data.create;
  83. if (newNodes) {
  84. newNodes.sort(function (a, b) {
  85. return a.index - b.index;
  86. });
  87. for (const node of newNodes) {
  88. sheet.addRows(node.index, 1);
  89. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  90. }
  91. }
  92. }
  93. // 处理更新
  94. if (data.update) {
  95. const rows = [];
  96. for (const u of data.update) {
  97. rows.push(tree.nodes.indexOf(u));
  98. }
  99. SpreadJsObj.reLoadRowsData(sheet, rows);
  100. }
  101. // 处理展开
  102. if (data.expand) {
  103. const expanded = [];
  104. for (const e of data.expand) {
  105. if (expanded.indexOf(e) === -1) {
  106. const posterity = tree.getPosterity(e);
  107. for (const p of posterity) {
  108. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  109. expanded.push(p);
  110. }
  111. }
  112. }
  113. }
  114. });
  115. },
  116. selectionChanged: function (e, info) {
  117. if (info.newSelections[0].row !== info.oldSelections[0].row) {
  118. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  119. if (isTz) {
  120. posSpreadObj.loadCurPosData();
  121. posSearch.search($('#pos-keyword').val());
  122. }
  123. }
  124. },
  125. topRowChanged: function (e, info) {
  126. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  127. },
  128. };
  129. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  130. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  131. const posSpreadObj = {
  132. /**
  133. * 加载部位明细 根据当前台账选择节点
  134. */
  135. loadCurPosData: function () {
  136. const node = SpreadJsObj.getSelectObject(billsSheet);
  137. if (node) {
  138. const posData = pos.getLedgerPos(node.id) || [];
  139. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  140. } else {
  141. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  142. }
  143. SpreadJsObj.resetFieldReadOnly(posSheet);
  144. },
  145. };
  146. posSpreadObj.loadCurPosData();
  147. SpreadJsObj.resetTopAndSelect(posSheet);
  148. $.divResizer({
  149. select: '#revise-resize',
  150. callback: function () {
  151. billsSpread.refresh();
  152. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  153. $(".sp-wrap").height(bcontent-40);
  154. posSpread.refresh();
  155. }
  156. });
  157. let searchLedger;
  158. $.divResizer({
  159. select: '#revise-right-spr',
  160. callback: function () {
  161. billsSpread.refresh();
  162. if (posSpread) {
  163. posSpread.refresh();
  164. }
  165. if (searchLedger && searchLedger.spread) {
  166. searchLedger.spread.refresh();
  167. }
  168. }
  169. });
  170. // 展开收起标准清单
  171. $('a', '#side-menu').bind('click', function (e) {
  172. e.preventDefault();
  173. const tab = $(this), tabPanel = $(tab.attr('content'));
  174. const showSideTools = function (show) {
  175. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  176. if (show) {
  177. right.show();
  178. autoFlashHeight();
  179. /**
  180. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  181. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  182. * 故需要通过最终的parent.width再计算一次left.width
  183. *
  184. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  185. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  186. *
  187. */
  188. //left.css('width', parent.width() - right.outerWidth());
  189. //left.css('width', parent.width() - right.outerWidth());
  190. const percent = 100 - right.outerWidth() /parent.width() * 100;
  191. left.css('width', percent + '%');
  192. } else {
  193. left.width(parent.width());
  194. right.hide();
  195. }
  196. };
  197. // 展开工具栏、切换标签
  198. if (!tab.hasClass('active')) {
  199. const close = $('.active', '#side-menu').length === 0;
  200. $('a', '#side-menu').removeClass('active');
  201. tab.addClass('active');
  202. $('.tab-content .tab-pane').removeClass('active');
  203. tabPanel.addClass('active');
  204. showSideTools(tab.hasClass('active'));
  205. if (tab.attr('content') === '#search' && !searchLedger) {
  206. if (!searchLedger) {
  207. searchLedger = $.billsSearch({
  208. selector: '#search',
  209. searchSpread: billsSpread,
  210. resultSpreadSetting: {
  211. cols: [
  212. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  213. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  214. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  215. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  216. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  217. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  218. ],
  219. emptyRows: 0,
  220. headRows: 1,
  221. headRowHeight: [32],
  222. defaultRowHeight: 21,
  223. headerFont: '12px 微软雅黑',
  224. font: '12px 微软雅黑',
  225. },
  226. afterLocated: function () {
  227. posSpreadObj.loadCurPosData();
  228. }
  229. });
  230. }
  231. searchLedger.spread.refresh();
  232. }
  233. }
  234. else {// 收起工具栏
  235. tab.removeClass('active');
  236. tabPanel.removeClass('active');
  237. showSideTools(tab.hasClass('active'));
  238. }
  239. billsSpread.refresh();
  240. if (posSpread) {
  241. posSpread.refresh();
  242. }
  243. });
  244. // 显示层次
  245. (function (select, sheet) {
  246. $(select).click(function () {
  247. if (!sheet.zh_tree) return;
  248. const tag = $(this).attr('tag');
  249. const tree = sheet.zh_tree;
  250. switch (tag) {
  251. case "1":
  252. case "2":
  253. case "3":
  254. case "4":
  255. case "5":
  256. tree.expandByLevel(parseInt(tag));
  257. SpreadJsObj.refreshTreeRowVisible(sheet);
  258. break;
  259. case "last":
  260. tree.expandByCustom(() => { return true; });
  261. SpreadJsObj.refreshTreeRowVisible(sheet);
  262. break;
  263. case "leafXmj":
  264. tree.expandToLeafXmj();
  265. SpreadJsObj.refreshTreeRowVisible(sheet);
  266. break;
  267. }
  268. });
  269. })('a[name=showLevel]', billsSheet);
  270. $('#reviseHistory').change(function () {
  271. postData(window.location.pathname + '/info', { rid: this.value }, function (result) {
  272. $('#user-name').val(result.user_name);
  273. $('#content')[0].textContent = result.content;
  274. $('#end-time').val(result.end_time_str);
  275. });
  276. });
  277. });