lib_detail.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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: 50, vAlign: 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. let index_html = '';
  65. const index_list = result.indexList;
  66. for(let i in index_list) {
  67. index_html += '<tr> <td>'+ index_list[i].code +'</td> <td>'+ index_list[i].name +'</td>' +
  68. '<td>'+ (index_list[i].unit1 !== null ? index_list[i].unit1 : '') +'</td>' +
  69. '<td>'+ (index_list[i].unit2 !== null ? index_list[i].unit2 : '') +'</td>' +
  70. '<td>'+ index_list[i].rule +'</td> <td>'+ (index_list[i].eval_rule !== null ? index_list[i].eval_rule : '') +'</td>' +
  71. '<td>'+ (index_list[i].value !== null ? index_list[i].value : '') +'</td> </tr>';
  72. }
  73. $('#indexList').html(index_html);
  74. let param_html = '';
  75. const param_list = result.paramList;
  76. for(let i in param_list) {
  77. param_list[i].calc_value = param_list[i].calc_value !== null ? param_list[i].calc_value : '';
  78. let subNode = param_list[i].match_type === 3 ? '(自动绑定)' : (param_list[i].match_type === 4 ? param_list[i].match_key : '');
  79. param_html += '<tr> <td>'+ param_list[i].name +'</td><td>'+ subNode +'</td>' +
  80. '<td><input type="number" class="form-control form-control-sm" value="'+ param_list[i].calc_value +'" ' +
  81. 'data-old-value="'+ param_list[i].calc_value +'" data-lib-id="'+ param_list[i].lib_id +'" ' +
  82. 'data-node-id="'+ param_list[i].node_id +'" data-code="'+ param_list[i].code +'"></td> </tr>';
  83. }
  84. $('#paramList').html(param_html);
  85. });
  86. }
  87. }
  88. $('body').on('blur', '#paramList input', function () {
  89. if($(this).val() != $(this).attr('data-old-value')){
  90. const postInfo = {
  91. lib_id: parseInt($(this).attr('data-lib-id')),
  92. node_id: parseInt($(this).attr('data-node-id')),
  93. code: $(this).attr('data-code'),
  94. updateType: 'modify',
  95. value: parseFloat($(this).val())
  96. };
  97. $(this).attr('data-old-value', $(this).val());
  98. const postUrl = '/lib/updateParamValue';
  99. postData(postUrl, postInfo, function (result) {
  100. // console.log(result);
  101. });
  102. }
  103. })
  104. });