ration_coe.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  43. };
  44. ration_coe.prototype.refreshAfterUpdate=function(data){
  45. var glj_list = projectObj.project.ration_coe.datas;
  46. var glj_index= _.findIndex(glj_list,(glj)=>{
  47. return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
  48. })
  49. _.forEach(data.doc, function(n, key) {
  50. glj_list[glj_index][key] = n;
  51. });
  52. var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
  53. gljOprObj.sheetData=showList;
  54. sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,showList);
  55. };
  56. ration_coe.prototype.refreshAfterDelete=function(data){
  57. var glj_list = projectObj.project.ration_coe.datas;
  58. _.remove(glj_list,data.query);
  59. _.remove(gljOprObj.sheetData,data.query);
  60. sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,gljOprObj.sheetData);
  61. };
  62. ration_coe.prototype.getRationCoedata=function(newRation,data){
  63. var criteria= {};
  64. criteria.ration_coe_list = [];
  65. var dataLength = 0;
  66. if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
  67. dataLength = data.rationCoeList.length
  68. }
  69. for(var i=0;i<=dataLength;i++){;
  70. var newCoe = {
  71. libID :data.rationRepId,
  72. rationID:newRation.ID,
  73. projectID : newRation.projectID
  74. }
  75. if(i==dataLength){
  76. newCoe.coeID=-1;
  77. newCoe.name = '自定义系数';
  78. newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
  79. newCoe.isAdjust=0;
  80. }else {
  81. newCoe.coeID= data.rationCoeList[i];
  82. }
  83. criteria.ration_coe_list.push(newCoe);
  84. }
  85. criteria.updateType = 'ut_create';
  86. return criteria;
  87. };
  88. ration_coe.prototype.deleteByRation = function(ration){
  89. var coe_list = projectObj.project.ration_coe.datas;
  90. var newList =_.filter(coe_list,(coe)=>{
  91. return coe.rationID!=ration.ID;
  92. });
  93. if(newList!=undefined){
  94. projectObj.project.ration_coe.datas = newList;
  95. }
  96. };
  97. return new ration_coe(project);
  98. }
  99. };