ration_coe.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var ration_coe = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration_coe = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. var sourceType = ModuleNames.ration_coe;
  14. this.getSourceType = function () {
  15. return sourceType;
  16. }
  17. proj.registerModule(ModuleNames.ration_coe, this);
  18. };
  19. // prototype用于定义public方法
  20. ration_coe.prototype.loadData = function (datas) {
  21. this.datas = datas;
  22. };
  23. // 提交数据后返回数据处理
  24. ration_coe.prototype.doAfterUpdate = function(err, data){
  25. if(!err){
  26. if(data.updateTpye=='ut_update'){
  27. this.refreshAfterUpdate(data);
  28. }else if(data.updateTpye=='ut_delete'){
  29. this.refreshAfterDelete(data);
  30. } else {
  31. this.refreshAfterSave(data);
  32. }
  33. }
  34. };
  35. ration_coe.prototype.refreshAfterSave=function(data){
  36. if(projectObj.project.ration_coe.datas&&Array.isArray(projectObj.project.ration_coe.datas)){
  37. projectObj.project.ration_coe.datas = projectObj.project.ration_coe.datas.concat(data);
  38. }else {
  39. projectObj.project.ration_coe.datas = data;
  40. }
  41. sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,data);
  42. gljOprObj.coeSheetData=data;
  43. // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  44. };
  45. ration_coe.prototype.refreshAfterUpdate=function(data){
  46. var coe_list = projectObj.project.ration_coe.datas;
  47. var coe_index= _.findIndex(coe_list,(coe)=>{
  48. return coe.ID==data.query.ID&&coe.projectID==data.query.projectID;
  49. })
  50. _.forEach(data.doc, function(n, key) {
  51. coe_list[coe_index][key] = n;
  52. });
  53. var showList = _.filter(coe_list,{'projectID':data.query.projectID,'rationID':coe_list[coe_index].rationID});
  54. gljOprObj.coeSheetData=showList;
  55. sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,showList);
  56. };
  57. ration_coe.prototype.refreshAfterDelete=function(data){
  58. var glj_list = projectObj.project.ration_coe.datas;
  59. _.remove(glj_list,data.query);
  60. _.remove(gljOprObj.sheetData,data.query);
  61. sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,gljOprObj.sheetData);
  62. };
  63. ration_coe.prototype.getRationCoedata=function(newRation,data){
  64. var criteria= {};
  65. criteria.ration_coe_list = [];
  66. var dataLength = 0;
  67. if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
  68. dataLength = data.rationCoeList.length
  69. }
  70. for(var i=0;i<=dataLength;i++){;
  71. var newCoe = {
  72. libID :data.rationRepId,
  73. rationID:newRation.ID,
  74. projectID : newRation.projectID
  75. }
  76. if(i==dataLength){
  77. newCoe.coeID=-1;
  78. newCoe.name = '自定义系数';
  79. newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
  80. newCoe.isAdjust=0;
  81. }else {
  82. newCoe.coeID= data.rationCoeList[i];
  83. }
  84. criteria.ration_coe_list.push(newCoe);
  85. }
  86. criteria.updateType = 'ut_create';
  87. return criteria;
  88. };
  89. ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
  90. var updateData = [];
  91. var newobj = {
  92. 'updateType': type,
  93. 'query': query,
  94. }
  95. if(doc){
  96. newobj['doc']=doc;
  97. }
  98. if(callfunction){
  99. newobj['updateFunction']=callfunction;
  100. }
  101. updateData.push(newobj);
  102. return updateData;
  103. };
  104. ration_coe.prototype.adjustCoeClick = function(recode,newval){
  105. var query = {
  106. 'ID':recode.ID,
  107. 'projectID': recode.projectID
  108. };
  109. var doc ={
  110. isAdjust:newval,
  111. };
  112. var updateData = this.getUpdateData('ut_update',query,doc);
  113. project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
  114. };
  115. ration_coe.prototype.deleteByRation = function(ration){
  116. var coe_list = projectObj.project.ration_coe.datas;
  117. var newList =_.filter(coe_list,(coe)=>{
  118. return coe.rationID!=ration.ID;
  119. });
  120. if(newList!=undefined){
  121. projectObj.project.ration_coe.datas = newList;
  122. }
  123. };
  124. return new ration_coe(project);
  125. }
  126. };