ledger_audit.js 11 KB

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