home.js 48 KB

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