revise_history.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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(window.location.pathname + '/load', {}, function (result) {
  151. billsTree.loadDatas(result.bills);
  152. treeCalc.calculateAll(billsTree);
  153. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  154. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  155. pos.loadDatas(result.pos);
  156. posSpreadObj.loadCurPosData();
  157. SpreadJsObj.resetTopAndSelect(posSheet);
  158. }, null);
  159. $.divResizer({
  160. select: '#revise-resize',
  161. callback: function () {
  162. billsSpread.refresh();
  163. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  164. $(".sp-wrap").height(bcontent-30);
  165. posSpread.refresh();
  166. }
  167. });
  168. let searchLedger;
  169. $.divResizer({
  170. select: '#revise-right-spr',
  171. callback: function () {
  172. billsSpread.refresh();
  173. if (posSpread) {
  174. posSpread.refresh();
  175. }
  176. if (searchLedger && searchLedger.spread) {
  177. searchLedger.spread.refresh();
  178. }
  179. }
  180. });
  181. // 展开收起标准清单
  182. $('a', '#side-menu').bind('click', function (e) {
  183. e.preventDefault();
  184. const tab = $(this), tabPanel = $(tab.attr('content'));
  185. const showSideTools = function (show) {
  186. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  187. if (show) {
  188. right.show();
  189. autoFlashHeight();
  190. /**
  191. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  192. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  193. * 故需要通过最终的parent.width再计算一次left.width
  194. *
  195. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  196. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  197. *
  198. */
  199. //left.css('width', parent.width() - right.outerWidth());
  200. //left.css('width', parent.width() - right.outerWidth());
  201. const percent = 100 - right.outerWidth() /parent.width() * 100;
  202. left.css('width', percent + '%');
  203. } else {
  204. left.width(parent.width());
  205. right.hide();
  206. }
  207. };
  208. // 展开工具栏、切换标签
  209. if (!tab.hasClass('active')) {
  210. const close = $('.active', '#side-menu').length === 0;
  211. $('a', '#side-menu').removeClass('active');
  212. tab.addClass('active');
  213. $('.tab-content .tab-pane').removeClass('active');
  214. tabPanel.addClass('active');
  215. showSideTools(tab.hasClass('active'));
  216. if (tab.attr('content') === '#search' && !searchLedger) {
  217. if (!searchLedger) {
  218. searchLedger = $.billsSearch({
  219. selector: '#search',
  220. searchSpread: billsSpread,
  221. resultSpreadSetting: {
  222. cols: [
  223. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  224. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  225. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  226. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  227. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  228. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  229. ],
  230. emptyRows: 0,
  231. headRows: 1,
  232. headRowHeight: [32],
  233. headColWidth: [30],
  234. defaultRowHeight: 21,
  235. headerFont: '12px 微软雅黑',
  236. font: '12px 微软雅黑',
  237. selectedBackColor: '#fffacd',
  238. },
  239. afterLocated: function () {
  240. posSpreadObj.loadCurPosData();
  241. }
  242. });
  243. }
  244. searchLedger.spread.refresh();
  245. }
  246. }
  247. else {// 收起工具栏
  248. tab.removeClass('active');
  249. tabPanel.removeClass('active');
  250. showSideTools(tab.hasClass('active'));
  251. }
  252. billsSpread.refresh();
  253. if (posSpread) {
  254. posSpread.refresh();
  255. }
  256. });
  257. // 显示层次
  258. (function (select, sheet) {
  259. $(select).click(function () {
  260. if (!sheet.zh_tree) return;
  261. const tag = $(this).attr('tag');
  262. const tree = sheet.zh_tree;
  263. switch (tag) {
  264. case "1":
  265. case "2":
  266. case "3":
  267. case "4":
  268. case "5":
  269. tree.expandByLevel(parseInt(tag));
  270. SpreadJsObj.refreshTreeRowVisible(sheet);
  271. break;
  272. case "last":
  273. tree.expandByCustom(() => { return true; });
  274. SpreadJsObj.refreshTreeRowVisible(sheet);
  275. break;
  276. case "leafXmj":
  277. tree.expandToLeafXmj();
  278. SpreadJsObj.refreshTreeRowVisible(sheet);
  279. break;
  280. }
  281. });
  282. })('a[name=showLevel]', billsSheet);
  283. $('#reviseHistory').change(function () {
  284. postData(window.location.pathname + '/info', { rid: this.value }, function (result) {
  285. $('#user-name').val(result.user_name);
  286. $('#content')[0].textContent = result.content;
  287. $('#end-time').val(result.end_time_str);
  288. });
  289. });
  290. });