home.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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", "$interval"
  62. , function ($scope, $state, msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $itemout, $ionicScrollDelegate, $interval) {
  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. //测试动画切换
  78. $scope.sort.first = 'img/demo/head7.jpg';
  79. $scope.sort.second = 'img/demo/head6.jpg';
  80. $scope.sort.third = 'img/demo/head5.jpg';
  81. $scope.sort.slide1 = 'list-grow-animation';
  82. $scope.sort.slide2 = 'slide-in-both-ways';
  83. $scope.sort.slide3 = 'bounce-animation';
  84. $interval.cancel($scope.multi.promise);
  85. return;
  86. $scope.tosupport = true;
  87. $scope.vm.coin = 0;
  88. $scope.index = 0;
  89. }
  90. $scope.cancelsupport = function () {
  91. $scope.tosupport = false;
  92. }
  93. $scope.changetype = function (type) {
  94. $ionicScrollDelegate.scrollTop(true);
  95. $scope.type = type;
  96. }
  97. $scope.index = 0;
  98. $scope.$on('$ionicView.beforeEnter', function () {
  99. $scope.calcmultiplier();
  100. $ionicTabsDelegate.showBar(false);
  101. });
  102. $scope.$on('$ionicView.leave', function () {
  103. $ionicTabsDelegate.showBar(true);
  104. $interval.cancel($scope.multi.promise);
  105. });
  106. $scope.vm = {
  107. coin:"",
  108. comment:""
  109. }
  110. $scope.changeindex = function (index) {
  111. $scope.index = index;
  112. $scope.vm.coin = index*5;
  113. }
  114. //实时排行
  115. $scope.sort = {
  116. first: 'img/demo/head5.jpg',
  117. second: 'img/demo/head6.jpg',
  118. third: 'img/demo/head7.jpg',
  119. slide: ''
  120. }
  121. $scope.multi = {
  122. a: 0.5,
  123. b:new Date('2017-03-03'),
  124. c: 20,
  125. result: 0,
  126. promise:null,
  127. }
  128. $scope.vidEnded = function () {
  129. alert('播放完毕');
  130. }
  131. //实时计算支持乘数
  132. $scope.calcmultiplier = function () {
  133. $scope.multi.promise=$interval(function () {
  134. var date = new Date();
  135. var inter = date.getTime() - $scope.multi.b.getTime();
  136. var minutes = Math.floor(inter / (60 * 1000));
  137. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  138. if (number<=1) {
  139. number = 1;
  140. }
  141. $scope.multi.result = number;
  142. },1000);
  143. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  144. }
  145. $scope.supportDream = function (data) {
  146. if(!$scope.vm.coin){
  147. msg.error("请选择梦想币数量!");
  148. return ;
  149. }
  150. var data = {
  151. id:id,
  152. coin:$scope.vm.coin
  153. };
  154. homeService.supportDream(data).then(function(result){
  155. $scope.tosupport = false;
  156. number = result.data.data;
  157. //最新支持乘数
  158. })
  159. };
  160. $scope.collectionDream = function(){
  161. homeService.collectionDream(id).then(function(result){
  162. //最新支持乘数
  163. })
  164. }
  165. $scope.showText = function(){
  166. $scope.aboutStyle = {
  167. "white-space" : "normal"
  168. }
  169. $scope.ionDownStyle = {
  170. "display" : "none"
  171. }
  172. }
  173. $scope.input = {
  174. placeholder: '评论',
  175. focus:false
  176. }
  177. $scope.replay = function ($event, name) {
  178. $scope.input.focus = true;
  179. //$event.stopPropagation();
  180. $scope.input.placeholder = "回复" + name;
  181. $scope.vm.comment='';
  182. }
  183. $scope.comment = function(){
  184. // $event.stopPropagation();
  185. $scope.input.placeholder = "评论";
  186. $scope.input.focus = true;
  187. $scope.vm.comment='';
  188. }
  189. $scope.addpict = function () {
  190. $scope.imgs=new Array();
  191. common.chooseImage().then(function (img) {
  192. common.uploadFiles(img,1).then(function (result) {
  193. var response = JSON.parse(result.response);
  194. var file = response.data.file;
  195. $scope.imgs.push(file);
  196. }, function (error) {
  197. msg.error('图片上传失败');
  198. });
  199. }, function (error) {
  200. console.log('图片选择失败');
  201. });
  202. };
  203. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  204. scope: $scope,
  205. animation: 'slide-in-up'
  206. }).then(function(modal) {
  207. $scope.rechagemodal = modal;
  208. });
  209. $scope.openRechargeModal = function() {
  210. $scope.rechagemodal.show();
  211. $scope.rvm={
  212. dream:'',
  213. about:'',
  214. money:''
  215. };
  216. };
  217. $scope.closeRechargeModal = function() {
  218. $scope.rechagemodal.hide();
  219. };
  220. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  221. scope: $scope,
  222. animation: 'slide-in-up'
  223. }).then(function(modal) {
  224. $scope.modal = modal;
  225. });
  226. $scope.openModal = function() {
  227. $scope.modal.show();
  228. $scope.ivm={
  229. dream:'',
  230. about:'',
  231. money:''
  232. };
  233. $scope.iimgServer = config.imgServer;
  234. $scope.iimgs = [];
  235. };
  236. $scope.closeModal = function() {
  237. $scope.modal.hide();
  238. };
  239. //当我们用到模型时,清除它!
  240. $scope.$on('$destroy', function() {
  241. $scope.modal.remove();
  242. });
  243. }]);
  244. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  245. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  246. $scope.index = 0;
  247. $scope.index1 = 0;
  248. $scope.vm = {
  249. keywords : ""
  250. }
  251. $scope.ismore = true;
  252. $scope.selectHot = function (index) {
  253. $scope.index = index;
  254. }
  255. $scope.selectHistory = function (index) {
  256. $scope.index1 = index;
  257. }
  258. $scope.showmore = function () {
  259. $scope.ismore = true;
  260. }
  261. $scope.keychange = function () {
  262. $scope.ismore = false;
  263. }
  264. $scope.type = 1;
  265. $scope.changetype = function (type) {
  266. $scope.type = type;
  267. }
  268. $scope.$on('$ionicView.beforeEnter', function () {
  269. $ionicTabsDelegate.showBar(false);
  270. $ionicNavBarDelegate.showBackButton(false);
  271. });
  272. $scope.$on('$ionicView.leave', function () {
  273. $ionicTabsDelegate.showBar(true);
  274. });
  275. $scope.searchContent = function ()
  276. {
  277. homeService.searchContent($scope.vm.keywords).then(function(result){
  278. },function(error){
  279. });
  280. };
  281. }]);
  282. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  283. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  284. $scope.$on('$ionicView.beforeEnter', function () {
  285. });
  286. }]);
  287. })(angular.module('app.controllers'));