lib_detail.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. 'use strict';
  2. /**
  3. * 指标库-项目节参数
  4. *
  5. * @author Mai
  6. * @date 2018/4/25
  7. * @version
  8. */
  9. $(document).ready(function() {
  10. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  11. const billsSheet = billsSpread.getActiveSheet();
  12. const billsTree = createNewPathTree({
  13. id: 'n_id',
  14. pid: 'n_pid',
  15. order: 'n_order',
  16. level: 'n_level',
  17. full_path: 'n_full_path',
  18. is_leaf: 'n_is_leaf',
  19. rootId: -1,
  20. keys: ['id', 'lib_id', 'n_id'],
  21. preUrl: '/lib/detail',
  22. });
  23. billsTree.loadDatas(bills);
  24. SpreadJsObj.initSheet(billsSheet, {
  25. cols: [
  26. {title: '项目节编号', field: 'code', width: 120, cellType: 'tree', vAlign: 1, readOnly: true},
  27. {title: '清单编号', field: 'b_code', width: 80, vAlign: 1, readOnly: true},
  28. {title: '名称', field: 'name', width: 200, vAlign: 1, readOnly: true},
  29. {title: '单位', field: 'units', width: 62, vAlign: 1, hAlign: 1, readOnly: true},
  30. {title: '数量1', field: 'dgn_quantity1', width: 60, type: 'Number', vAlign: 1, readOnly: true},
  31. {title: '数量2', field: 'dgn_quantity2', width: 60, type: 'Number', vAlign: 1, readOnly: true},
  32. {title: '金额', field: 'total_price', width: 60, type: 'Number', vAlign: 1, readOnly: true},
  33. ],
  34. //treeCol: 0,
  35. emptyRows: 3,
  36. headRows: 2,
  37. headRowHeight: [28],
  38. defaultRowHeight: 30,
  39. });
  40. SpreadJsObj.loadSheetData(billsSheet, 'tree', billsTree);
  41. billsSheet.selectionPolicy(0);
  42. billsSheet.selectionUnit(1);
  43. billsSheet.clearSelection();
  44. billsSheet.setActiveCell(0);
  45. setquotaParamIndex();
  46. const spreadNS = GC.Spread.Sheets;
  47. //项目节选中
  48. billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  49. setquotaParamIndex();
  50. });
  51. function setquotaParamIndex() {
  52. const billsInfo = billsTree.nodes[billsSheet.getActiveRowIndex()];
  53. $('#codeName').text(billsInfo.name);
  54. $('#indexList').html('');
  55. $('#paramList').html('');
  56. if(billsInfo.match_node !== null){
  57. const postUrl = '/lib/getParamAndIndex';
  58. const postInfo = {
  59. lib_id: billsInfo.lib_id,
  60. node_id: billsInfo.match_node,
  61. bills_id: billsInfo.id
  62. };
  63. postData(postUrl, postInfo, function (result) {
  64. updateIndexHTML(result.indexList);
  65. updateParamHTML(result.paramList);
  66. });
  67. }
  68. }
  69. function updateIndexHTML(indexlist) {
  70. let index_html = '';
  71. const index_list = indexlist;
  72. for(let i in index_list) {
  73. index_html += '<tr> <td>'+ index_list[i].code +'</td> <td>'+ index_list[i].name +'</td>' +
  74. '<td>'+ (index_list[i].unit1 !== null ? index_list[i].unit1 : '') +'</td>' +
  75. '<td width="75">'+ (index_list[i].unit2 !== null ? index_list[i].unit2 : '') +'</td>' +
  76. '<td>'+ index_list[i].rule +'</td> <td class="text-right">'+ (index_list[i].eval_rule !== null ? index_list[i].eval_rule : '') +'</td>' +
  77. '<td class="text-right">'+ (index_list[i].value !== null ? index_list[i].value : '') +'</td> </tr>';
  78. }
  79. $('#indexList').html(index_html);
  80. }
  81. function updateParamHTML(paramlist) {
  82. let param_html = '';
  83. const param_list = paramlist;
  84. for(let i in param_list) {
  85. param_list[i].calc_value = param_list[i].calc_value !== null ? param_list[i].calc_value : '';
  86. let subNode = param_list[i].match_type === 3 ? '(自动绑定)' : (param_list[i].match_type === 4 ? param_list[i].match_key : '');
  87. param_html += '<tr> <td>'+ param_list[i].name +'</td><td>'+ subNode +'</td>' +
  88. '<td><input type="text" class="form-control form-control-sm text-right" value="'+ param_list[i].calc_value +'" ' +
  89. 'data-old-value="'+ param_list[i].calc_value +'" data-lib-id="'+ param_list[i].lib_id +'" ' +
  90. 'data-node-id="'+ param_list[i].node_id +'" data-code="'+ param_list[i].code +'"></td> </tr>';
  91. }
  92. $('#paramList').html(param_html);
  93. }
  94. $('body').on('blur', '#paramList input', function () {
  95. const self = $(this);
  96. if(self.val() != self.attr('data-old-value')){
  97. const postInfo = {
  98. lib_id: parseInt(self.attr('data-lib-id')),
  99. node_id: parseInt(self.attr('data-node-id')),
  100. code: self.attr('data-code'),
  101. updateType: 'modify',
  102. value: parseFloat(self.val())
  103. };
  104. const postUrl = '/lib/updateParamValue';
  105. postData(postUrl, postInfo, function (result) {
  106. self.attr('data-old-value', result.param.calc_value);
  107. updateIndexHTML(result.indexes);
  108. },function (result) {
  109. self.val(self.attr('data-old-value'));
  110. });
  111. }
  112. });
  113. $('#param-visible').click(function () {
  114. if (this.innerHTML === '展开') {
  115. this.innerHTML = '收起';
  116. $('.sjs-bottom-4').show();
  117. autoFlashHeight();
  118. } else {
  119. this.innerHTML = '展开';
  120. $('.sjs-bottom-4').hide();
  121. autoFlashHeight();
  122. }
  123. });
  124. });