ledger_audit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/5/30
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function getTenderId() {
  11. return window.location.pathname.split('/')[2];
  12. }
  13. function checkTzMeasureType () {
  14. return tender.measure_type === measureType.tz.value;
  15. }
  16. $(document).ready(() => {
  17. autoFlashHeight();
  18. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  19. const treeSetting = {
  20. id: 'ledger_id',
  21. pid: 'ledger_pid',
  22. order: 'order',
  23. level: 'level',
  24. rootId: -1,
  25. keys: ['id', 'tender_id', 'ledger_id'],
  26. preUrl: '/ledger',
  27. autoExpand: 3,
  28. // markFoldKey: 'bills-fold',
  29. // markFoldSubKey: window.location.pathname.split('/')[2],
  30. markExpandKey: 'bills-expand',
  31. markExpandSubKey: window.location.pathname.split('/')[2],
  32. };
  33. if (checkTzMeasureType()) {
  34. treeSetting.calcFields = ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];
  35. } else {
  36. treeSetting.calcFields = ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];
  37. }
  38. const ledgerTree = createNewPathTree('fx', treeSetting);
  39. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  40. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  41. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  42. // 初始化 部位明细
  43. const pos = new PosData({
  44. id: 'id', ledgerId: 'lid',
  45. });
  46. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  47. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  48. $.subMenu({
  49. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  50. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  51. key: 'menu.1.0.0',
  52. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  53. callback: function (info) {
  54. if (info.mini) {
  55. $('.panel-title').addClass('fluid');
  56. $('#sub-menu').removeClass('panel-sidebar');
  57. } else {
  58. $('.panel-title').removeClass('fluid');
  59. $('#sub-menu').addClass('panel-sidebar');
  60. }
  61. autoFlashHeight();
  62. ledgerSpread.refresh();
  63. posSpread.refresh();
  64. }
  65. });
  66. const loadCurPosData = function () {
  67. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  68. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  69. if (node) {
  70. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  71. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  72. } else {
  73. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  74. }
  75. };
  76. // 台账模式加载部位明细数据
  77. if (checkTzMeasureType()) {
  78. $.divResizer({
  79. select: '#main-resize',
  80. callback: function () {
  81. ledgerSpread.refresh();
  82. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  83. $(".sp-wrap").height(bcontent-30);
  84. posSpread.refresh();
  85. }
  86. });
  87. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  88. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  89. }
  90. postData('/tender/' + getTenderId() + '/ledger/load', null, function (data) {
  91. ledgerTree.loadDatas(data.bills);
  92. treeCalc.calculateAll(ledgerTree);
  93. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  94. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  95. pos.loadDatas(data.pos);
  96. loadCurPosData();
  97. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  98. }, null, true);
  99. ledgerSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  100. loadCurPosData();
  101. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  102. posSearch.search($('#pos-keyword').val());
  103. });
  104. ledgerSpread.bind(spreadNS.Events.TopRowChanged, function (e, info) {
  105. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  106. });
  107. let dealBills, searchLedger;
  108. $.divResizer({
  109. select: '#right-spr',
  110. callback: function () {
  111. ledgerSpread.refresh();
  112. if (posSpread) {
  113. posSpread.refresh();
  114. }
  115. if (dealBills) {
  116. dealBills.spread.refresh();
  117. }
  118. }
  119. });
  120. // 展开收起 签约清单|清单意见
  121. $('a', '.side-menu').bind('click', function () {
  122. const tab = $(this), tabPanel = $(tab.attr('content'));
  123. const showSideTools = function (show) {
  124. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  125. if (show) {
  126. right.show();
  127. autoFlashHeight();
  128. /**
  129. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  130. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  131. * 故需要通过最终的parent.width再计算一次left.width
  132. *
  133. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  134. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  135. *
  136. */
  137. // left.css('width', parent.width() - right.outerWidth());
  138. // left.css('width', parent.width() - right.outerWidth());
  139. const percent = 100 - right.outerWidth() /parent.width() * 100;
  140. left.css('width', percent + '%');
  141. } else {
  142. left.width(parent.width());
  143. right.hide();
  144. }
  145. };
  146. if (!tab.hasClass('active')) {
  147. $('a', '.side-menu').removeClass('active');
  148. tab.addClass('active');
  149. $('.tab-content .tab-pane').removeClass('active');
  150. tabPanel.addClass('active');
  151. showSideTools(tab.hasClass('active'));
  152. if (tab.attr('content') === '#deal-bills' && !dealBills) {
  153. dealBills = new DealBills($('#deal-bills-spread')[0], {
  154. cols: [
  155. {title: '清单编号', field: 'code', width: 85, formatter: '@', readOnly: true},
  156. {title: '名称', field: 'name', width: 150, formatter: '@', readOnly: true},
  157. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  158. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  159. {title: '数量', field: 'quantity', width: 50, readOnly: true},
  160. {title: '金額', field: 'total_price', width: 50, readOnly: true},
  161. ],
  162. emptyRows: 0,
  163. headRows: 1,
  164. headRowHeight: [32],
  165. defaultRowHeight: 21,
  166. headerFont: '12px 微软雅黑',
  167. font: '12px 微软雅黑',
  168. headColWidth: [30],
  169. selectedBackColor: '#fffacd',
  170. });
  171. dealBills.loadData();
  172. } else if (tab.attr('content') === '#search' && !searchLedger) {
  173. if (!searchLedger) {
  174. searchLedger = $.billsSearch({
  175. selector: '#search',
  176. searchSpread: ledgerSpread,
  177. resultSpreadSetting: {
  178. cols: [
  179. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  180. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  181. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  182. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  183. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  184. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  185. ],
  186. emptyRows: 0,
  187. headRows: 1,
  188. headRowHeight: [32],
  189. headColWidth: [30],
  190. defaultRowHeight: 21,
  191. headerFont: '12px 微软雅黑',
  192. font: '12px 微软雅黑',
  193. selectedBackColor: '#fffacd',
  194. },
  195. afterLocated: function () {
  196. loadCurPosData();
  197. }
  198. });
  199. }
  200. searchLedger.spread.refresh();
  201. }
  202. } else {
  203. tab.removeClass('active');
  204. tabPanel.removeClass('active');
  205. showSideTools(tab.hasClass('active'));
  206. }
  207. ledgerSpread.refresh();
  208. if (posSpread) {
  209. posSpread.refresh();
  210. }
  211. });
  212. class DealBills {
  213. constructor (obj, spreadSetting) {
  214. this.obj = obj;
  215. this.url = '/tender/' + getTenderId() + '/deal';
  216. this.spreadSetting = spreadSetting;
  217. this.spread = SpreadJsObj.createNewSpread(this.obj);
  218. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  219. }
  220. loadData () {
  221. const self = this;
  222. postData(this.url+'/get-data', {}, function (data) {
  223. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  224. });
  225. }
  226. }
  227. // 显示层次
  228. (function (select, sheet) {
  229. $(select).click(function () {
  230. if (!sheet.zh_tree) return;
  231. const tag = $(this).attr('tag');
  232. const tree = sheet.zh_tree;
  233. switch (tag) {
  234. case "1":
  235. case "2":
  236. case "3":
  237. case "4":
  238. case "5":
  239. tree.expandByLevel(parseInt(tag));
  240. SpreadJsObj.refreshTreeRowVisible(sheet);
  241. break;
  242. case "last":
  243. tree.expandByCustom(() => { return true; });
  244. SpreadJsObj.refreshTreeRowVisible(sheet);
  245. break;
  246. case "leafXmj":
  247. tree.expandToLeafXmj();
  248. SpreadJsObj.refreshTreeRowVisible(sheet);
  249. break;
  250. }
  251. });
  252. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  253. });
  254. // texterea换行
  255. function auditCheck(i) {
  256. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  257. $('textarea[name="opinion"]').eq(i).val(opinion);
  258. return true;
  259. }