home.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. (function (app) {
  2. app.controller('homeCtrl', ["$scope", "$ionicTabsDelegate", "$http", 'config', "$state", "msg", "$ionicPopover", "homeService", "$ionicPopup", "$timeout", "$ionicSideMenuDelegate"
  3. , function ($scope, $ionicTabsDelegate, $http, config, $state, msg, $ionicPopover, homeService, $ionicPopup, $timeout, $ionicSideMenuDelegate) {
  4. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  5. $ionicTabsDelegate.showBar(true);
  6. });
  7. $scope.type = 'hot';//tab切换
  8. $scope.chosedIndex = 0;
  9. $scope.clickAvatar = function(index){
  10. $scope.chosedIndex = index;
  11. };
  12. $ionicPopover.fromTemplateUrl('my-popover.html', {
  13. scope: $scope
  14. }).then(function (popover) {
  15. $scope.popover = popover;
  16. });
  17. $scope.toggleLeftSideMenu = function () {
  18. $ionicSideMenuDelegate.toggleLeft();
  19. };
  20. $scope.doFilter = function () {
  21. $ionicSideMenuDelegate.toggleRight();
  22. };
  23. $scope.openPopover = function ($event) {
  24. $scope.popover.show($event);
  25. };
  26. $scope.closePopover = function () {
  27. $scope.popover.hide();
  28. };
  29. $scope.changetype = function (type) {
  30. $scope.type = type;
  31. $scope.load(true);
  32. };
  33. $scope.toDetail = function (id) {
  34. $state.go('app.home_dreamdetail',{id:id});
  35. };
  36. $scope.toUserDetail = function (id,dream_id) {
  37. homeService.toUserDetail(id,dream_id).then(function(result){
  38. $scope.items = result.data.data;
  39. $state.go('app.home_userDetail',{id:id,dream_id:dream_id,items:$scope.items});
  40. },function(error){
  41. //msg.error(msg.data.error)
  42. })
  43. };
  44. $scope.changeFilter = function (input) {
  45. switch (input) {
  46. case '1':
  47. if ($scope.filter.sex == 1) {
  48. $scope.filter.sex = 0;
  49. } else {
  50. $scope.filter.sex = 1;
  51. }
  52. break;
  53. case '2':
  54. if ($scope.filter.sex == 2) {
  55. $scope.filter.sex = 0;
  56. } else {
  57. $scope.filter.sex = 2;
  58. }
  59. break;
  60. case '18-21':
  61. if ($scope.filter.age == 1) {
  62. $scope.filter.age = 0;
  63. } else {
  64. $scope.filter.age = 1;
  65. }
  66. break;
  67. case '22-25':
  68. if ($scope.filter.age == 2) {
  69. $scope.filter.age = 0;
  70. } else {
  71. $scope.filter.age = 2;
  72. }
  73. break;
  74. case '26-29':
  75. if ($scope.filter.age == 3) {
  76. $scope.filter.age = 0;
  77. } else {
  78. $scope.filter.age = 3;
  79. }
  80. break;
  81. case '30-33':
  82. if ($scope.filter.age == 4) {
  83. $scope.filter.age = 0;
  84. } else {
  85. $scope.filter.age = 4;
  86. }
  87. break;
  88. case '34-37':
  89. if ($scope.filter.age == 5) {
  90. $scope.filter.age = 0;
  91. } else {
  92. $scope.filter.age = 5;
  93. }
  94. break;
  95. case '>38':
  96. if ($scope.filter.age == 6) {
  97. $scope.filter.age = 0;
  98. } else {
  99. $scope.filter.age = 6;
  100. }
  101. break;
  102. default:
  103. }
  104. };
  105. $scope.filter = {
  106. hasMore: false,
  107. pageIndex: 1,
  108. pageSize: 20,
  109. sex: 0,//1男,2女,0:全部,
  110. age: 0,//0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>38,
  111. city:''
  112. };
  113. $scope.index = {
  114. banner: [],
  115. users: [],
  116. dreams:[]
  117. };
  118. $scope.next = function (type) {
  119. //type:1 前一个,type:2 后一个
  120. if($scope.index.users.length>0){
  121. if(type==1)
  122. {
  123. var temp= $scope.index.users.splice(0,1);
  124. $scope.index.users.push(temp[0]);
  125. }
  126. if (type==2){
  127. var temp= $scope.index.users.splice($scope.index.users.length-1,1);
  128. $scope.index.users.unshift(temp[0]);
  129. }
  130. }
  131. };
  132. $scope.load = function (init) {
  133. if (init) {
  134. $scope.filter.pageIndex = 1;
  135. $scope.index.dreams = [];
  136. }
  137. msg.loading();
  138. homeService.index($scope.type, $scope.filter.pageIndex).then(function (result) {
  139. msg.hide();
  140. $scope.index.banners = result.data.data.banners;
  141. $scope.index.users = result.data.data.users;
  142. $scope.filter.pageIndex++;
  143. var more = (result.data.data.dreams.data.length >= $scope.filter.pageSize);
  144. $scope.filter.hasMore = more;
  145. $scope.index.dreams = $scope.index.dreams.concat(result.data.data.dreams.data);
  146. if (init) {
  147. $scope.$broadcast('scroll.refreshComplete');
  148. } else {
  149. $scope.$broadcast('scroll.infiniteScrollComplete');
  150. }
  151. }, function (error) {
  152. msg.hide();
  153. });
  154. };
  155. $scope.qrscan = function () {
  156. cordova.plugins.barcodeScanner.scan(
  157. function (result) {
  158. //扫码成功后执行的回调函数
  159. alert("收到一个二维码\n" +
  160. "扫码文字结果: " + result.text + "\n" +
  161. "格式: " + result.format + "\n" +
  162. "是否在扫码页面取消扫码: " + result.cancelled);
  163. },
  164. function (error) {
  165. //扫码失败执行的回调函数
  166. alert("Scanning failed: " + error);
  167. }, {
  168. preferFrontCamera: false, // iOS and Android 设置前置摄像头
  169. showFlipCameraButton: true, // iOS and Android 显示旋转摄像头按钮
  170. showTorchButton: true, // iOS and Android 显示打开闪光灯按钮
  171. torchOn: false, // Android, launch with the torch switched on (if available)打开手电筒
  172. prompt: "在扫描区域内放置二维码", // Android提示语
  173. resultDisplayDuration: 500, // Android, display scanned text for X ms.
  174. //0 suppresses it entirely, default 1500 设置扫码时间的参数
  175. formats: "QR_CODE", // 二维码格式可设置多种类型
  176. orientation: "portrait", // Android only (portrait|landscape),
  177. //default unset so it rotates with the device在安卓上 landscape 是横屏状态
  178. disableAnimations: true, // iOS 是否禁止动画
  179. disableSuccessBeep: false // iOS 禁止成功后提示声音 “滴”
  180. }
  181. );
  182. };
  183. $scope.data = {};
  184. $scope.load(true);
  185. $scope.$on('$ionicView.beforeLeave', function () {
  186. $scope.popover.hide();
  187. $scope.load(true);
  188. });
  189. }]);
  190. app.controller('dreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
  191. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $ionicScrollDelegate, $interval) {
  192. var id = $stateParams.id;
  193. var top3user = '';
  194. $scope.chosedIndex = 0;
  195. $scope.clickAvatar = function(index){
  196. $scope.chosedIndex = index;
  197. };
  198. // id=5;
  199. $scope.$on('$ionicView.beforeEnter', function () {
  200. $ionicTabsDelegate.showBar(false);
  201. $scope.load(id);
  202. $scope.thisUser = storage.getObject('user');
  203. homeService.myInfo().then(function(result){
  204. $scope.user = result.data.data;
  205. });
  206. console.log($scope.user);
  207. });
  208. $scope.$on('$ionicView.leave', function () {
  209. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  210. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  211. });
  212. $scope.load = function (id) {
  213. msg.loading();
  214. homeService.dreamDetail(id).then(function (result) {
  215. msg.hide();
  216. console.log(result);
  217. $scope.dream = result.data.data;
  218. var reg = new RegExp("\n", "g");
  219. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  220. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  221. var date = new Date();
  222. var inter = (end_time.getTime() - date.getTime()) / 1000;
  223. leftTimer(inter);
  224. $scope.multi.a = $scope.dream.a;
  225. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  226. $scope.multi.c = $scope.dream.c;
  227. $scope.multi.promise = $scope.dream.a;
  228. var newtop3user = '' ;
  229. angular.forEach($scope.dream.top3user, function(user) {
  230. newtop3user= newtop3user +user.id+","
  231. });
  232. if(top3user!=''&&newtop3user!=top3user){
  233. //测试动画切换
  234. $timeout(function() {
  235. $scope.sort.slide1 = 'list-grow-animation';
  236. $scope.sort.slide2 = 'slide-in-both-ways';
  237. $scope.sort.slide3 = 'bounce-animation';
  238. }, 50);
  239. }
  240. top3user = newtop3user;
  241. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  242. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  243. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  244. $scope.calcmultiplier();
  245. }, function (error) {
  246. msg.hide();
  247. });
  248. };
  249. $scope.openSupport = function () {
  250. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  251. };
  252. // $ionicModal.fromTemplateUrl('supportExplain.html', {
  253. // scope: $scope
  254. // }).then(function(modal) {
  255. // $scope.supportmodal = modal;
  256. // });
  257. // $scope.openSupportmodal = function() {
  258. // $scope.supportmodal.show();
  259. // };
  260. // $scope.closeSupportmodal = function() {
  261. // $scope.supportmodal.hide();
  262. // };
  263. $scope.multi = {
  264. a: '',
  265. b: '',
  266. c: '',
  267. result: 1,
  268. promise:null
  269. };
  270. $scope.type = 1;//tab切换
  271. $scope.tosupport = false;
  272. $scope.support = function ($event) {
  273. $event.stopPropagation();
  274. $scope.tosupport = true;
  275. $scope.vm.coin = 0;
  276. $scope.index = 0;
  277. };
  278. $scope.cancelSupport = function () {
  279. $scope.tosupport = false;
  280. $scope.toshare = false;
  281. $scope.input.show = false;
  282. };
  283. $scope.toshare = false;
  284. $scope.share = function ($event) {
  285. $event.stopPropagation();
  286. $scope.toshare = true;
  287. };
  288. $scope.toRecharge = function(){
  289. $state.go("app.recharge")
  290. };
  291. $scope.shareDream = function (type) {
  292. if (type==1) {//微信
  293. Wechat.share({
  294. text: "微信分享",
  295. scene: Wechat.Scene.TIMELINE // share to Timeline
  296. }, function () {
  297. alert("Success");
  298. }, function (reason) {
  299. alert("Failed: " + reason);
  300. });
  301. //Wechat.share({
  302. // message: {
  303. // title: "微信分享",
  304. // description: "This is description.",
  305. // thumb: "www/img/thumbnail.png",
  306. // mediaTagName: "TEST-TAG-001",
  307. // messageExt: "这是第三方带的测试字段",
  308. // messageAction: "<action>dotalist</action>",
  309. // media: "YOUR_MEDIA_OBJECT_HERE"
  310. // },
  311. // scene: Wechat.Scene.TIMELINE // share to Timeline
  312. //}, function () {
  313. // alert("Success");
  314. //}, function (reason) {
  315. // alert("Failed: " + reason);
  316. //});
  317. //Wechat.share({
  318. // message: {
  319. // media: {
  320. // type: Wechat.Type.WEBPAGE,
  321. // webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
  322. // }
  323. // },
  324. // scene: Wechat.Scene.TIMELINE // share to Timeline
  325. //}, function () {
  326. // alert("Success");
  327. //}, function (reason) {
  328. // alert("Failed: " + reason);
  329. //});
  330. }
  331. if (type == 2) {//微博 https://github.com/iVanPan/cordova_weibo/blob/master/README_ZH.md
  332. var args = {};
  333. args.text = '微博文字分享';
  334. WeiboSDK.shareTextToWeibo(function () {
  335. alert('share success');
  336. }, function (failReason) {
  337. alert(failReason);
  338. }, args);
  339. }
  340. // $state.go("app.shareDream",{item:$scope.dream});
  341. };
  342. //实时排行
  343. $scope.sort = {
  344. slide: ''
  345. };
  346. $scope.changeType = function (type) {
  347. $ionicScrollDelegate.scrollTop(true);
  348. $scope.type = type;
  349. };
  350. $scope.index = 0;
  351. $scope.vm = {
  352. coin:"",
  353. title:""
  354. };
  355. $scope.timer = '';
  356. var leftTimer = function (countDown) {
  357. if (isNaN(countDown)) {
  358. $scope.timer = '结束';
  359. return;
  360. }
  361. var day=parseInt(countDown/(24*60*60));
  362. var h=parseInt(countDown/(60*60)%24);
  363. var m=parseInt(countDown/60%60);
  364. var s=parseInt(countDown%60);
  365. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  366. if(day>0) $scope.timer = day+'天';
  367. if(day<0 && h>0) $scope.timer = h+'小时';
  368. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  369. if(day<0 && h<0 && m<0) $scope.timer = '结束';
  370. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  371. $scope.leftTimer = $interval(function () {
  372. if (countDown >= 1) leftTimer(countDown - 1);
  373. },1000);*/
  374. /* if(countDown<=0){
  375. $scope.timer='结束';
  376. }*/
  377. };
  378. $scope.changeIndex = function (index) {
  379. $scope.index = index;
  380. $scope.vm.coin = index*5;
  381. };
  382. $scope.vidEnded = function () {
  383. alert('播放完毕');
  384. };
  385. //实时计算支持乘数
  386. $scope.calcmultiplier = function () {
  387. $scope.multi.promise = $interval(function () {
  388. var date = new Date();
  389. var inter = date.getTime() - $scope.multi.b.getTime();
  390. var minutes = Math.floor(inter / (60 * 1000));
  391. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  392. if (number<=1) {
  393. number = 1;
  394. }
  395. //$scope.multi.result = Math.round(number * 100) / 100;
  396. $scope.multi.result = Math.round(number * 100 / 100);
  397. },1000);
  398. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  399. };
  400. $scope.supportDream = function (data) {
  401. if(!$scope.vm.coin){
  402. msg.error("请选择梦想币数量!");
  403. return ;
  404. }
  405. var data = {
  406. id:id,
  407. coin:$scope.vm.coin
  408. };
  409. homeService.supportDream(data).then(function(result){
  410. $scope.tosupport = false;
  411. $scope.load(id);
  412. $interval.cancel($scope.multi.promise);
  413. })
  414. };
  415. $scope.collectionDream = function(is_collection){
  416. homeService.collectionDream(id,is_collection).then(function(result){
  417. $scope.dream.is_collection=result.data.data;
  418. })
  419. };
  420. $scope.add = function(is_collection){
  421. var data = {
  422. id:id,
  423. title:$scope.vm.title,
  424. pics:$scope.imgs
  425. };
  426. homeService.add_interaction(data).then(function(){
  427. $scope.load(id);
  428. $scope.closeModal();
  429. })
  430. };
  431. $scope.showAbout = true;
  432. $scope.hideAbout = false;
  433. $scope.showText = function(){
  434. $scope.aboutStyle = {
  435. "white-space" : "normal"
  436. };
  437. $scope.showAbout = false;
  438. $scope.hideAbout = true;
  439. };
  440. $scope.hideText = function(){
  441. $scope.aboutStyle = {
  442. "white-space" : "nowrap"
  443. };
  444. $scope.showAbout = true;
  445. $scope.hideAbout = false;
  446. };
  447. $scope.input = {
  448. placeholder: '评论',
  449. focus: false,
  450. show:false
  451. };
  452. $scope.replay = function ($event, name) {
  453. $event.stopPropagation();
  454. $scope.input.focus = true;
  455. $scope.input.show = true;
  456. $scope.input.placeholder = "回复" + name;
  457. $scope.vm.title='';
  458. };
  459. $scope.comment = function(){
  460. // $event.stopPropagation();
  461. //$scope.input.placeholder = "评论";
  462. $scope.input.focus = true;
  463. $scope.vm.title='';
  464. };
  465. $scope.submitComment = function(iid){
  466. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  467. var data = {
  468. id:iid,
  469. content:$scope.vm.comment
  470. };
  471. console.log($scope.vm.comment+" "+iid);
  472. homeService.add_comment(data).then(function(){
  473. $scope.vm.comment = '' ;
  474. $scope.load(id);
  475. $scope.closeModal();
  476. })
  477. };
  478. $scope.bigImage = false;
  479. $scope.showBigImage = function(imageName){
  480. $scope.url = imageName;
  481. $scope.bigImage = true;
  482. };
  483. $scope.hideBigImage = function(){
  484. $scope.bigImage = false;
  485. };
  486. $scope.addpict = function () {
  487. common.chooseImage().then(function (img) {
  488. common.uploadFiles(img,1).then(function (result) {
  489. var response = JSON.parse(result.response);
  490. var file = response.data.file;
  491. $scope.imgs.push(config.imgServer+file);
  492. console.log(JSON.stringify(config.imgServer+file));
  493. }, function (error) {
  494. msg.error('图片上传失败');
  495. });
  496. }, function (error) {
  497. console.log('图片选择失败');
  498. });
  499. };
  500. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  501. scope: $scope,
  502. animation: 'slide-in-up'
  503. }).then(function(modal) {
  504. $scope.rechagemodal = modal;
  505. });
  506. $scope.openRechargeModal = function() {
  507. $scope.rechagemodal.show();
  508. $scope.vm.money = '';
  509. };
  510. $scope.closeRechargeModal = function() {
  511. $scope.rechagemodal.hide();
  512. };
  513. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  514. scope: $scope,
  515. animation: 'slide-in-up'
  516. }).then(function(modal) {
  517. $scope.modal = modal;
  518. });
  519. $scope.openModal = function() {
  520. $scope.modal.show();
  521. $scope.vm.title = '';
  522. $scope.imgs = [];
  523. };
  524. $scope.closeModal = function() {
  525. $scope.modal.hide();
  526. };
  527. //当我们用到模型时,清除它!
  528. $scope.$on('$destroy', function() {
  529. $scope.modal.remove();
  530. });
  531. $scope.toMessage = function(){
  532. $state.go("app.message");
  533. }
  534. }]);
  535. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  536. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  537. var id = $stateParams.id;
  538. var top3user = '';
  539. $scope.chosedIndex = 0;
  540. $scope.clickAvatar = function(index){
  541. $scope.chosedIndex = index;
  542. };
  543. // id=5;
  544. $scope.$on('$ionicView.beforeEnter', function () {
  545. $ionicTabsDelegate.showBar(false);
  546. $scope.load(id);
  547. $scope.thisUser = storage.getObject('user');
  548. homeService.myInfo().then(function(result){
  549. $scope.user = result.data.data;
  550. });
  551. console.log($scope.user);
  552. });
  553. $scope.$on('$ionicView.leave', function () {
  554. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  555. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  556. });
  557. $scope.load = function (id) {
  558. msg.loading();
  559. homeService.dreamDetail(id).then(function (result) {
  560. msg.hide();
  561. console.log(result);
  562. $scope.dream = result.data.data;
  563. var reg = new RegExp("\n", "g");
  564. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  565. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  566. var date = new Date();
  567. var inter = (end_time.getTime() - date.getTime()) / 1000;
  568. leftTimer(inter);
  569. $scope.multi.a = $scope.dream.a;
  570. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  571. $scope.multi.c = $scope.dream.c;
  572. $scope.multi.promise = $scope.dream.a;
  573. var newtop3user = '' ;
  574. angular.forEach($scope.dream.top3user, function(user) {
  575. newtop3user= newtop3user +user.id+","
  576. });
  577. if(top3user!=''&&newtop3user!=top3user){
  578. //测试动画切换
  579. $timeout(function() {
  580. $scope.sort.slide1 = 'list-grow-animation';
  581. $scope.sort.slide2 = 'slide-in-both-ways';
  582. $scope.sort.slide3 = 'bounce-animation';
  583. }, 50);
  584. }
  585. top3user = newtop3user;
  586. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  587. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  588. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  589. $scope.calcmultiplier();
  590. }, function (error) {
  591. msg.hide();
  592. });
  593. };
  594. $scope.openSupport = function () {
  595. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  596. };
  597. // $ionicModal.fromTemplateUrl('supportExplain.html', {
  598. // scope: $scope
  599. // }).then(function(modal) {
  600. // $scope.supportmodal = modal;
  601. // });
  602. // $scope.openSupportmodal = function() {
  603. // $scope.supportmodal.show();
  604. // };
  605. // $scope.closeSupportmodal = function() {
  606. // $scope.supportmodal.hide();
  607. // };
  608. $scope.multi = {
  609. a: '',
  610. b: '',
  611. c: '',
  612. result: 1,
  613. promise:null
  614. };
  615. $scope.type = 1;//tab切换
  616. $scope.tosupport = false;
  617. $scope.support = function ($event) {
  618. $event.stopPropagation();
  619. $scope.tosupport = true;
  620. $scope.vm.coin = 0;
  621. $scope.index = 0;
  622. };
  623. $scope.cancelSupport = function () {
  624. $scope.tosupport = false;
  625. $scope.toshare = false;
  626. $scope.input.show = false;
  627. };
  628. $scope.toshare = false;
  629. $scope.share = function ($event) {
  630. $event.stopPropagation();
  631. $scope.toshare = true;
  632. };
  633. $scope.toRecharge = function(){
  634. $state.go("app.recharge")
  635. };
  636. $scope.shareDream = function(){
  637. $state.go("app.shareDream",{item:$scope.dream});
  638. };
  639. //实时排行
  640. $scope.sort = {
  641. slide: ''
  642. };
  643. $scope.changeType = function (type) {
  644. $ionicScrollDelegate.scrollTop(true);
  645. $scope.type = type;
  646. };
  647. $scope.index = 0;
  648. $scope.vm = {
  649. coin:"",
  650. title:""
  651. };
  652. $scope.timer = '';
  653. var leftTimer = function (countDown) {
  654. if (isNaN(countDown)) {
  655. $scope.timer = '结束';
  656. return;
  657. }
  658. var day=parseInt(countDown/(24*60*60));
  659. var h=parseInt(countDown/(60*60)%24);
  660. var m=parseInt(countDown/60%60);
  661. var s=parseInt(countDown%60);
  662. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  663. if(day>0) $scope.timer = day+'天';
  664. if(day<0 && h>0) $scope.timer = h+'小时';
  665. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  666. if(day<0 && h<0 && m<0) $scope.timer = '结束';
  667. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  668. $scope.leftTimer = $interval(function () {
  669. if (countDown >= 1) leftTimer(countDown - 1);
  670. },1000);*/
  671. /* if(countDown<=0){
  672. $scope.timer='结束';
  673. }*/
  674. };
  675. $scope.changeIndex = function (index) {
  676. $scope.index = index;
  677. $scope.vm.coin = index*5;
  678. };
  679. $scope.vidEnded = function () {
  680. alert('播放完毕');
  681. };
  682. //实时计算支持乘数
  683. $scope.calcmultiplier = function () {
  684. $scope.multi.promise = $interval(function () {
  685. var date = new Date();
  686. var inter = date.getTime() - $scope.multi.b.getTime();
  687. var minutes = Math.floor(inter / (60 * 1000));
  688. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  689. if (number<=1) {
  690. number = 1;
  691. }
  692. //$scope.multi.result = Math.round(number * 100) / 100;
  693. $scope.multi.result = Math.round(number * 100 / 100);
  694. },1000);
  695. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  696. };
  697. $scope.supportDream = function (data) {
  698. if(!$scope.vm.coin){
  699. msg.error("请选择梦想币数量!");
  700. return ;
  701. }
  702. var data = {
  703. id:id,
  704. coin:$scope.vm.coin
  705. };
  706. homeService.supportDream(data).then(function(result){
  707. $scope.tosupport = false;
  708. $scope.load(id);
  709. $interval.cancel($scope.multi.promise);
  710. })
  711. };
  712. $scope.collectionDream = function(is_collection){
  713. homeService.collectionDream(id,is_collection).then(function(result){
  714. $scope.dream.is_collection=result.data.data;
  715. })
  716. };
  717. $scope.add = function(is_collection){
  718. var data = {
  719. id:id,
  720. title:$scope.vm.title,
  721. pics:$scope.imgs
  722. };
  723. homeService.add_interaction(data).then(function(){
  724. $scope.load(id);
  725. $scope.closeModal();
  726. })
  727. };
  728. $scope.showAbout = true;
  729. $scope.hideAbout = false;
  730. $scope.showText = function(){
  731. $scope.aboutStyle = {
  732. "white-space" : "normal"
  733. };
  734. $scope.showAbout = false;
  735. $scope.hideAbout = true;
  736. };
  737. $scope.hideText = function(){
  738. $scope.aboutStyle = {
  739. "white-space" : "nowrap"
  740. };
  741. $scope.showAbout = true;
  742. $scope.hideAbout = false;
  743. };
  744. $scope.input = {
  745. placeholder: '评论',
  746. focus: false,
  747. show:false
  748. };
  749. $scope.replay = function ($event, name) {
  750. $event.stopPropagation();
  751. $scope.input.focus = true;
  752. $scope.input.show = true;
  753. $scope.input.placeholder = "回复" + name;
  754. $scope.vm.title='';
  755. };
  756. $scope.comment = function(){
  757. // $event.stopPropagation();
  758. //$scope.input.placeholder = "评论";
  759. $scope.input.focus = true;
  760. $scope.vm.title='';
  761. };
  762. $scope.submitComment = function(iid){
  763. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  764. var data = {
  765. id:iid,
  766. content:$scope.vm.comment
  767. };
  768. console.log($scope.vm.comment+" "+iid);
  769. homeService.add_comment(data).then(function(){
  770. $scope.vm.comment = '' ;
  771. $scope.load(id);
  772. $scope.closeModal();
  773. })
  774. };
  775. $scope.bigImage = false;
  776. $scope.showBigImage = function(imageName){
  777. $scope.url = imageName;
  778. $scope.bigImage = true;
  779. };
  780. $scope.hideBigImage = function(){
  781. $scope.bigImage = false;
  782. };
  783. $scope.addpict = function () {
  784. common.chooseImage().then(function (img) {
  785. common.uploadFiles(img,1).then(function (result) {
  786. var response = JSON.parse(result.response);
  787. var file = response.data.file;
  788. $scope.imgs.push(config.imgServer+file);
  789. console.log(JSON.stringify(config.imgServer+file));
  790. }, function (error) {
  791. msg.error('图片上传失败');
  792. });
  793. }, function (error) {
  794. console.log('图片选择失败');
  795. });
  796. };
  797. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  798. scope: $scope,
  799. animation: 'slide-in-up'
  800. }).then(function(modal) {
  801. $scope.rechagemodal = modal;
  802. });
  803. $scope.openRechargeModal = function() {
  804. $scope.rechagemodal.show();
  805. $scope.vm.money = '';
  806. };
  807. $scope.closeRechargeModal = function() {
  808. $scope.rechagemodal.hide();
  809. };
  810. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  811. scope: $scope,
  812. animation: 'slide-in-up'
  813. }).then(function(modal) {
  814. $scope.modal = modal;
  815. });
  816. $scope.openModal = function() {
  817. $scope.modal.show();
  818. $scope.vm.title = '';
  819. $scope.imgs = [];
  820. };
  821. $scope.closeModal = function() {
  822. $scope.modal.hide();
  823. };
  824. //当我们用到模型时,清除它!
  825. $scope.$on('$destroy', function() {
  826. $scope.modal.remove();
  827. });
  828. $scope.toMessage = function(){
  829. $state.go("app.message");
  830. }
  831. }]);
  832. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  833. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  834. var id = $stateParams.id;
  835. $scope.dream_id = $stateParams.dream_id;
  836. $scope.items = $stateParams.items;
  837. $scope.$on('$ionicView.beforeEnter', function () {
  838. $ionicTabsDelegate.showBar(false);
  839. });
  840. $scope.attentionUser = function(id,is_care){
  841. homeService.attentionUser(id,is_care).then(function(result){
  842. $scope.items.is_care=result.data.data;
  843. })
  844. };
  845. $scope.cancelSupport = function () {
  846. $scope.tosupport = false;
  847. $scope.toshare = false;
  848. };
  849. $scope.toshare = false;
  850. $scope.share = function ($event) {
  851. $event.stopPropagation();
  852. $scope.toshare = true;
  853. };
  854. $scope.shareDream = function(){
  855. $state.go("app.shareDream",{item:$scope.user});
  856. };
  857. $scope.toDetail = function (dream_id) {
  858. $state.go('app.home_dreamdetail',{id:dream_id});
  859. };
  860. $scope.toOldDream = function(){
  861. $state.go("app.oldDream");
  862. };
  863. $scope.toSupportDream = function(){
  864. $state.go("app.supportDream");
  865. };
  866. $scope.collectionDream = function(is_collection){
  867. homeService.collectionDream(id,is_collection).then(function(result){
  868. $scope.user.is_collection=result.data.data;
  869. })
  870. };
  871. }]);
  872. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  873. , function ($scope,homeService,$stateParams, $state, msg) {
  874. $scope.dream = $stateParams.item;
  875. $scope.showAbout = true;
  876. $scope.hideAbout = false;
  877. $scope.showText = function(){
  878. $scope.aboutStyle = {
  879. "white-space" : "normal"
  880. };
  881. $scope.showAbout = false;
  882. $scope.hideAbout = true;
  883. };
  884. $scope.hideText = function(){
  885. $scope.aboutStyle = {
  886. "white-space" : "nowrap"
  887. };
  888. $scope.showAbout = true;
  889. $scope.hideAbout = false;
  890. };
  891. }]);
  892. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  893. , function ($scope,homeService,$stateParams, $state, msg) {
  894. $scope.toDetail = function(){
  895. $state.go("app.home_userDetail")
  896. }
  897. }]);
  898. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  899. , function ($scope,homeService,$stateParams, $state, msg) {
  900. $scope.toDetail = function(){
  901. $state.go("app.home_userDetail")
  902. }
  903. }]);
  904. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  905. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  906. $scope.showMore = function (keyword,index) {
  907. if(!keyword)return;
  908. $scope.index = index;
  909. // $scope.vm.keyword = keyword;
  910. homeService.search(keyword).then(function(result){
  911. $scope.isResult = true;
  912. $scope.dream_infos = result.data.data.dream_infos;
  913. $scope.user_infos = result.data.data.user_infos;
  914. });
  915. };
  916. $scope.search = function (keyword) {
  917. $scope.vm.keyword = keyword;
  918. homeService.search(keyword).then(function(result){
  919. $scope.isResult = true;
  920. $scope.dream_infos = result.data.data.dream_infos;
  921. $scope.user_infos = result.data.data.user_infos;
  922. });
  923. };
  924. $scope.toDetail = function (id) {
  925. $state.go('app.home_dreamdetail',{id:id});
  926. };
  927. $scope.toUser = function (id) {
  928. $state.go('app.home_userDetail',{id:id});
  929. };
  930. $scope.$on('$ionicView.beforeEnter', function () {
  931. $scope.isResult = false;
  932. $scope.index = 0;
  933. $scope.vm = {
  934. keyword : ""
  935. }
  936. $ionicTabsDelegate.showBar(false);
  937. // $ionicNavBarDelegate.showBackButton(false);
  938. homeService.search('').then(function(result){
  939. $scope.hot_searches = result.data.data.hot_searches;
  940. $scope.history_searches = result.data.data.history_searches;
  941. });
  942. });
  943. }]);
  944. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  945. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  946. }]);
  947. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  948. , function ($scope, $state, myService, msg) {
  949. $scope.$on('$ionicView.beforeEnter', function () {
  950. myService.myDream().then(function(result){
  951. console.log(result.data.data);
  952. $scope.dreams = result.data.data;
  953. });
  954. });
  955. $scope.toDetail = function (id) {
  956. $state.go('app.home_dreamdetail',{id:id});
  957. };
  958. }]);
  959. })(angular.module('app.controllers'));