home.js 47 KB

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