home.js 40 KB

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