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