area_increase_fee_view.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Created by zhang on 2020/1/10.
  3. */
  4. let areaIncreaseFeeObj = {
  5. setDefaultSetting:function () {
  6. if(!gljUtil.isDef(projectObj.project.property.areaSetting)){
  7. let data={
  8. labour:10,
  9. material:1.5,
  10. machine:0,
  11. };
  12. projectObj.project.updateProjectProperty(data,"areaSetting")
  13. }
  14. },
  15. casCadeUpdate:async function (node,newval,fieldName) {
  16. let datas = [];
  17. let data = {
  18. type:node.sourceType,
  19. data:{ID:node.data.ID}
  20. };
  21. setData(data.data,newval,fieldName);
  22. datas.push(data);
  23. setChildren(node,newval,datas);//同步设置所有子项
  24. let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
  25. projectObj.project.calcProgram.calcNodesAndSave(nodes,async function () {
  26. await OVER_HEIGHT.reCalcOverHeightFee();
  27. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(nodes);
  28. });
  29. function setChildren(pnode,newValue,datas) {//同步设置所有子项
  30. if(pnode.children.length > 0 && (pnode.children[0].sourceType == ModuleNames.bills || pnode.children[0].sourceType == ModuleNames.ration)){//设置子项
  31. for(let c of pnode.children){
  32. let data = {
  33. type:c.sourceType,
  34. data:{ID:c.data.ID}
  35. };
  36. setData(data.data,newval,fieldName);
  37. datas.push(data);
  38. setChildren(c,newValue,datas)
  39. }
  40. }
  41. }
  42. function setData(data,avalue,fieldName) {
  43. data[fieldName] = avalue;
  44. if(fieldName == "outPutMaxPrice") data.maxPrice = null;
  45. }
  46. },
  47. confirmAreaIncreaseFeeSetting:async function () {
  48. let labour = $("#areaIncreaseFee_labour").val();
  49. let material = $("#areaIncreaseFee_material").val();
  50. let machine = $("#areaIncreaseFee_machine").val();
  51. if(!settingNumCheck(labour,"人工")) return;
  52. if(!settingNumCheck(material,"材料")) return;
  53. if(!settingNumCheck(machine,"机械")) return;
  54. let areaSetting = {
  55. labour:scMathUtil.roundForObj(labour,2),
  56. material:scMathUtil.roundForObj(material,2),
  57. machine:scMathUtil.roundForObj(machine,2)
  58. };
  59. let tem ={
  60. type:'project',
  61. data:{ID:projectObj.project.ID(),"property.areaSetting":areaSetting}
  62. };
  63. $('#areaIncreaseFeeDiv').modal('hide');
  64. let needUpdate = false;
  65. for(let key in areaSetting){
  66. if(areaSetting[key] != projectObj.project.property.areaSetting[key]){
  67. needUpdate = true;
  68. break;
  69. }
  70. }
  71. if(needUpdate){
  72. let datas = this.getAreaIncreaseDatas();
  73. datas.push(tem);
  74. let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
  75. projectObj.project.calcProgram.calcNodesAndSave(nodes);
  76. }
  77. function settingNumCheck(value,type) {
  78. if(!number_util.isNum(value)){
  79. alert("输入的"+type+"数据类型不对,请重新输入!");
  80. return false;
  81. }
  82. if(parseFloat(value) < -100){
  83. alert("输入的"+type+"不能小于负100,请重新输入!");
  84. return false
  85. }
  86. return true;
  87. }
  88. },
  89. getAreaIncreaseDatas:function (withBills = false) {
  90. let datas = [];
  91. let rations = projectObj.project.Ration.datas;
  92. for(let r of rations){
  93. if(r.areaIncreaseFee == true){
  94. datas.push({type:"ration",data:{ID:r.ID,areaIncreaseFee:true}})
  95. }
  96. }
  97. if(withBills == true){
  98. let bills = projectObj.project.Bills.datas;
  99. for(let b of bills){
  100. if(b.areaIncreaseFee == true){
  101. datas.push({type:"bills",data:{ID:b.ID,areaIncreaseFee:true}})
  102. }
  103. }
  104. }
  105. return datas;
  106. },
  107. cancelAreaIncreaseFee:async function () {
  108. let datas = this.getAreaIncreaseDatas(true);
  109. //将值设置为false
  110. for(let d of datas){
  111. d.data.areaIncreaseFee = false;
  112. }
  113. let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
  114. projectObj.project.calcProgram.calcNodesAndSave(nodes,async function () {
  115. await OVER_HEIGHT.reCalcOverHeightFee();
  116. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(nodes);
  117. });
  118. }
  119. };
  120. $(function () {
  121. $("#areaIncreaseFeeConfirm").on("click",async function(e){
  122. areaIncreaseFeeObj.confirmAreaIncreaseFeeSetting();
  123. });
  124. $('#areaIncreaseFeeDiv').on('show.bs.modal', function (e) {
  125. let areaSetting = {
  126. labour:10,
  127. material:1.5,
  128. machine:0,
  129. };
  130. if(gljUtil.isDef(projectObj.project.property.areaSetting)) areaSetting = projectObj.project.property.areaSetting;
  131. $("#areaIncreaseFee_labour").val(areaSetting.labour);
  132. $("#areaIncreaseFee_material").val(areaSetting.material);
  133. $("#areaIncreaseFee_machine").val(areaSetting.machine);
  134. });
  135. });