composition.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if($(e.target).data('name')==undefined){
  15. return;
  16. }
  17. currentTag = $(e.target).data('name');
  18. // 获取工料机当前选中的行号
  19. let projectGLJId = 0;
  20. if (currentTag === "mix-ratio") {
  21. if (mixRatioSpread === null) {
  22. mixRatioSpread = new CompositionSpread();
  23. mixRatioSpread.init(currentTag);
  24. mixRatioSpread.initRightClick(currentTag);
  25. mixRatioSpread.successCallback = compositionSuccess;
  26. }
  27. // 筛选数据显示(显示混凝土、砂浆、配合比)
  28. projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO,GLJTypeConst.MAIN_MATERIAL]);
  29. projectGLJSheet.selectRow(projectGLJSpread.firstMixRatioRow);
  30. projectGLJId = projectGLJSheet.getActiveDataByField('id');
  31. // 获取数据
  32. mixRatioSpread.getRatioData(projectGLJId);
  33. }
  34. if (currentTag === "machine") {
  35. if (machineSpread === null) {
  36. machineSpread = new CompositionSpread();
  37. machineSpread.init(currentTag);
  38. machineSpread.initRightClick(currentTag);
  39. machineSpread.successCallback = compositionSuccess;
  40. }
  41. // 筛选数据显示(显示普通机械)
  42. projectGLJSheet.filterData('unit_price.type', [GLJTypeConst.GENERAL_MACHINE]);
  43. projectGLJSheet.selectRow(projectGLJSpread.firstMachineRow);
  44. projectGLJId = projectGLJSheet.getActiveDataByField('id');
  45. // 获取数据
  46. machineSpread.getRatioData(projectGLJId);
  47. }
  48. });
  49. });
  50. /**
  51. * 成功事件
  52. *
  53. * @param {object} info
  54. * @return {void}
  55. */
  56. function compositionSuccess(info) {
  57. // 成功则对相应的总消耗量进行设置
  58. let row= projectGLJSheet.sheet.getActiveRowIndex();//取父机械或组成物的下标
  59. let parentData = jsonData[row];
  60. let ratioData = _.find(parentData.ratio_data,{"id":info.id});
  61. let con_key = gljOprObj.getIndex(ratioData,gljKeyArray);
  62. let updateNodes=[];
  63. for(let i=0;i< jsonData.length;i++){
  64. let tem_key = gljOprObj.getIndex(jsonData[i],gljKeyArray);
  65. if(con_key == tem_key){
  66. //乘以父工料机的消耗量得到该组成物总消耗量的改变量
  67. info.change = operationWithRound(parentData.quantity,info.change,"glj.quantity","*");
  68. projectGLJSheet.setCellByField('quantity', info.change, true,i);
  69. }
  70. }
  71. //更新ratio 数据
  72. ratioData[info.field]=info.newValue;
  73. //更新组成物map里的数据
  74. let p_key = gljOprObj.getIndex(parentData,gljKeyArray);
  75. let m_list = projectObj.project.projectGLJ.datas.mixRatioMap[p_key];
  76. let m_ratioData = _.find(m_list,{"id":info.id});
  77. if(m_ratioData){
  78. m_ratioData[info.field]=info.newValue;
  79. }
  80. // 设置父级3个价格
  81. parentData.unit_price.market_price = info.parentMarketPrice;
  82. parentData.unit_price.base_price = info.parentBasePrice;
  83. //更新表格
  84. projectGLJSheet.setCellByField('unit_price.market_price', info.parentMarketPrice, false);
  85. projectGLJSheet.setCellByField('base_price', info.parentBasePrice, false);
  86. projectGLJSheet.setCellByField('adjust_price', info.parentMarketPrice, false);
  87. // 更新组成物缓存
  88. projectObj.project.composition.loadData();
  89. //选查找使用了父项目工料机的定额工料机
  90. let ration_gljs = _.filter(projectObj.project.ration_glj.datas,{'projectGLJID':parentData.id});
  91. let nodes = projectObj.project.mainTree.nodes;
  92. let prefix = projectObj.project.mainTree.prefix;
  93. for(let rg of ration_gljs){
  94. let node = nodes[prefix+rg.rationID];
  95. if(node){
  96. updateNodes.push(node);
  97. }
  98. }
  99. //或者是使用了父项目工料机的工料机类型的定额
  100. let rations = _.filter(projectObj.project.Ration.datas,{'type':3,'projectGLJID':parentData.id});
  101. for(let r of rations){
  102. let r_node = nodes[prefix+r.ID];
  103. if(r_node){
  104. r_node.data.marketUnitFee=info.parentMarketPrice;
  105. updateNodes.push(r_node);
  106. }
  107. }
  108. if(updateNodes.length>0){
  109. projectObj.project.calcProgram.calcRationsAndSave(updateNodes);
  110. }
  111. gljOprObj.refreshView();
  112. }