composition.js 5.0 KB

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