home.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  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) {
  37. homeService.toUserDetail(id).then(function(result){
  38. $scope.items = result.data.data;
  39. $state.go('app.home_userDetail',{id: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. $scope.dream.video = config.imgServer+$scope.dream.video;
  219. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  220. var reg = new RegExp("\n", "g");
  221. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  222. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  223. var date = new Date();
  224. var inter = (end_time.getTime() - date.getTime()) / 1000;
  225. leftTimer(inter);
  226. $scope.multi.a = $scope.dream.a;
  227. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  228. $scope.multi.c = $scope.dream.c;
  229. $scope.multi.promise = $scope.dream.a;
  230. var newtop3user = '' ;
  231. angular.forEach($scope.dream.top3user, function(user) {
  232. newtop3user= newtop3user +user.id+","
  233. });
  234. if(top3user!=''&&newtop3user!=top3user){
  235. //测试动画切换
  236. $timeout(function() {
  237. $scope.sort.slide1 = 'list-grow-animation';
  238. $scope.sort.slide2 = 'slide-in-both-ways';
  239. $scope.sort.slide3 = 'bounce-animation';
  240. }, 50);
  241. }
  242. top3user = newtop3user;
  243. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  244. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  245. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  246. $scope.calcmultiplier();
  247. }, function (error) {
  248. msg.hide();
  249. });
  250. };
  251. $scope.openSupport = function () {
  252. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  253. };
  254. // $ionicModal.fromTemplateUrl('supportExplain.html', {
  255. // scope: $scope
  256. // }).then(function(modal) {
  257. // $scope.supportmodal = modal;
  258. // });
  259. // $scope.openSupportmodal = function() {
  260. // $scope.supportmodal.show();
  261. // };
  262. // $scope.closeSupportmodal = function() {
  263. // $scope.supportmodal.hide();
  264. // };
  265. $scope.multi = {
  266. a: '',
  267. b: '',
  268. c: '',
  269. result: 1,
  270. promise:null
  271. };
  272. $scope.type = 1;//tab切换
  273. $scope.tosupport = false;
  274. $scope.support = function ($event) {
  275. $event.stopPropagation();
  276. $scope.tosupport = true;
  277. $scope.vm.coin = 0;
  278. $scope.index = 0;
  279. };
  280. $scope.cancelSupport = function () {
  281. $scope.tosupport = false;
  282. $scope.toshare = false;
  283. $scope.input.show = false;
  284. };
  285. $scope.toshare = false;
  286. $scope.share = function ($event) {
  287. $event.stopPropagation();
  288. $scope.toshare = true;
  289. };
  290. $scope.toRecharge = function(){
  291. $state.go("app.recharge")
  292. };
  293. $scope.shareDream = function (type) {
  294. if (type==1) {//微信
  295. Wechat.share({
  296. text: "微信分享",
  297. scene: Wechat.Scene.TIMELINE // share to Timeline
  298. }, function () {
  299. alert("Success");
  300. }, function (reason) {
  301. alert("Failed: " + reason);
  302. });
  303. //Wechat.share({
  304. // message: {
  305. // title: "微信分享",
  306. // description: "This is description.",
  307. // thumb: "www/img/thumbnail.png",
  308. // mediaTagName: "TEST-TAG-001",
  309. // messageExt: "这是第三方带的测试字段",
  310. // messageAction: "<action>dotalist</action>",
  311. // media: "YOUR_MEDIA_OBJECT_HERE"
  312. // },
  313. // scene: Wechat.Scene.TIMELINE // share to Timeline
  314. //}, function () {
  315. // alert("Success");
  316. //}, function (reason) {
  317. // alert("Failed: " + reason);
  318. //});
  319. //Wechat.share({
  320. // message: {
  321. // media: {
  322. // type: Wechat.Type.WEBPAGE,
  323. // webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
  324. // }
  325. // },
  326. // scene: Wechat.Scene.TIMELINE // share to Timeline
  327. //}, function () {
  328. // alert("Success");
  329. //}, function (reason) {
  330. // alert("Failed: " + reason);
  331. //});
  332. }
  333. if (type == 2) {//微博 https://github.com/iVanPan/cordova_weibo/blob/master/README_ZH.md
  334. var args = {};
  335. args.text = '微博文字分享';
  336. WeiboSDK.shareTextToWeibo(function () {
  337. alert('share success');
  338. }, function (failReason) {
  339. alert(failReason);
  340. }, args);
  341. }
  342. // $state.go("app.shareDream",{item:$scope.dream});
  343. };
  344. //实时排行
  345. $scope.sort = {
  346. slide: ''
  347. };
  348. $scope.changeType = function (type) {
  349. $ionicScrollDelegate.scrollTop(true);
  350. $scope.type = type;
  351. };
  352. $scope.index = 0;
  353. $scope.vm = {
  354. coin:"",
  355. title:""
  356. };
  357. $scope.timer = '';
  358. var leftTimer = function (countDown) {
  359. if (isNaN(countDown)) {
  360. $scope.timer = '结束';
  361. return;
  362. }
  363. var day=parseInt(countDown/(24*60*60));
  364. var h=parseInt(countDown/(60*60)%24);
  365. var m=parseInt(countDown/60%60);
  366. var s=parseInt(countDown%60);
  367. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  368. if(day>0) $scope.timer = day+'天';
  369. if(day<0 && h>0) $scope.timer = h+'小时';
  370. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  371. if(day<0 && h<0 && m<0) $scope.timer = '结束';
  372. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  373. $scope.leftTimer = $interval(function () {
  374. if (countDown >= 1) leftTimer(countDown - 1);
  375. },1000);*/
  376. /* if(countDown<=0){
  377. $scope.timer='结束';
  378. }*/
  379. };
  380. $scope.changeIndex = function (index) {
  381. $scope.index = index;
  382. $scope.vm.coin = index*10;
  383. };
  384. $scope.vidEnded = function () {
  385. alert('播放完毕');
  386. };
  387. //实时计算支持乘数
  388. $scope.calcmultiplier = function () {
  389. $scope.multi.promise = $interval(function () {
  390. var date = new Date();
  391. var inter = date.getTime() - $scope.multi.b.getTime();
  392. var minutes = Math.floor(inter / (60 * 1000));
  393. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  394. if (number<=1) {
  395. number = 1;
  396. }
  397. //$scope.multi.result = Math.round(number * 100) / 100;
  398. $scope.multi.result = Math.round(number * 100 / 100);
  399. },1000);
  400. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  401. };
  402. $scope.supportDream = function (data) {
  403. if(!$scope.vm.coin){
  404. msg.error("请选择梦想币数量!");
  405. return ;
  406. }
  407. var data = {
  408. id:id,
  409. coin:$scope.vm.coin
  410. };
  411. homeService.supportDream(data).then(function(result){
  412. $scope.tosupport = false;
  413. $scope.load(id);
  414. $interval.cancel($scope.multi.promise);
  415. })
  416. };
  417. $scope.collectionDream = function(is_collection){
  418. homeService.collectionDream(id,is_collection).then(function(result){
  419. $scope.dream.is_collection=result.data.data;
  420. })
  421. };
  422. $scope.add = function(is_collection){
  423. var data = {
  424. id:id,
  425. title:$scope.vm.title,
  426. pics:$scope.imgs
  427. };
  428. homeService.add_interaction(data).then(function(){
  429. $scope.load(id);
  430. $scope.closeModal();
  431. })
  432. };
  433. $scope.showAbout = true;
  434. $scope.hideAbout = false;
  435. $scope.showText = function(){
  436. $scope.aboutStyle = {
  437. "white-space" : "normal"
  438. };
  439. $scope.showAbout = false;
  440. $scope.hideAbout = true;
  441. };
  442. $scope.hideText = function(){
  443. $scope.aboutStyle = {
  444. "white-space" : "nowrap"
  445. };
  446. $scope.showAbout = true;
  447. $scope.hideAbout = false;
  448. };
  449. $scope.input = {
  450. placeholder: '评论',
  451. focus: false,
  452. show:false
  453. };
  454. $scope.replay = function ($event, name) {
  455. $event.stopPropagation();
  456. $scope.input.focus = true;
  457. $scope.input.show = true;
  458. $scope.input.placeholder = "回复" + name;
  459. $scope.vm.title='';
  460. };
  461. $scope.comment = function(){
  462. // $event.stopPropagation();
  463. //$scope.input.placeholder = "评论";
  464. $scope.input.focus = true;
  465. $scope.vm.title='';
  466. };
  467. $scope.submitComment = function(iid){
  468. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  469. var data = {
  470. id:iid,
  471. content:$scope.vm.comment
  472. };
  473. console.log($scope.vm.comment+" "+iid);
  474. homeService.add_comment(data).then(function(){
  475. $scope.vm.comment = '' ;
  476. $scope.load(id);
  477. $scope.closeModal();
  478. })
  479. };
  480. $scope.bigImage = false;
  481. $scope.showBigImage = function(imageName){
  482. $scope.url = imageName;
  483. $scope.bigImage = true;
  484. };
  485. $scope.hideBigImage = function(){
  486. $scope.bigImage = false;
  487. };
  488. $scope.addpict = function () {
  489. common.chooseImage().then(function (img) {
  490. common.uploadFiles(img,1).then(function (result) {
  491. var response = JSON.parse(result.response);
  492. var file = response.data.file;
  493. $scope.imgs.push(config.imgServer+file);
  494. console.log(JSON.stringify(config.imgServer+file));
  495. }, function (error) {
  496. msg.error('图片上传失败');
  497. });
  498. }, function (error) {
  499. console.log('图片选择失败');
  500. });
  501. };
  502. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  503. scope: $scope,
  504. animation: 'slide-in-up'
  505. }).then(function(modal) {
  506. $scope.rechagemodal = modal;
  507. });
  508. $scope.openRechargeModal = function() {
  509. $scope.rechagemodal.show();
  510. $scope.vm.money = '';
  511. };
  512. $scope.closeRechargeModal = function() {
  513. $scope.rechagemodal.hide();
  514. };
  515. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  516. scope: $scope,
  517. animation: 'slide-in-up'
  518. }).then(function(modal) {
  519. $scope.modal = modal;
  520. });
  521. $scope.openModal = function() {
  522. $scope.modal.show();
  523. $scope.vm.title = '';
  524. $scope.imgs = [];
  525. };
  526. $scope.closeModal = function() {
  527. $scope.modal.hide();
  528. };
  529. //当我们用到模型时,清除它!
  530. $scope.$on('$destroy', function() {
  531. $scope.modal.remove();
  532. });
  533. $scope.toMessage = function(){
  534. $state.go("app.message");
  535. }
  536. }]);
  537. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  538. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  539. var id = $stateParams.id;
  540. var top3user = '';
  541. $scope.chosedIndex = 0;
  542. $scope.clickAvatar = function(index){
  543. $scope.chosedIndex = index;
  544. };
  545. // id=5;
  546. $scope.$on('$ionicView.beforeEnter', function () {
  547. $ionicTabsDelegate.showBar(false);
  548. $scope.load(id);
  549. $scope.thisUser = storage.getObject('user');
  550. homeService.myInfo().then(function(result){
  551. $scope.user = result.data.data;
  552. });
  553. console.log($scope.user);
  554. });
  555. $scope.$on('$ionicView.leave', function () {
  556. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  557. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  558. });
  559. $scope.load = function (id) {
  560. msg.loading();
  561. homeService.dreamDetail(id).then(function (result) {
  562. msg.hide();
  563. console.log(result);
  564. $scope.dream = result.data.data;
  565. $scope.dream.video = config.imgServer+$scope.dream.video;
  566. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  567. var reg = new RegExp("\n", "g");
  568. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  569. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  570. var date = new Date();
  571. var inter = (end_time.getTime() - date.getTime()) / 1000;
  572. leftTimer(inter);
  573. $scope.multi.a = $scope.dream.a;
  574. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  575. $scope.multi.c = $scope.dream.c;
  576. $scope.multi.promise = $scope.dream.a;
  577. var newtop3user = '' ;
  578. angular.forEach($scope.dream.top3user, function(user) {
  579. newtop3user= newtop3user +user.id+","
  580. });
  581. if(top3user!=''&&newtop3user!=top3user){
  582. //测试动画切换
  583. $timeout(function() {
  584. $scope.sort.slide1 = 'list-grow-animation';
  585. $scope.sort.slide2 = 'slide-in-both-ways';
  586. $scope.sort.slide3 = 'bounce-animation';
  587. }, 50);
  588. }
  589. top3user = newtop3user;
  590. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  591. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  592. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  593. $scope.calcmultiplier();
  594. }, function (error) {
  595. msg.hide();
  596. });
  597. };
  598. $scope.openSupport = function () {
  599. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  600. };
  601. // $ionicModal.fromTemplateUrl('supportExplain.html', {
  602. // scope: $scope
  603. // }).then(function(modal) {
  604. // $scope.supportmodal = modal;
  605. // });
  606. // $scope.openSupportmodal = function() {
  607. // $scope.supportmodal.show();
  608. // };
  609. // $scope.closeSupportmodal = function() {
  610. // $scope.supportmodal.hide();
  611. // };
  612. $scope.multi = {
  613. a: '',
  614. b: '',
  615. c: '',
  616. result: 1,
  617. promise:null
  618. };
  619. $scope.type = 1;//tab切换
  620. $scope.tosupport = false;
  621. $scope.support = function ($event) {
  622. $event.stopPropagation();
  623. $scope.tosupport = true;
  624. $scope.vm.coin = 0;
  625. $scope.index = 0;
  626. };
  627. $scope.cancelSupport = function () {
  628. $scope.tosupport = false;
  629. $scope.toshare = false;
  630. $scope.input.show = false;
  631. };
  632. $scope.toshare = false;
  633. $scope.share = function ($event) {
  634. $event.stopPropagation();
  635. $scope.toshare = true;
  636. };
  637. $scope.toRecharge = function(){
  638. $state.go("app.recharge")
  639. };
  640. $scope.shareDream = function(){
  641. $state.go("app.shareDream",{item:$scope.dream});
  642. };
  643. //实时排行
  644. $scope.sort = {
  645. slide: ''
  646. };
  647. $scope.changeType = function (type) {
  648. $ionicScrollDelegate.scrollTop(true);
  649. $scope.type = type;
  650. };
  651. $scope.index = 0;
  652. $scope.vm = {
  653. coin:"",
  654. title:""
  655. };
  656. $scope.timer = '';
  657. var leftTimer = function (countDown) {
  658. if (isNaN(countDown)) {
  659. $scope.timer = '结束';
  660. return;
  661. }
  662. var day=parseInt(countDown/(24*60*60));
  663. var h=parseInt(countDown/(60*60)%24);
  664. var m=parseInt(countDown/60%60);
  665. var s=parseInt(countDown%60);
  666. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  667. if(day>0) $scope.timer = day+'天';
  668. if(day<0 && h>0) $scope.timer = h+'小时';
  669. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  670. if(day<0 && h<0 && m<0) $scope.timer = '结束';
  671. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  672. $scope.leftTimer = $interval(function () {
  673. if (countDown >= 1) leftTimer(countDown - 1);
  674. },1000);*/
  675. /* if(countDown<=0){
  676. $scope.timer='结束';
  677. }*/
  678. };
  679. $scope.changeIndex = function (index) {
  680. $scope.index = index;
  681. $scope.vm.coin = index*10;
  682. };
  683. $scope.vidEnded = function () {
  684. alert('播放完毕');
  685. };
  686. //实时计算支持乘数
  687. $scope.calcmultiplier = function () {
  688. $scope.multi.promise = $interval(function () {
  689. var date = new Date();
  690. var inter = date.getTime() - $scope.multi.b.getTime();
  691. var minutes = Math.floor(inter / (60 * 1000));
  692. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  693. if (number<=1) {
  694. number = 1;
  695. }
  696. //$scope.multi.result = Math.round(number * 100) / 100;
  697. $scope.multi.result = Math.round(number * 100 / 100);
  698. },1000);
  699. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  700. };
  701. $scope.supportDream = function (data) {
  702. if(!$scope.vm.coin){
  703. msg.error("请选择梦想币数量!");
  704. return ;
  705. }
  706. var data = {
  707. id:id,
  708. coin:$scope.vm.coin
  709. };
  710. homeService.supportDream(data).then(function(result){
  711. $scope.tosupport = false;
  712. $scope.load(id);
  713. $interval.cancel($scope.multi.promise);
  714. })
  715. };
  716. $scope.collectionDream = function(is_collection){
  717. homeService.collectionDream(id,is_collection).then(function(result){
  718. $scope.dream.is_collection=result.data.data;
  719. })
  720. };
  721. $scope.add = function(is_collection){
  722. var data = {
  723. id:id,
  724. title:$scope.vm.title,
  725. pics:$scope.imgs
  726. };
  727. homeService.add_interaction(data).then(function(){
  728. $scope.load(id);
  729. $scope.closeModal();
  730. })
  731. };
  732. $scope.showAbout = true;
  733. $scope.hideAbout = false;
  734. $scope.showText = function(){
  735. $scope.aboutStyle = {
  736. "white-space" : "normal"
  737. };
  738. $scope.showAbout = false;
  739. $scope.hideAbout = true;
  740. };
  741. $scope.hideText = function(){
  742. $scope.aboutStyle = {
  743. "white-space" : "nowrap"
  744. };
  745. $scope.showAbout = true;
  746. $scope.hideAbout = false;
  747. };
  748. $scope.input = {
  749. placeholder: '评论',
  750. focus: false,
  751. show:false
  752. };
  753. $scope.replay = function ($event, name) {
  754. $event.stopPropagation();
  755. $scope.input.focus = true;
  756. $scope.input.show = true;
  757. $scope.input.placeholder = "回复" + name;
  758. $scope.vm.title='';
  759. };
  760. $scope.comment = function(){
  761. // $event.stopPropagation();
  762. //$scope.input.placeholder = "评论";
  763. $scope.input.focus = true;
  764. $scope.vm.title='';
  765. };
  766. $scope.submitComment = function(iid){
  767. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  768. var data = {
  769. id:iid,
  770. content:$scope.vm.comment
  771. };
  772. console.log($scope.vm.comment+" "+iid);
  773. homeService.add_comment(data).then(function(){
  774. $scope.vm.comment = '' ;
  775. $scope.load(id);
  776. $scope.closeModal();
  777. })
  778. };
  779. $scope.bigImage = false;
  780. $scope.showBigImage = function(imageName){
  781. $scope.url = imageName;
  782. $scope.bigImage = true;
  783. };
  784. $scope.hideBigImage = function(){
  785. $scope.bigImage = false;
  786. };
  787. $scope.addpict = function () {
  788. common.chooseImage().then(function (img) {
  789. common.uploadFiles(img,1).then(function (result) {
  790. var response = JSON.parse(result.response);
  791. var file = response.data.file;
  792. $scope.imgs.push(config.imgServer+file);
  793. console.log(JSON.stringify(config.imgServer+file));
  794. }, function (error) {
  795. msg.error('图片上传失败');
  796. });
  797. }, function (error) {
  798. console.log('图片选择失败');
  799. });
  800. };
  801. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  802. scope: $scope,
  803. animation: 'slide-in-up'
  804. }).then(function(modal) {
  805. $scope.rechagemodal = modal;
  806. });
  807. $scope.openRechargeModal = function() {
  808. $scope.rechagemodal.show();
  809. $scope.vm.money = '';
  810. };
  811. $scope.closeRechargeModal = function() {
  812. $scope.rechagemodal.hide();
  813. };
  814. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  815. scope: $scope,
  816. animation: 'slide-in-up'
  817. }).then(function(modal) {
  818. $scope.modal = modal;
  819. });
  820. $scope.openModal = function() {
  821. $scope.modal.show();
  822. $scope.vm.title = '';
  823. $scope.imgs = [];
  824. };
  825. $scope.closeModal = function() {
  826. $scope.modal.hide();
  827. };
  828. //当我们用到模型时,清除它!
  829. $scope.$on('$destroy', function() {
  830. $scope.modal.remove();
  831. });
  832. $scope.toMessage = function(){
  833. $state.go("app.my_message");
  834. }
  835. }]);
  836. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  837. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  838. var id = $stateParams.id;
  839. $scope.items = $stateParams.items;
  840. $scope.$on('$ionicView.beforeEnter', function () {
  841. $ionicTabsDelegate.showBar(false);
  842. });
  843. $scope.attentionUser = function(is_care){
  844. homeService.attentionUser(id,is_care).then(function(result){
  845. $scope.items.is_care=result.data.data;
  846. })
  847. };
  848. $scope.next = function (type) {
  849. //type:1 前一个,type:2 后一个
  850. if($scope.items.imgs.length>0){
  851. if(type==1)
  852. {
  853. var temp= $scope.items.imgs.splice(0,1);
  854. $scope.items.imgs.push(temp[0]);
  855. }
  856. if (type==2){
  857. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  858. $scope.items.imgs.unshift(temp[0]);
  859. }
  860. }
  861. };
  862. $scope.bigImage = false;
  863. $scope.showBigImage = function(imageName){
  864. $scope.url = imageName;
  865. $scope.bigImage = true;
  866. };
  867. $scope.hideBigImage = function(){
  868. $scope.bigImage = false;
  869. };
  870. $scope.cancelSupport = function () {
  871. $scope.tosupport = false;
  872. $scope.toshare = false;
  873. };
  874. $scope.toshare = false;
  875. $scope.share = function ($event) {
  876. $event.stopPropagation();
  877. $scope.toshare = true;
  878. };
  879. $scope.shareDream = function(){
  880. $state.go("app.shareDream",{item:$scope.user});
  881. };
  882. $scope.toDetail = function (dream_id) {
  883. if($scope.items.near_dream==null){
  884. msg.alert("当前梦想","该用户没有当前梦想");
  885. }
  886. if($scope.items.near_dream!=null){
  887. var dream_id = $scope.items.near_dream.id;
  888. $state.go('app.home_dreamdetail',{id:dream_id});
  889. }
  890. };
  891. $scope.toOldDream = function(){
  892. if($scope.items.dreams.length==0){
  893. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  894. }
  895. if($scope.items.dreams.length!=0){
  896. $state.go("app.oldDream",{user_id:$scope.items.user.id});
  897. }
  898. };
  899. $scope.toSupportDream = function(){
  900. if($scope.items.sup_dreams.length==0){
  901. msg.alert("支持的梦想","该用户没有支持的梦想");
  902. }
  903. if($scope.items.sup_dreams.length!=0){
  904. $state.go("app.supportDream",{user_id:$scope.items.user.id});
  905. }
  906. };
  907. $scope.collectionDream = function(is_collection){
  908. homeService.collectionDream(id,is_collection).then(function(result){
  909. $scope.user.is_collection=result.data.data;
  910. })
  911. };
  912. }]);
  913. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  914. , function ($scope,homeService,$stateParams, $state, msg) {
  915. $scope.dream = $stateParams.item;
  916. $scope.showAbout = true;
  917. $scope.hideAbout = false;
  918. $scope.showText = function(){
  919. $scope.aboutStyle = {
  920. "white-space" : "normal"
  921. };
  922. $scope.showAbout = false;
  923. $scope.hideAbout = true;
  924. };
  925. $scope.hideText = function(){
  926. $scope.aboutStyle = {
  927. "white-space" : "nowrap"
  928. };
  929. $scope.showAbout = true;
  930. $scope.hideAbout = false;
  931. };
  932. }]);
  933. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  934. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  935. $scope.$on('$ionicView.beforeEnter', function () {
  936. $ionicTabsDelegate.showBar(false);
  937. myService.messageInfo().then(function(result){
  938. $scope.infos = result.data.data;
  939. },function(error){
  940. });
  941. });
  942. $scope.notRead = function(){
  943. $scope.readStyle = {
  944. "display" : "none"
  945. };
  946. };
  947. //系统消息
  948. $scope.systemInfo = function(){
  949. $state.go("app.message_sys");
  950. myService.systemInfo().then(function(result){
  951. },function(error){
  952. });
  953. };
  954. //回复我的
  955. $scope.replyMy = function(){
  956. $state.go("app.message_reply");
  957. myService.replyMy().then(function(result){
  958. },function(error){
  959. });
  960. };
  961. $scope.personalLetter = function(){
  962. $state.go("app.letter");
  963. }
  964. }]);
  965. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  966. , function ($scope,homeService,$stateParams, $state, msg) {
  967. var user_id = $stateParams.user_id;
  968. $scope.$on('$ionicView.beforeEnter',function(){
  969. $scope.toUserDetail(user_id);
  970. });
  971. $scope.toUserDetail = function(user_id){
  972. homeService.toUserDetail(user_id).then(function(result){
  973. $scope.items = result.data.data;
  974. $scope.user = result.data.data.user;
  975. $scope.dreams = $scope.user.sup_dream;
  976. },function(error){
  977. })
  978. };
  979. $scope.toDetail = function(){
  980. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  981. }
  982. }]);
  983. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  984. , function ($scope,homeService,$stateParams, $state, msg) {
  985. var user_id = $stateParams.user_id;
  986. $scope.$on('$ionicView.beforeEnter',function(){
  987. $scope.toUserDetail(user_id);
  988. });
  989. $scope.toUserDetail = function(user_id){
  990. homeService.toUserDetail(user_id).then(function(result){
  991. $scope.items = result.data.data;
  992. $scope.user = result.data.data.user;
  993. $scope.dreams = $scope.user.sup_dream;
  994. },function(error){
  995. })
  996. };
  997. $scope.toDetail = function(){
  998. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  999. }
  1000. }]);
  1001. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1002. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1003. $scope.showMore = function (keyword,index) {
  1004. if(!keyword)return;
  1005. $scope.index = index;
  1006. $scope.search(keyword);
  1007. };
  1008. $scope.search = function (keyword) {
  1009. $scope.vm.keyword = keyword;
  1010. homeService.search(keyword).then(function(result){
  1011. $scope.isResult = true;
  1012. $scope.dream_infos = result.data.data.dream_infos;
  1013. $scope.user_infos = result.data.data.user_infos;
  1014. });
  1015. };
  1016. $scope.toUserDetail = function (id) {
  1017. homeService.toUserDetail(id).then(function(result){
  1018. $scope.items = result.data.data;
  1019. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1020. },function(error){
  1021. //msg.error(msg.data.error)
  1022. })
  1023. };
  1024. $scope.toDetail = function (id) {
  1025. $state.go('app.home_dreamdetail',{id:id});
  1026. };
  1027. $scope.$on('$ionicView.beforeEnter', function () {
  1028. $scope.isResult = false;
  1029. $scope.index = 0;
  1030. $scope.vm = {
  1031. keyword : ""
  1032. };
  1033. $ionicTabsDelegate.showBar(false);
  1034. // $ionicNavBarDelegate.showBackButton(false);
  1035. homeService.search('').then(function(result){
  1036. $scope.hot_searches = result.data.data.hot_searches;
  1037. $scope.history_searches = result.data.data.history_searches;
  1038. });
  1039. });
  1040. }]);
  1041. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1042. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1043. }]);
  1044. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1045. , function ($scope, $state, myService, msg) {
  1046. $scope.$on('$ionicView.beforeEnter', function () {
  1047. myService.myDream().then(function(result){
  1048. console.log(result.data.data);
  1049. $scope.dreams = result.data.data;
  1050. });
  1051. });
  1052. $scope.toDetail = function (id) {
  1053. $state.go('app.home_dreamdetail',{id:id});
  1054. };
  1055. }]);
  1056. })(angular.module('app.controllers'));