revise_history.js 12 KB

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