home.js 46 KB

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