revise_history.js 12 KB

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