home.js 44 KB

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