ration_installation.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * Created by zhang on 2018/2/24.
  3. */
  4. let ration_installation = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration_installation = function (proj) {
  10. // this.project = proj;
  11. this.datas = [];
  12. var sourceType = ModuleNames.ration_installation;
  13. this.getSourceType = function () {
  14. return sourceType;
  15. }
  16. proj.registerModule(ModuleNames.ration_installation, this);
  17. };
  18. // prototype用于定义public方法
  19. ration_installation.prototype.loadData = function (datas) {
  20. this.datas = datas;
  21. };
  22. ration_installation.prototype.addDatasToList = function (datas) {
  23. let me = this;
  24. if(datas&&datas.length>0){
  25. if (me.datas && Array.isArray(me.datas)) {
  26. me.datas = me.datas.concat(datas);
  27. } else {
  28. me.datas = datas;
  29. }
  30. }
  31. };
  32. ration_installation.prototype.getBySectionID = function(sectionID){
  33. var ri_list = this.datas;
  34. return _.filter(ri_list,{'sectionId':sectionID});
  35. };
  36. ration_installation.prototype.deleteByRation = function(ration){
  37. var ri_list = projectObj.project.ration_installation.datas;
  38. _.remove(ri_list,{'rationID':ration.ID});
  39. };
  40. ration_installation.prototype.getByID = function (ID) {
  41. let me = this;
  42. let ri = _.find(me.datas,{'ID':ID})
  43. return ri;
  44. };
  45. ration_installation.prototype.getCalcRIByItemID = function (libID,itemID) {//按费用项ID取费用规则不为空的定额安装增加费
  46. return _.filter(this.datas,function (item) {
  47. if(item.libID == libID && item.feeItemId == itemID && item.ruleId && item.ruleId !=""){
  48. return true;
  49. }
  50. return false;
  51. })
  52. };
  53. ration_installation.prototype.getDataByConditions = function (conditions) {
  54. return _.filter(this.datas,function (item) {
  55. let match = true;
  56. for(let ckey in conditions){
  57. if( Array.isArray(conditions[ckey])){
  58. let isContain = _.includes(conditions[ckey],item[ckey]);
  59. if(!isContain){//不包含
  60. match = false;
  61. break;
  62. }
  63. }else {
  64. if(conditions[ckey]!=item[ckey]){
  65. match = false;
  66. break;
  67. }
  68. }
  69. }
  70. return match;
  71. })
  72. };
  73. ration_installation.prototype.applyRuleByIDs = function(projectID,IDs,ruleId,callback){
  74. let me = this;
  75. $.bootstrapLoading.start();
  76. CommonAjax.post('/installation/applyRuleByIDs',{projectID:projectID,IDs:IDs,ruleId:ruleId},function (data) {
  77. //更新缓存
  78. for(let ID of IDs){
  79. let ri = _.find(me.datas,{'ID':ID});
  80. ri.ruleId = ruleId;
  81. ri.unifiedSetting = 0;
  82. }
  83. if(callback){
  84. callback();
  85. }
  86. $.bootstrapLoading.end();
  87. },function () {
  88. $.bootstrapLoading.end();
  89. })
  90. };
  91. ration_installation.prototype.update = function (updateData,callback) {
  92. let me = this;
  93. $.bootstrapLoading.start();
  94. CommonAjax.post('/installation/updateRationInstallation',updateData,function (data) {
  95. //更新缓存
  96. let ri = _.find(me.datas,{'ID':updateData.ID});
  97. if(ri){
  98. for(let key in updateData){
  99. ri[key] = updateData[key];
  100. }
  101. }
  102. if(callback){
  103. callback();
  104. }
  105. $.bootstrapLoading.end();
  106. },function () {
  107. $.bootstrapLoading.end();
  108. })
  109. };
  110. return new ration_installation(project);
  111. }
  112. };