home.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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"
  62. , function ($scope, $state, msg,common, config, homeService, $ionicTabsDelegate,$stateParams,$ionicModal,$itemout) {
  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. $scope.type = type;
  86. }
  87. $scope.index = 0;
  88. $scope.$on('$ionicView.beforeEnter', function () {
  89. $ionicTabsDelegate.showBar(false);
  90. });
  91. $scope.$on('$ionicView.leave', function () {
  92. $ionicTabsDelegate.showBar(true);
  93. });
  94. $scope.vm = {
  95. coin:"",
  96. comment:""
  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. $scope.tosupport = false;
  113. number = result.data.data;
  114. //最新支持乘数
  115. })
  116. };
  117. $scope.collectionDream = function(){
  118. homeService.collectionDream(id).then(function(result){
  119. //最新支持乘数
  120. })
  121. }
  122. $scope.showText = function(){
  123. $scope.aboutStyle = {
  124. "white-space" : "normal"
  125. }
  126. $scope.ionDownStyle = {
  127. "display" : "none"
  128. }
  129. }
  130. $scope.placeholder="评论";
  131. $scope.replay = function($event){
  132. // $event.stopPropagation();
  133. $scope.placeholder="回复百川";
  134. $scope.addReplay=true;
  135. $scope.vm.comment='';
  136. }
  137. $scope.comment = function(){
  138. $event.stopPropagation();
  139. $scope.placeholder="评论";
  140. $scope.addReplay=true;
  141. $scope.vm.comment='';
  142. }
  143. $scope.addpict = function () {
  144. common.chooseImage().then(function (img) {
  145. common.uploadFiles(img,1).then(function (result) {
  146. var response = JSON.parse(result.response);
  147. var file = response.data.file;
  148. $scope.imgs.push(file);
  149. }, function (error) {
  150. msg.error('图片上传失败');
  151. });
  152. }, function (error) {
  153. console.log('图片选择失败');
  154. });
  155. };
  156. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  157. scope: $scope,
  158. animation: 'slide-in-up'
  159. }).then(function(modal) {
  160. $scope.rechagemodal = modal;
  161. });
  162. $scope.openRechargeModal = function() {
  163. $scope.rechagemodal.show();
  164. $scope.rvm={
  165. dream:'',
  166. about:'',
  167. money:''
  168. };
  169. };
  170. $scope.closeRechargeModal = function() {
  171. $scope.rechagemodal.hide();
  172. };
  173. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  174. scope: $scope,
  175. animation: 'slide-in-up'
  176. }).then(function(modal) {
  177. $scope.modal = modal;
  178. });
  179. $scope.openModal = function() {
  180. $scope.modal.show();
  181. $scope.ivm={
  182. dream:'',
  183. about:'',
  184. money:''
  185. };
  186. $scope.iimgServer = config.imgServer;
  187. $scope.iimgs = [];
  188. };
  189. $scope.closeModal = function() {
  190. $scope.modal.hide();
  191. };
  192. //当我们用到模型时,清除它!
  193. $scope.$on('$destroy', function() {
  194. $scope.modal.remove();
  195. });
  196. }]);
  197. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  198. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  199. $scope.index = 0;
  200. $scope.index1 = 0;
  201. $scope.vm = {
  202. keywords : ""
  203. }
  204. $scope.ismore = true;
  205. $scope.selectHot = function (index) {
  206. $scope.index = index;
  207. }
  208. $scope.selectHistory = function (index) {
  209. $scope.index1 = index;
  210. }
  211. $scope.showmore = function () {
  212. $scope.ismore = true;
  213. }
  214. $scope.keychange = function () {
  215. $scope.ismore = false;
  216. }
  217. $scope.type = 1;
  218. $scope.changetype = function (type) {
  219. $scope.type = type;
  220. }
  221. $scope.$on('$ionicView.beforeEnter', function () {
  222. $ionicTabsDelegate.showBar(false);
  223. $ionicNavBarDelegate.showBackButton(false);
  224. });
  225. $scope.$on('$ionicView.leave', function () {
  226. $ionicTabsDelegate.showBar(true);
  227. });
  228. $scope.searchContent = function ()
  229. {
  230. homeService.searchContent($scope.vm.keywords).then(function(result){
  231. },function(error){
  232. });
  233. };
  234. }]);
  235. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  236. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  237. $scope.$on('$ionicView.beforeEnter', function () {
  238. });
  239. }]);
  240. })(angular.module('app.controllers'));