ledger_audit.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/5/30
  7. * @version
  8. */
  9. function loadContent(data) {
  10. const html = [];
  11. html.push('<div name="auditContent" class="card my-3">');
  12. html.push('<div class="card-body">');
  13. html.push('<table class="table table-sm table-bordered mb-2">');
  14. console.log(data);
  15. console.log(data.rela_bills);
  16. const bills = JSON.parse(data.rela_bills);
  17. console.log(bills);
  18. for (const b of bills) {
  19. html.push('<tr bid=' + b.ledger_id + '>');
  20. const code = b.code ? b.code : b.b_code;
  21. html.push('<td>' + code + '</td>');
  22. html.push('<td>' + b.name + '</td>');
  23. html.push('</tr>');
  24. }
  25. html.push('</table>');
  26. html.push('<p>'+ data.content +'</p>');
  27. html.push('<span class="text-muted">' + data.in_time.toLocaleString() + '</span>');
  28. html.push('</div>');
  29. html.push('</div>');
  30. $('#opinion>div.sjs-height-2').append(html.join(''));
  31. }
  32. function loadContents(data) {
  33. $('div[name=auditContent]').remove();
  34. for (const d of data) {
  35. loadContent(d);
  36. }
  37. };
  38. $(document).ready(() => {
  39. autoFlashHeight();
  40. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  41. const ledgerTree = createNewPathTree('active', {
  42. id: 'ledger_id',
  43. pid: 'ledger_pid',
  44. order: 'order',
  45. level: 'level',
  46. rootId: -1,
  47. keys: ['id', 'tender_id', 'ledger_id']
  48. });
  49. ledgerTree.loadDatas(ledger);
  50. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  51. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  52. let dealBills;
  53. // 展开收起标准清单
  54. $('a', '.side-menu').bind('click', function () {
  55. const tab = $(this), tabPanel = $(tab.attr('content'));
  56. const showSideTools = function (show) {
  57. if (show) {
  58. $('.c-body.col-12').removeClass('col-12').addClass('col-8');
  59. $('.c-body.col-0').removeClass('col-0').addClass('col-4').show();
  60. } else {
  61. $('.c-body.col-8').removeClass('col-8').addClass('col-12');
  62. $('.c-body.col-4').removeClass('col-4').addClass('col-0').hide();
  63. }
  64. }
  65. if (!tab.hasClass('active')) {
  66. $('a', '#side-menu').removeClass('active');
  67. tab.addClass('active');
  68. showSideTools(tab.hasClass('active'));
  69. $('.tab-content .tab-pane').hide();
  70. tabPanel.show();
  71. if (tab.attr('content') === '#deal-bills' && !dealBills) {
  72. dealBills = new DealBills($('#deal-bills-spread')[0], {
  73. cols: [
  74. {title: '清单编号', field: 'code', width: 120, readOnly: true},
  75. {title: '名称', field: 'name', width: 230, readOnly: true},
  76. {title: '单位', field: 'unit', width: 50, readOnly: true},
  77. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  78. {title: '数量', field: 'quantity', width: 50, readOnly: true},
  79. ],
  80. emptyRows: 0,
  81. });
  82. dealBills.loadData();
  83. }
  84. } else {
  85. tab.removeClass('active');
  86. showSideTools(tab.hasClass('active'));
  87. tabPanel.hide();
  88. }
  89. ledgerSpread.refresh();
  90. });
  91. class DealBills {
  92. constructor (obj, spreadSetting) {
  93. this.obj = obj;
  94. this.url = '/deal';
  95. this.spreadSetting = spreadSetting;
  96. this.spread = SpreadJsObj.createNewSpread(this.obj);
  97. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  98. }
  99. loadData () {
  100. const self = this;
  101. postData(this.url+'/get-data', {}, function (data) {
  102. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  103. });
  104. }
  105. }
  106. // 右键菜单
  107. $.contextMenu({
  108. selector: '#ledger-spread',
  109. build: function ($trigger, e) {
  110. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  111. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  112. },
  113. items: {
  114. 'addRelaBills': {
  115. name: '添加至“清单意见”',
  116. icon: 'fa-sign-in',
  117. callback: function (key, opt) {
  118. const sheet = ledgerSpread.getActiveSheet();
  119. const selection = sheet.getSelections();
  120. const row = selection[0].row;
  121. const select = ledgerTree.nodes[row];
  122. const exist = $('tr[bid=' + select.ledger_id +']', '#rela_bills').length > 0;
  123. if (!exist) {
  124. const html = [];
  125. html.push('<tr bid=' + select.ledger_id + '>');
  126. html.push('<td>');
  127. html.push(select.code && select.code !== '' ? select.code : select.b_code);
  128. html.push('</td>');
  129. html.push('<td>' + select.name + '</td>');
  130. html.push('<td><a href="javascript: void(0);">移除</a></td>');
  131. html.push('</tr>');
  132. $('#rela_bills').append(html.join(''));
  133. }
  134. $('#billsHint').hide();
  135. if ($('tr[bid]', '#rela_bills').length === 1) {
  136. $('a', '#rela_bills').bind('click', function () {
  137. $(this).parent().parent().remove();
  138. if ($('tr[bid]', '#rela_bills').length === 0) {
  139. $('#billsHint').show();
  140. }
  141. });
  142. }
  143. },
  144. visible: function(key, opt){
  145. const sheet = ledgerSpread.getActiveSheet();
  146. const selection = sheet.getSelections();
  147. const row = selection[0].row;
  148. const select = ledgerTree.nodes[row];
  149. return select;
  150. }
  151. },
  152. }
  153. });
  154. $('textarea').bind('input propertychange', function () {
  155. if ($(this).val().length > 0) {
  156. $('#opinionHint').hide();
  157. } else {
  158. $('#opinionHint').show();
  159. }
  160. });
  161. $('#addContent').click(function () {
  162. const bills = [];
  163. for (const tr of $('#rela_bills>tr')) {
  164. bills.push($(tr).attr('bid'));
  165. }
  166. const data = {
  167. opinion: $('#content').val(),
  168. bills,
  169. };
  170. postData('/ledger/audit/addContent', data, (data) => {
  171. $('legend', '#opinion').text(userName + ' 清单意见');
  172. loadContents(data);
  173. });
  174. });
  175. $('select').change(function () {
  176. postData('/ledger/audit/getContent', {audit_id: parseInt($(this).val())}, (data) => {
  177. $('legend', '#opinion').text($(this).find('option:selected').text() + ' 清单意见');
  178. loadContents(data);
  179. });
  180. });
  181. });