home.js 47 KB

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