ration_installation.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.getByID = function (ID) {
  33. let me = this;
  34. let ri = _.find(me.datas,{'ID':ID})
  35. return ri;
  36. };
  37. ration_installation.prototype.update = function (updateData,callback) {
  38. let me = this;
  39. $.bootstrapLoading.start();
  40. CommonAjax.post('/installation/updateRationInstallation',updateData,function (data) {
  41. //更新缓存
  42. let ri = _.find(me.datas,{'ID':updateData.ID});
  43. if(ri){
  44. for(let key in updateData){
  45. ri[key] = updateData[key];
  46. }
  47. }
  48. if(callback){
  49. callback();
  50. }
  51. $.bootstrapLoading.end();
  52. },function () {
  53. $.bootstrapLoading.end();
  54. })
  55. };
  56. return new ration_installation(project);
  57. }
  58. };