home.js 46 KB

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