home.js 50 KB

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