home.js 44 KB

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