home.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. msg.error(error.data.message);
  55. });
  56. }
  57. $scope.data = {};
  58. $scope.load(true);
  59. //$scope.$on('$ionicView.enter', function () {
  60. //});
  61. }]);
  62. app.controller('dreamDetailCtrl', ["$scope", "$state", "msg","common","config", "homeService", "$ionicTabsDelegate","$stateParams","$ionicModal","$timeout"
  63. , function ($scope, $state, msg,common, config, homeService, $ionicTabsDelegate,$stateParams,$ionicModal,$itemout) {
  64. var id = $stateParams.id;
  65. id=6;
  66. $scope.load = function (id) {
  67. homeService.dreamDetail(id).then(function (result) {
  68. console.log(result);
  69. }, function (error) {
  70. msg.error(error.data.message);
  71. });
  72. }
  73. $scope.load(6);
  74. $scope.type = 1;//tab切换
  75. $scope.tosupport = false;
  76. $scope.support = function ($event) {
  77. $event.stopPropagation();
  78. $scope.tosupport = true;
  79. $scope.vm.coin = 0;
  80. $scope.index = 0;
  81. }
  82. $scope.cancelsupport = function () {
  83. $scope.tosupport = false;
  84. }
  85. $scope.changetype = function (type) {
  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. }
  98. $scope.changeindex = function (index) {
  99. $scope.index = index;
  100. $scope.vm.coin = index*5;
  101. }
  102. $scope.supportDream = function(data){
  103. if(!$scope.vm.coin){
  104. msg.error("请选择梦想币数量!");
  105. return ;
  106. }
  107. var data = {
  108. id:id,
  109. coin:$scope.vm.coin
  110. };
  111. homeService.supportDream(data).then(function(result){
  112. },function(erro){
  113. })
  114. };
  115. $scope.showText = function(){
  116. $scope.aboutStyle = {
  117. "white-space" : "normal"
  118. }
  119. $scope.ionDownStyle = {
  120. "display" : "none"
  121. }
  122. }
  123. $scope.placeholder="评论";
  124. $scope.replay = function(id,cid,username){
  125. $event.stopPropagation();
  126. $scope.placeholder="回复百川";
  127. $scope.addReplay=true;
  128. $scope.vm.comment='';
  129. }
  130. $scope.comment = function(){
  131. $event.stopPropagation();
  132. $scope.placeholder="评论";
  133. $scope.addReplay=true;
  134. $scope.vm.comment='';
  135. }
  136. $scope.addpict = function () {
  137. common.chooseImage().then(function (img) {
  138. common.uploadFiles(img,1).then(function (result) {
  139. var response = JSON.parse(result.response);
  140. var file = response.data.file;
  141. $scope.imgs.push(file);
  142. }, function (error) {
  143. msg.error('图片上传失败');
  144. });
  145. }, function (error) {
  146. console.log('图片选择失败');
  147. });
  148. };
  149. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  150. scope: $scope,
  151. animation: 'slide-in-up'
  152. }).then(function(modal) {
  153. $scope.rechagemodal = modal;
  154. });
  155. $scope.openRechargeModal = function() {
  156. $scope.rechagemodal.show();
  157. $scope.rvm={
  158. dream:'',
  159. about:'',
  160. money:''
  161. };
  162. };
  163. $scope.closeRechargeModal = function() {
  164. $scope.rechagemodal.hide();
  165. };
  166. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  167. scope: $scope,
  168. animation: 'slide-in-up'
  169. }).then(function(modal) {
  170. $scope.modal = modal;
  171. });
  172. $scope.openModal = function() {
  173. $scope.modal.show();
  174. $scope.ivm={
  175. dream:'',
  176. about:'',
  177. money:''
  178. };
  179. $scope.iimgServer = config.imgServer;
  180. $scope.iimgs = [];
  181. };
  182. $scope.closeModal = function() {
  183. $scope.modal.hide();
  184. };
  185. //当我们用到模型时,清除它!
  186. $scope.$on('$destroy', function() {
  187. $scope.modal.remove();
  188. });
  189. }]);
  190. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  191. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  192. $scope.index = 0;
  193. $scope.index1 = 0;
  194. $scope.vm = {
  195. keywords : ""
  196. }
  197. $scope.ismore = true;
  198. $scope.selectHot = function (index) {
  199. $scope.index = index;
  200. }
  201. $scope.selectHistory = function (index) {
  202. $scope.index1 = index;
  203. }
  204. $scope.showmore = function () {
  205. $scope.ismore = true;
  206. }
  207. $scope.keychange = function () {
  208. $scope.ismore = false;
  209. }
  210. $scope.type = 1;
  211. $scope.changetype = function (type) {
  212. $scope.type = type;
  213. }
  214. $scope.$on('$ionicView.beforeEnter', function () {
  215. $ionicTabsDelegate.showBar(false);
  216. $ionicNavBarDelegate.showBackButton(false);
  217. });
  218. $scope.$on('$ionicView.leave', function () {
  219. $ionicTabsDelegate.showBar(true);
  220. });
  221. $scope.searchContent = function ()
  222. {
  223. homeService.searchContent($scope.vm.keywords).then(function(result){
  224. },function(error){
  225. });
  226. };
  227. }]);
  228. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  229. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  230. $scope.$on('$ionicView.beforeEnter', function () {
  231. });
  232. }]);
  233. })(angular.module('app.controllers'));