home.js 46 KB

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