ration_installation.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.getInstallationByRationID = function (rationID) {
  33. let insList = _.filter(this.datas, {'rationID': rationID});
  34. return insList;
  35. };
  36. ration_installation.prototype.getBySectionID = function(sectionID){
  37. var ri_list = this.datas;
  38. return _.filter(ri_list,{'sectionId':sectionID});
  39. };
  40. ration_installation.prototype.deleteByRation = function(ration){
  41. var ri_list = projectObj.project.ration_installation.datas;
  42. _.remove(ri_list,{'rationID':ration.ID});
  43. };
  44. ration_installation.prototype.getByID = function (ID) {
  45. let me = this;
  46. let ri = _.find(me.datas,{'ID':ID})
  47. return ri;
  48. };
  49. ration_installation.prototype.getCalcRIByItemID = function (libID,itemID) {//按费用项ID取费用规则不为空的定额安装增加费
  50. return _.filter(this.datas,function (item) {
  51. if(item.libID == libID && item.feeItemId == itemID && item.ruleId && item.ruleId !=""){
  52. return true;
  53. }
  54. return false;
  55. })
  56. };
  57. ration_installation.prototype.getDataByConditions = function (conditions) {
  58. return _.filter(this.datas,function (item) {
  59. let match = true;
  60. for(let ckey in conditions){
  61. if( Array.isArray(conditions[ckey])){
  62. let isContain = _.includes(conditions[ckey],item[ckey]);
  63. if(!isContain){//不包含
  64. match = false;
  65. break;
  66. }
  67. }else {
  68. if(conditions[ckey]!=item[ckey]){
  69. match = false;
  70. break;
  71. }
  72. }
  73. }
  74. return match;
  75. })
  76. };
  77. ration_installation.prototype.applyRuleByIDs = function(projectID,IDs,ruleId,callback){
  78. let me = this;
  79. $.bootstrapLoading.start();
  80. CommonAjax.post('/installation/applyRuleByIDs',{projectID:projectID,IDs:IDs,ruleId:ruleId},function (data) {
  81. //更新缓存
  82. for(let ID of IDs){
  83. let ri = _.find(me.datas,{'ID':ID});
  84. ri.ruleId = ruleId;
  85. ri.unifiedSetting = 0;
  86. }
  87. if(callback){
  88. callback();
  89. }
  90. $.bootstrapLoading.end();
  91. },function () {
  92. $.bootstrapLoading.end();
  93. })
  94. };
  95. ration_installation.prototype.update = function (updateData,callback) {
  96. let me = this;
  97. $.bootstrapLoading.start();
  98. CommonAjax.post('/installation/updateRationInstallation',updateData,function (data) {
  99. //更新缓存
  100. let ri = _.find(me.datas,{'ID':updateData.ID});
  101. if(ri){
  102. for(let key in updateData){
  103. ri[key] = updateData[key];
  104. }
  105. }
  106. if(callback){
  107. callback();
  108. }
  109. $.bootstrapLoading.end();
  110. },function () {
  111. $.bootstrapLoading.end();
  112. })
  113. };
  114. return new ration_installation(project);
  115. }
  116. };