revise_history.js 12 KB

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