home.js 13 KB

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