ration_coe.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. gljOprObj.showCoeData(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,function(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. gljOprObj.showCoeData(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. gljOprObj.showCoeData(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. newCoe.coes = this.getCustomerCoeData();
  82. }else {
  83. newCoe.coeID= data.rationCoeList[i];
  84. }
  85. criteria.ration_coe_list.push(newCoe);
  86. }
  87. criteria.updateType = 'ut_create';
  88. return criteria;
  89. };
  90. ration_coe.prototype.getCustomerCoeData = function () {
  91. var coeList = [];
  92. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'定额'});
  93. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'人工'});
  94. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'材料'});
  95. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'机械'});
  96. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
  97. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
  98. return coeList;
  99. };
  100. ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
  101. var updateData = [];
  102. var newobj = {
  103. 'updateType': type,
  104. 'query': query,
  105. }
  106. if(doc){
  107. newobj['doc']=doc;
  108. }
  109. if(callfunction){
  110. newobj['updateFunction']=callfunction;
  111. }
  112. updateData.push(newobj);
  113. return updateData;
  114. };
  115. ration_coe.prototype.adjustCoeClick = function(recode,newval){
  116. var query = {
  117. 'ID':recode.ID,
  118. 'projectID': recode.projectID,
  119. 'rationID':recode.rationID
  120. };
  121. var doc ={
  122. isAdjust:newval,
  123. };
  124. var updateData = this.getUpdateData('ut_update',query,doc,'adjustUpdate');
  125. project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
  126. };
  127. ration_coe.prototype.updateCustomerCoe = function (data) {
  128. var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');
  129. project.pushNow('updateCustomerCoe',[this.getSourceType()],updateData);
  130. };
  131. ration_coe.prototype.deleteByRation = function(ration){
  132. var coe_list = projectObj.project.ration_coe.datas;
  133. var newList =_.filter(coe_list,(coe)=>{
  134. return coe.rationID!=ration.ID;
  135. });
  136. if(newList!=undefined){
  137. projectObj.project.ration_coe.datas = newList;
  138. }
  139. };
  140. return new ration_coe(project);
  141. }
  142. };