home.js 46 KB

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