home.js 14 KB

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