composition.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * 配合比相关
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/7/10
  6. * @version
  7. */
  8. let mixRatioSpread = null;
  9. let machineSpread = null;
  10. let isDeleting = false;
  11. $(document).ready(function() {
  12. // 切换tab触发refresh
  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 === "mix-ratio") {
  18. if (mixRatioSpread === null) {
  19. mixRatioSpread = new CompositionSpread();
  20. mixRatioSpread.init(currentTag);
  21. mixRatioSpread.initRightClick(currentTag);
  22. mixRatioSpread.successCallback = compositionSuccess;
  23. }
  24. // 筛选数据显示(显示混凝土、砂浆、配合比)
  25. projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO]);
  26. projectGLJSheet.selectRow(projectGLJSpread.firstMixRatioRow);
  27. projectGLJId = projectGLJSheet.getActiveDataByField('id');
  28. // 获取数据
  29. mixRatioSpread.getRatioData(projectGLJId);
  30. }
  31. if (currentTag === "machine") {
  32. if (machineSpread === null) {
  33. machineSpread = new CompositionSpread();
  34. machineSpread.init(currentTag);
  35. machineSpread.initRightClick(currentTag);
  36. machineSpread.successCallback = compositionSuccess;
  37. }
  38. // 筛选数据显示(显示普通机械)
  39. projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.GENERAL_MACHINE]);
  40. projectGLJSheet.selectRow(projectGLJSpread.firstMachineRow);
  41. projectGLJId = projectGLJSheet.getActiveDataByField('id');
  42. // 获取数据
  43. machineSpread.getRatioData(projectGLJId);
  44. }
  45. });
  46. });
  47. /**
  48. * 成功事件
  49. *
  50. * @param {object} info
  51. * @return {void}
  52. */
  53. function compositionSuccess(info) {
  54. // 成功则对相应的总消耗量进行设置
  55. let row= projectGLJSheet.sheet.getActiveRowIndex();//取父机械或组成物的下标
  56. let parentData = jsonData[row];
  57. let ratioData = _.find(parentData.ratio_data,{"id":info.id});
  58. let con_key = gljOprObj.getIndex(ratioData,gljKeyArray);
  59. for(let i=0;i< jsonData.length;i++){
  60. let tem_key = gljOprObj.getIndex(jsonData[i],gljKeyArray);
  61. if(con_key == tem_key){
  62. //乘以父工料机的消耗量得到该组成物总消耗量的改变量
  63. info.change = operationWithRound(parentData.quantity,info.change,"glj.quantity","*");
  64. projectGLJSheet.setCellByField('quantity', info.change, true,i);
  65. }
  66. }
  67. // 设置父级3个价格
  68. projectGLJSheet.setCellByField('unit_price.market_price', info.parentMarketPrice, false);
  69. projectGLJSheet.setCellByField('unit_price.base_price', info.parentBasePrice, false);
  70. projectGLJSheet.setCellByField('adjust_price', info.parentMarketPrice, false);
  71. // 更新组成物缓存
  72. projectObj.project.composition.loadData();
  73. }