revise_history.js 11 KB

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