ration_coe.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 glj_list = projectObj.project.ration_coe.datas;
  47. var glj_index= _.findIndex(glj_list,(glj)=>{
  48. return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
  49. })
  50. _.forEach(data.doc, function(n, key) {
  51. glj_list[glj_index][key] = n;
  52. });
  53. var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_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.deleteByRation = function(ration){
  90. var coe_list = projectObj.project.ration_coe.datas;
  91. var newList =_.filter(coe_list,(coe)=>{
  92. return coe.rationID!=ration.ID;
  93. });
  94. if(newList!=undefined){
  95. projectObj.project.ration_coe.datas = newList;
  96. }
  97. };
  98. return new ration_coe(project);
  99. }
  100. };