home.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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: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, $timeout, $ionicScrollDelegate, $interval) {
  63. var id = $stateParams.id;
  64. id=5;
  65. $scope.load = function (id) {
  66. msg.loading();
  67. homeService.dreamDetail(id).then(function (result) {
  68. msg.hide();
  69. console.log(result);
  70. $scope.dream = result.data.data
  71. console.log();
  72. var date = new Date();
  73. var inter = (date.getTime() - new Date($scope.dream.created_at).getTime())/1000
  74. leftTimer($scope.dream.time-inter);
  75. $scope.multi = {
  76. a: $scope.dream.a,
  77. b: new Date($scope.dream.created_at),
  78. c: $scope.dream.c,
  79. result: 1,
  80. promise:null,
  81. }
  82. $scope.calcmultiplier();
  83. }, function (error) {
  84. msg.hide();
  85. });
  86. }
  87. $scope.type = 1;//tab切换
  88. $scope.tosupport = false;
  89. $scope.support = function ($event) {
  90. $event.stopPropagation();
  91. $scope.tosupport = true;
  92. $scope.vm.coin = 0;
  93. $scope.index = 0;
  94. }
  95. $scope.cancelSupport = function () {
  96. $scope.tosupport = false;
  97. }
  98. $scope.changeType = function (type) {
  99. $ionicScrollDelegate.scrollTop(true);
  100. $scope.type = type;
  101. }
  102. $scope.index = 0;
  103. $scope.$on('$ionicView.beforeEnter', function () {
  104. $scope.load(id);
  105. $ionicTabsDelegate.showBar(false);
  106. });
  107. $scope.$on('$ionicView.leave', function () {
  108. $ionicTabsDelegate.showBar(true);
  109. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  110. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  111. });
  112. $scope.vm = {
  113. coin:"",
  114. title:""
  115. }
  116. $scope.timer = '';
  117. var leftTimer = function (countDown) {
  118. var day=parseInt(countDown/(24*60*60));
  119. var h=parseInt(countDown/(60*60)%24);
  120. var m=parseInt(countDown/60%60);
  121. var s=parseInt(countDown%60);
  122. $scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  123. if(day>0) $scope.timer = day+'天'+ $scope.timer;
  124. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  125. $scope.leftTimer = $interval(function () {
  126. if (countDown >= 1) leftTimer(countDown - 1);
  127. },1000);
  128. if(countDown<=0){
  129. $scope.timer='结束';
  130. }
  131. }
  132. $scope.changeIndex = function (index) {
  133. $scope.index = index;
  134. $scope.vm.coin = index*5;
  135. }
  136. //实时排行
  137. $scope.sort = {
  138. first: 'img/demo/head5.jpg',
  139. second: 'img/demo/head6.jpg',
  140. third: 'img/demo/head7.jpg',
  141. slide: ''
  142. }
  143. $scope.vidEnded = function () {
  144. alert('播放完毕');
  145. }
  146. //实时计算支持乘数
  147. $scope.calcmultiplier = function () {
  148. $scope.multi.promise=$interval(function () {
  149. var date = new Date();
  150. var inter = date.getTime() - $scope.multi.b.getTime();
  151. var minutes = Math.floor(inter / (60 * 1000));
  152. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  153. if (number<=1) {
  154. number = 1;
  155. }
  156. $scope.multi.result = Math.round(number * 100) / 100;
  157. },1000);
  158. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  159. }
  160. $scope.supportDream = function (data) {
  161. if(!$scope.vm.coin){
  162. msg.error("请选择梦想币数量!");
  163. return ;
  164. }
  165. var data = {
  166. id:id,
  167. coin:$scope.vm.coin
  168. };
  169. homeService.supportDream(data).then(function(result){
  170. $scope.tosupport = false;
  171. $scope.load(id);
  172. //
  173. //测试动画切换
  174. $scope.sort.first = 'img/demo/head7.jpg';
  175. $scope.sort.second = 'img/demo/head6.jpg';
  176. $scope.sort.third = 'img/demo/head5.jpg';
  177. $scope.sort.slide1 = 'list-grow-animation';
  178. $scope.sort.slide2 = 'slide-in-both-ways';
  179. $scope.sort.slide3 = 'bounce-animation';
  180. $interval.cancel($scope.multi.promise);
  181. })
  182. };
  183. $scope.collectionDream = function(is_collection){
  184. homeService.collectionDream(id,is_collection).then(function(result){
  185. $scope.dream.is_collection=result.data.data;
  186. })
  187. }
  188. $scope.add = function(is_collection){
  189. var data = {
  190. id:id,
  191. title:$scope.vm.title,
  192. pics:$scope.imgs,
  193. };
  194. homeService.add_interaction(data).then(function(){
  195. $scope.load(id);
  196. $scope.closeModal();
  197. })
  198. }
  199. $scope.showText = function(){
  200. $scope.aboutStyle = {
  201. "white-space" : "normal"
  202. }
  203. $scope.ionDownStyle = {
  204. "display" : "none"
  205. }
  206. }
  207. $scope.input = {
  208. placeholder: '评论',
  209. focus:false
  210. }
  211. $scope.replay = function ($event, name) {
  212. $scope.input.focus = true;
  213. //$event.stopPropagation();
  214. $scope.input.placeholder = "回复" + name;
  215. $scope.vm.title='';
  216. }
  217. $scope.comment = function(){
  218. // $event.stopPropagation();
  219. $scope.input.placeholder = "评论";
  220. $scope.input.focus = true;
  221. $scope.vm.title='';
  222. }
  223. $scope.imgs = new Array();
  224. $scope.addpict = function () {
  225. common.chooseImage().then(function (img) {
  226. common.uploadFiles(img,1).then(function (result) {
  227. var response = JSON.parse(result.response);
  228. var file = response.data.file;
  229. $scope.imgs.push(config.imgServer+file);
  230. console.log(JSON.stringify(config.imgServer+file));
  231. }, function (error) {
  232. msg.error('图片上传失败');
  233. });
  234. }, function (error) {
  235. console.log('图片选择失败');
  236. });
  237. };
  238. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  239. scope: $scope,
  240. animation: 'slide-in-up'
  241. }).then(function(modal) {
  242. $scope.rechagemodal = modal;
  243. });
  244. $scope.openRechargeModal = function() {
  245. $scope.rechagemodal.show();
  246. $scope.vm.money = '';
  247. };
  248. $scope.closeRechargeModal = function() {
  249. $scope.rechagemodal.hide();
  250. };
  251. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  252. scope: $scope,
  253. animation: 'slide-in-up'
  254. }).then(function(modal) {
  255. $scope.modal = modal;
  256. });
  257. $scope.openModal = function() {
  258. $scope.modal.show();
  259. $scope.vm.title = '';
  260. $scope.imgServer = config.imgServer;
  261. $scope.imgs = [];
  262. };
  263. $scope.closeModal = function() {
  264. $scope.modal.hide();
  265. };
  266. //当我们用到模型时,清除它!
  267. $scope.$on('$destroy', function() {
  268. $scope.modal.remove();
  269. });
  270. }]);
  271. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  272. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  273. $scope.index = 0;
  274. $scope.index1 = 0;
  275. $scope.vm = {
  276. keywords : ""
  277. }
  278. $scope.ismore = true;
  279. $scope.selectHot = function (index) {
  280. $scope.index = index;
  281. }
  282. $scope.selectHistory = function (index) {
  283. $scope.index1 = index;
  284. }
  285. $scope.showMore = function () {
  286. $scope.ismore = true;
  287. }
  288. $scope.keyChange = function () {
  289. $scope.ismore = false;
  290. }
  291. $scope.type = 1;
  292. $scope.changeType = function (type) {
  293. $scope.type = type;
  294. }
  295. $scope.$on('$ionicView.beforeEnter', function () {
  296. $ionicTabsDelegate.showBar(false);
  297. $ionicNavBarDelegate.showBackButton(false);
  298. });
  299. $scope.$on('$ionicView.leave', function () {
  300. $ionicTabsDelegate.showBar(true);
  301. });
  302. $scope.searchContent = function ()
  303. {
  304. homeService.searchContent($scope.vm.keywords).then(function(result){
  305. },function(error){
  306. });
  307. };
  308. }]);
  309. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  310. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  311. $scope.$on('$ionicView.beforeEnter', function () {
  312. });
  313. }]);
  314. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  315. , function ($scope, $state, myService, msg) {
  316. $scope.$on('$ionicView.beforeEnter', function () {
  317. myService.myDream().then(function(result){
  318. console.log(result.data.data);
  319. $scope.dreams = result.data.data;
  320. });
  321. });
  322. $scope.toDetail = function (id) {
  323. $state.go('app.home_dreamdetail',{id:id});
  324. };
  325. }]);
  326. })(angular.module('app.controllers'));