ledger_audit.js 11 KB

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