home.js 59 KB

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