revise_history.js 12 KB

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