home.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. (function (app) {
  2. app.controller('homeCtrl', ["$scope", "$http", 'config', "$state", "msg", "$ionicPopover", "homeService"
  3. , function ($scope, $http, config, $state, msg, $ionicPopover, homeService) {
  4. $scope.type = 'hot';//tab切换
  5. $ionicPopover.fromTemplateUrl('my-popover.html', {
  6. scope: $scope
  7. }).then(function (popover) {
  8. $scope.popover = popover;
  9. });
  10. $scope.openPopover = function ($event) {
  11. $scope.popover.show($event);
  12. };
  13. $scope.closePopover = function () {
  14. $scope.popover.hide();
  15. };
  16. $scope.changetype = function (type) {
  17. $scope.type = type;
  18. $scope.load(true);
  19. }
  20. $scope.toDetail = function (id) {
  21. $state.go('app.home_dreamdetail',id);
  22. };
  23. $scope.filter = {
  24. hasMore: false,
  25. pageIndex: 1,
  26. pageSize: 20,
  27. }
  28. $scope.index = {
  29. banner: [],
  30. users: [],
  31. dreams:[]
  32. };
  33. $scope.load = function (init) {
  34. if (init) {
  35. $scope.filter.pageIndex = 1;
  36. $scope.index.dreams = [];
  37. }
  38. msg.loading();
  39. homeService.index($scope.type, $scope.filter.pageIndex).then(function (result) {
  40. msg.hide();
  41. $scope.index.banners = result.data.data.banners;
  42. $scope.index.users = result.data.data.users;
  43. $scope.filter.pageIndex++;
  44. var more = (result.data.data.dreams.data.length >= $scope.filter.pageSize);
  45. $scope.filter.hasMore = more;
  46. $scope.index.dreams = $scope.index.dreams.concat(result.data.data.dreams.data);
  47. if (init) {
  48. $scope.$broadcast('scroll.refreshComplete');
  49. } else {
  50. $scope.$broadcast('scroll.infiniteScrollComplete');
  51. }
  52. }, function (error) {
  53. msg.hide();
  54. });
  55. }
  56. $scope.data = {};
  57. $scope.load(true);
  58. //$scope.$on('$ionicView.enter', function () {
  59. //});
  60. }]);
  61. app.controller('dreamDetailCtrl', ["$scope", "$state", "msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout","$ionicScrollDelegate"
  62. , function ($scope, $state, msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $itemout, $ionicScrollDelegate) {
  63. var id = $stateParams.id;
  64. id=6;
  65. $scope.load = function (id) {
  66. homeService.dreamDetail(id).then(function (result) {
  67. console.log(result);
  68. }, function (error) {
  69. msg.error(error.data.message);
  70. });
  71. }
  72. $scope.load(6);
  73. $scope.type = 1;//tab切换
  74. $scope.tosupport = false;
  75. $scope.support = function ($event) {
  76. $event.stopPropagation();
  77. $scope.tosupport = true;
  78. $scope.vm.coin = 0;
  79. $scope.index = 0;
  80. }
  81. $scope.cancelsupport = function () {
  82. $scope.tosupport = false;
  83. }
  84. $scope.changetype = function (type) {
  85. $ionicScrollDelegate.scrollTop(true);
  86. $scope.type = type;
  87. }
  88. $scope.index = 0;
  89. $scope.$on('$ionicView.beforeEnter', function () {
  90. $ionicTabsDelegate.showBar(false);
  91. });
  92. $scope.$on('$ionicView.leave', function () {
  93. $ionicTabsDelegate.showBar(true);
  94. });
  95. $scope.vm = {
  96. coin:"",
  97. comment:""
  98. }
  99. $scope.changeindex = function (index) {
  100. $scope.index = index;
  101. $scope.vm.coin = index*5;
  102. }
  103. $scope.supportDream = function(data){
  104. if(!$scope.vm.coin){
  105. msg.error("请选择梦想币数量!");
  106. return ;
  107. }
  108. var data = {
  109. id:id,
  110. coin:$scope.vm.coin
  111. };
  112. homeService.supportDream(data).then(function(result){
  113. $scope.tosupport = false;
  114. number = result.data.data;
  115. //最新支持乘数
  116. })
  117. };
  118. $scope.collectionDream = function(){
  119. homeService.collectionDream(id).then(function(result){
  120. //最新支持乘数
  121. })
  122. }
  123. $scope.showText = function(){
  124. $scope.aboutStyle = {
  125. "white-space" : "normal"
  126. }
  127. $scope.ionDownStyle = {
  128. "display" : "none"
  129. }
  130. }
  131. $scope.placeholder="评论";
  132. $scope.replay = function($event,name){
  133. // $event.stopPropagation();
  134. $scope.placeholder = "回复" + name;
  135. $scope.addReplay=true;
  136. $scope.vm.comment='';
  137. }
  138. $scope.comment = function(){
  139. // $event.stopPropagation();
  140. $scope.placeholder="评论";
  141. $scope.addReplay=true;
  142. $scope.vm.comment='';
  143. }
  144. $scope.addpict = function () {
  145. $scope.imgs=new Array();
  146. common.chooseImage().then(function (img) {
  147. common.uploadFiles(img,1).then(function (result) {
  148. var response = JSON.parse(result.response);
  149. var file = response.data.file;
  150. $scope.imgs.push(file);
  151. }, function (error) {
  152. msg.error('图片上传失败');
  153. });
  154. }, function (error) {
  155. console.log('图片选择失败');
  156. });
  157. };
  158. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  159. scope: $scope,
  160. animation: 'slide-in-up'
  161. }).then(function(modal) {
  162. $scope.rechagemodal = modal;
  163. });
  164. $scope.openRechargeModal = function() {
  165. $scope.rechagemodal.show();
  166. $scope.rvm={
  167. dream:'',
  168. about:'',
  169. money:''
  170. };
  171. };
  172. $scope.closeRechargeModal = function() {
  173. $scope.rechagemodal.hide();
  174. };
  175. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  176. scope: $scope,
  177. animation: 'slide-in-up'
  178. }).then(function(modal) {
  179. $scope.modal = modal;
  180. });
  181. $scope.openModal = function() {
  182. $scope.modal.show();
  183. $scope.ivm={
  184. dream:'',
  185. about:'',
  186. money:''
  187. };
  188. $scope.iimgServer = config.imgServer;
  189. $scope.iimgs = [];
  190. };
  191. $scope.closeModal = function() {
  192. $scope.modal.hide();
  193. };
  194. //当我们用到模型时,清除它!
  195. $scope.$on('$destroy', function() {
  196. $scope.modal.remove();
  197. });
  198. }]);
  199. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  200. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  201. $scope.index = 0;
  202. $scope.index1 = 0;
  203. $scope.vm = {
  204. keywords : ""
  205. }
  206. $scope.ismore = true;
  207. $scope.selectHot = function (index) {
  208. $scope.index = index;
  209. }
  210. $scope.selectHistory = function (index) {
  211. $scope.index1 = index;
  212. }
  213. $scope.showmore = function () {
  214. $scope.ismore = true;
  215. }
  216. $scope.keychange = function () {
  217. $scope.ismore = false;
  218. }
  219. $scope.type = 1;
  220. $scope.changetype = function (type) {
  221. $scope.type = type;
  222. }
  223. $scope.$on('$ionicView.beforeEnter', function () {
  224. $ionicTabsDelegate.showBar(false);
  225. $ionicNavBarDelegate.showBackButton(false);
  226. });
  227. $scope.$on('$ionicView.leave', function () {
  228. $ionicTabsDelegate.showBar(true);
  229. });
  230. $scope.searchContent = function ()
  231. {
  232. homeService.searchContent($scope.vm.keywords).then(function(result){
  233. },function(error){
  234. });
  235. };
  236. }]);
  237. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  238. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  239. $scope.$on('$ionicView.beforeEnter', function () {
  240. });
  241. }]);
  242. })(angular.module('app.controllers'));