machine.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * 机械单价相关
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/7/17
  6. * @version
  7. */
  8. let machineHeader = [];
  9. let machineSheet = null;
  10. let machineSpread = null;
  11. $(document).ready(function() {
  12. initMachineExcel();
  13. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  14. currentTag = $(e.target).data('name');
  15. // 获取工料机当前选中的行号
  16. let projectGLJId = 0;
  17. if (currentTag === "machine" && machineSpread !== null) {
  18. // 筛选数据显示(显示普通机械)
  19. filterDataByType([GLJTypeConst.GENERAL_MACHINE]);
  20. // 获取数据
  21. getRatioData(projectGLJId, getMachine);
  22. }
  23. });
  24. });
  25. /**
  26. * 初始化excel
  27. *
  28. * @return {void}
  29. */
  30. function initMachineExcel() {
  31. machineHeader = [
  32. {name: '编码', field: 'code', visible: true},
  33. {name: '名称', field: 'name', visible: true},
  34. {name: '单位', field: 'unit_price.unit', visible: true},
  35. {name: 'ID', field: 'id', visible: false},
  36. {name: '类型', field: 'unit_price.type', visible: false},
  37. {name: '基价单价', field: "unit_price.base_price", visible: true},
  38. {name: '调整基价', field: 'adjust_price', visible: true},
  39. {name: '市场单价', field: "unit_price.market_price", visible: true},
  40. {name: '用量', field: 'consumption', visible: true, validator: 'number'},
  41. {name: 'CID', field: 'mix_ratio_id', visible: false},
  42. ];
  43. let setting = {
  44. header: []
  45. };
  46. let columnInfo = [];
  47. for(let tmp of machineHeader) {
  48. setting.header.push({headerName: tmp.name, headerWidth: 120});
  49. columnInfo.push({name: tmp.field, displayName: tmp.name, visible: tmp.visible, cellType: tmp.cellType, size: 120});
  50. }
  51. machineSpread = sheetCommonObj.buildSheet(document.getElementById("machine"), setting, 3);
  52. machineSpread.options.scrollbarShowMax = true;
  53. machineSpread.options.scrollbarMaxAlign = true;
  54. machineSpread.options.showHorizontalScrollbar = true;
  55. machineSheet = machineSpread.getActiveSheet();
  56. // 编码列号
  57. let codeColumn = getFieldColumn(machineHeader, 'code');
  58. // 单位列号
  59. let unitColumn = getFieldColumn(machineHeader, 'unit_price.unit');
  60. // 消耗量列号
  61. let consumptionColumn = getFieldColumn(machineHeader, 'consumption');
  62. // 居中样式
  63. let centerStyleSetting = {hAlign: 1};
  64. machineSheet.setStyle(-1, codeColumn, getStyle(centerStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
  65. machineSheet.setStyle(-1, unitColumn, getStyle(centerStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
  66. // 设置表单不可编辑
  67. machineSheet.options.isProtected = true;
  68. // 设置可编辑列
  69. machineSheet.getRange(-1, consumptionColumn, -1, 1).locked(false);
  70. // 绑定数据格式
  71. machineSheet.autoGenerateColumns = false;
  72. machineSheet.bindColumns(columnInfo);
  73. // 绑定事件
  74. // machineSheet.bind(GC.Spread.Sheets.Events.ValueChanged, updateConsumption);
  75. }
  76. /**
  77. * 获取对应的机械单价成功后方法
  78. *
  79. * @param {Object} response
  80. * @return {void|boolean}
  81. */
  82. function getMachine(response, type) {
  83. switch (type) {
  84. case 'success':
  85. response.data = JSON.parse(response.data);
  86. // 设置数据
  87. machineSheet.setDataSource(response.data);
  88. ratioSpecialColumn(response.data);
  89. machineSpread.refresh();
  90. break;
  91. case 'fail':
  92. // 设置数据
  93. machineSheet.setDataSource(null);
  94. machineSpread.refresh();
  95. alert('不存在对应数据');
  96. break;
  97. }
  98. }