RecommendContent.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. MWF.xApplication.AppMarketV2.RecommendContent = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. "view": "recommendContent.html"
  5. },
  6. initialize: function(app, container, options){
  7. this.setOptions(options);
  8. this.app = app;
  9. this.container = container;
  10. this.viewPath = this.app.path+this.app.options.style+"/"+this.options.view;
  11. this.load();
  12. },
  13. load: function(){
  14. this.container.loadHtml(this.viewPath, {"bind": {"lp": this.app.lp}, "module": this}, function(){
  15. this.loadRecommend(function(){
  16. this.fireEvent("load");
  17. }.bind(this));
  18. }.bind(this));
  19. },
  20. loadRecommend: function(callback){
  21. if (!this.isLoading){
  22. if (!this.topRecommendContentV){
  23. this.topRecommendContentV = new MWF.xApplication.AppMarketV2.RecommendContent.Recommend(this, {
  24. "onLoad": function(){ if (callback) callback(); }
  25. });
  26. }else{
  27. this.topRecommendContentV.load();
  28. }
  29. }
  30. }
  31. });
  32. MWF.xApplication.AppMarketV2.RecommendContent.Recommend= new Class({
  33. Implements: [Options, Events],
  34. options: {
  35. "type": "recommend"
  36. },
  37. initialize: function(content, options){
  38. this.setOptions(options);
  39. this.content = content;
  40. this.app = this.content.app;
  41. this.actions = this.app.actions;
  42. this.container = this.content.container;
  43. this.page = 1;
  44. this.pageSize = 3;
  45. this.querydata = {"orderBy":"recommend","isAsc":"true"};
  46. this.load();
  47. },
  48. load: function(){
  49. this.loadItemsRes();
  50. },
  51. loadItemsRes: function(){
  52. this.actions.MarketAction.listPaging(this.page, this.pageSize, this.querydata,function(json){
  53. if (json.data && json.data.length){
  54. this.loadItems(json.data);
  55. }else{
  56. this.emptyLoadContent();
  57. }
  58. this.fireEvent("load");
  59. }.bind(this));
  60. },
  61. reload: function(){
  62. if (!this.content.isLoading) {
  63. this.loadItemsRes();
  64. }
  65. },
  66. emptyLoadContent: function(){
  67. this.container.empty();
  68. this.container.removeClass("o2_homepage_area_content_loading").removeClass("icon_loading");
  69. //this.itemContentNode.addClass("o2_homepage_task_area_content_empty").addClass("icon_notask");
  70. this.content.noItemNode = new Element("div.o2_appMarket_content_empty_node", {"text": this.app.lp.noRecommend}).inject(this.container);
  71. var m = (this.content.contentHeight- this.content.noItemNode.getSize().y)/2;
  72. this.content.noItemNode.setStyle("margin-top", ""+m+"px");
  73. this.content.isLoading = false;
  74. },
  75. loadItems: function(data){
  76. data.each(function(d, i){
  77. this.loadItem(d, i);
  78. }.bind(this));
  79. },
  80. loadItem: function(d, i){
  81. var app;
  82. var apppar;
  83. if (i==0){
  84. app = this.content.recommendBiggestPic;
  85. apptext = this.content.recommendBiggestTitle;
  86. apppar = this.content.leftCoverNode;
  87. }
  88. if (i==1){
  89. app = this.content.recommendRightTopPic;
  90. apptext = this.content.recommendRightTopTitle;
  91. apppar = this.content.rightTopCoverNode;
  92. }
  93. if (i==2){
  94. app = this.content.recommendRightBottomPic;
  95. apptext = this.content.recommendRightBottomTitle;
  96. apppar = this.content.rightBottomCoverNode;
  97. }
  98. //获取对应indexPic图片
  99. this.actions.MarketAction.getCoverPic(d.id,function(json){
  100. if (json.data && json.data.value){
  101. app.setStyle("background-image", "url(data:image/png;base64,"+json.data.value+")");
  102. }
  103. }.bind(this));
  104. apptext.set("text",d.name);
  105. var _self = this;
  106. apppar.store("data", d);
  107. apppar.addEvents({
  108. "mouseover": function(){
  109. },
  110. "mouseout": function(){
  111. },
  112. "click": function(e){
  113. var d = this.retrieve("data");
  114. if (d) {
  115. _self.open(e, d);
  116. }
  117. }
  118. })
  119. },
  120. open: function(e, d){
  121. debugger;
  122. var apppar = {};
  123. apppar["appid"] = d.id;
  124. apppar["appname"] = d.name;
  125. layout.openApplication(e, "AppMarketV2.Application", apppar);
  126. },
  127. });