home.js 48 KB

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