home.js 46 KB

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