revise_history.js 12 KB

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