home.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  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("评论","是否删除评论").then(function(res){
  470. if(res)
  471. {
  472. }else {
  473. }
  474. });
  475. }
  476. };
  477. $scope.testcharge = function(number){
  478. if (!number) {
  479. msg.text('请输入充值金额');
  480. return;
  481. }
  482. homeService.testcharge(number,2).then(function (result) {
  483. msg.text("充值成功");
  484. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  485. $timeout(function () {
  486. $scope.closeRechargeModal();
  487. }, 500);
  488. homeService.myInfo().then(function (result) {
  489. $scope.user = result.data.data;
  490. });
  491. })
  492. }
  493. //充值
  494. $scope.charge = function(number){
  495. if (!number) {
  496. msg.text('请输入充值金额');
  497. return;
  498. }
  499. homeService.charge(number,2).then(function (result) {
  500. //todo:result需要返回支付宝或者微信的签名信息
  501. console.log("result: " + JSON.stringify(result));
  502. var payInfo = result.data;
  503. if ($scope.vm.payType == 1) { //支付宝
  504. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  505. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  506. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  507. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  508. //当e.resultStatus为9000时,请去服务端验证支付结果
  509. $scope.clicksub = false;
  510. if (e.resultStatus == '9000') {
  511. alert(orderID);
  512. //支付成功
  513. // $state.go('app.my');
  514. } else {
  515. msg.error("支付失败");
  516. // msg.error("支付失败:" + JSON.stringify(e));
  517. }
  518. }, function error(e) {
  519. $scope.clicksub = false;
  520. // msg.error("支付失败:" + JSON.stringify(e));
  521. msg.error("支付失败");
  522. });
  523. }
  524. if ($scope.vm.payType == 2) { //微信
  525. var obj = JSON.parse(payInfo);
  526. var params = {
  527. partnerid: obj.partnerid, // merchant id
  528. prepayid: obj.prepayid, // prepay id
  529. noncestr: obj.noncestr, // nonce
  530. timestamp: obj.timestamp, // timestamp
  531. sign: obj.sign, // signed string
  532. };
  533. Wechat.sendPaymentRequest(params, function (r) {
  534. $scope.clicksub = false;
  535. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  536. // alert(result);
  537. //支付成功
  538. // $state.go('app.my');
  539. }, function (erro) {
  540. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  541. });
  542. }, function (reason) {
  543. $scope.clicksub = false;
  544. msg.alert("支付失败:" + JSON.stringify(reason));
  545. });
  546. }
  547. // msg.text("充值成功");
  548. // $state.go('app.my');
  549. });
  550. }
  551. $scope.submitComment = function (index) {
  552. var interaction = $scope.dream.interactions[index];
  553. var iid = interaction.id;
  554. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  555. $scope.input.focus = true;
  556. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  557. var data = {
  558. id:iid,
  559. content:$scope.vm.comment
  560. };
  561. console.log($scope.vm.comment+" "+iid);
  562. homeService.add_comment(data).then(function(){
  563. $scope.vm.comment = '' ;
  564. $scope.load(id);
  565. $scope.closeModal();
  566. })
  567. };
  568. $scope.bigImage = false;
  569. $scope.showBigImage = function ($event, imageName) {
  570. $event.stopPropagation();
  571. $scope.url = imageName;
  572. $scope.bigImage = true;
  573. };
  574. $scope.hideBigImage = function(){
  575. $scope.bigImage = false;
  576. };
  577. $ionicModal.fromTemplateUrl('qrCode.html', {
  578. scope: $scope,
  579. animation: 'slide-in-up'
  580. }).then(function(modal) {
  581. $scope.qrCodemodal = modal;
  582. });
  583. $scope.openCode = function() {
  584. $scope.qrCodemodal.show();
  585. $scope.vm.money = '';
  586. };
  587. $scope.closeCode = function() {
  588. $scope.qrCodemodal.hide();
  589. };
  590. $ionicModal.fromTemplateUrl('commentPic.html', {
  591. scope: $scope,
  592. animation: 'slide-in-up'
  593. }).then(function(modal) {
  594. $scope.CommentPicmodal = modal;
  595. });
  596. $scope.openCommentPic = function(pic) {
  597. $scope.CommentPicmodal.show();
  598. $scope.commentPicUrl = pic;
  599. };
  600. $scope.closeCommentPic = function() {
  601. $scope.CommentPicmodal.hide();
  602. };
  603. $scope.addpict = function () {
  604. common.chooseImage().then(function (img) {
  605. common.uploadFiles(img,1).then(function (result) {
  606. var response = JSON.parse(result.response);
  607. var file = response.data.file;
  608. $scope.imgs.push(config.imgServer+file);
  609. console.log(JSON.stringify(config.imgServer+file));
  610. }, function (error) {
  611. msg.error('图片上传失败');
  612. });
  613. }, function (error) {
  614. console.log('图片选择失败');
  615. });
  616. };
  617. $scope.deletefile = function (file) {
  618. var index = $scope.imgs.indexOf(file);
  619. $scope.imgs.splice(index, 1);
  620. common.deletefile(file).then(function () {
  621. })
  622. };
  623. $scope.addvideo = function () {
  624. common.chooseVideo().then(function (file) {
  625. common.uploadFiles(file, 2).then(function (result) {
  626. var response = JSON.parse(result.response);
  627. $scope.video.server = response.data.file;
  628. var file = config.imgServer+response.data.file;
  629. console.log("file:"+file);
  630. $scope.video.isOK = true;
  631. $scope.video.file = file;
  632. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  633. console.log("vpic:"+$scope.video.vpic);
  634. }, function (error) {
  635. msg.error('视频上传失败');
  636. });
  637. }, function (erro) {
  638. console.log('选择视频失败');
  639. });
  640. };
  641. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  642. scope: $scope,
  643. animation: 'slide-in-up'
  644. }).then(function(modal) {
  645. $scope.rechagemodal = modal;
  646. });
  647. $scope.openRechargeModal = function() {
  648. $scope.rechagemodal.show();
  649. $scope.vm.money = '';
  650. };
  651. $scope.closeRechargeModal = function() {
  652. $scope.rechagemodal.hide();
  653. };
  654. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  655. scope: $scope,
  656. animation: 'slide-in-up'
  657. }).then(function(modal) {
  658. $scope.modal = modal;
  659. });
  660. $scope.openModal = function() {
  661. $scope.modal.show();
  662. $scope.vm.title = '';
  663. $scope.imgs = [];
  664. $scope.video = {};
  665. };
  666. $scope.closeModal = function() {
  667. $scope.modal.hide();
  668. };
  669. //当我们用到模型时,清除它!
  670. $scope.$on('$destroy', function() {
  671. $scope.modal.remove();
  672. });
  673. $scope.toMessage = function(){
  674. $state.go("app.message");
  675. }
  676. }]);
  677. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  678. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  679. var id = $stateParams.id;
  680. var top3user = '';
  681. $scope.chosedIndex = 0;
  682. $scope.clickAvatar = function(index){
  683. $scope.chosedIndex = index;
  684. homeService.myInfo().then(function(result){
  685. $scope.user = result.data.data;
  686. });
  687. };
  688. // id=5;
  689. $scope.$on('$ionicView.beforeEnter', function () {
  690. $ionicTabsDelegate.showBar(false);
  691. $scope.load(id);
  692. $scope.thisUser = storage.getObject('user');
  693. homeService.myInfo().then(function(result){
  694. $scope.user = result.data.data;
  695. });
  696. homeService.messageInfo().then(function(result){
  697. $scope.infos = result.data.data;
  698. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  699. $scope.showMessage=0;
  700. }
  701. else {
  702. $scope.showMessage=1;
  703. }
  704. },function(error){
  705. });
  706. });
  707. $scope.$on('$ionicView.leave', function () {
  708. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  709. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  710. });
  711. $scope.toSort = function(){
  712. //$scope.type = 3;
  713. $scope.changeType(3)
  714. };
  715. $scope.load = function (id) {
  716. msg.loading();
  717. homeService.dreamDetail(id).then(function (result) {
  718. msg.hide();
  719. console.log(result);
  720. $scope.showCode = function(codeName){
  721. $scope.url = codeName;
  722. $scope.code = true;
  723. };
  724. $scope.hideCode = function(){
  725. $scope.code = false;
  726. };
  727. $scope.dream = result.data.data;
  728. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  729. $scope.codeBtn = true;
  730. }
  731. if($scope.dream.video){
  732. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  733. $scope.dream.video = config.imgServer+$scope.dream.video;
  734. }
  735. var reg = new RegExp("\n", "g");
  736. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  737. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  738. var date = new Date();
  739. var inter = (end_time.getTime() - date.getTime()) / 1000;
  740. leftTimer(inter);
  741. $scope.multi.a = $scope.dream.a;
  742. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  743. $scope.multi.c = $scope.dream.c;
  744. $scope.multi.promise = $scope.dream.a;
  745. var newtop3user = '' ;
  746. angular.forEach($scope.dream.top3user, function(user) {
  747. newtop3user= newtop3user +user.id+","
  748. });
  749. if(top3user!=''&&newtop3user!=top3user){
  750. //测试动画切换
  751. $timeout(function() {
  752. $scope.sort.slide1 = 'list-grow-animation';
  753. $scope.sort.slide2 = 'slide-in-both-ways';
  754. $scope.sort.slide3 = 'bounce-animation';
  755. }, 50);
  756. }
  757. top3user = newtop3user;
  758. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  759. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  760. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  761. $scope.calcmultiplier();
  762. }, function (error) {
  763. msg.hide();
  764. });
  765. };
  766. $scope.openSupport = function () {
  767. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  768. };
  769. $scope.multi = {
  770. a: '',
  771. b: '',
  772. c: '',
  773. result: 1,
  774. promise:null
  775. };
  776. $scope.type = 1;//tab切换
  777. $scope.tosupport = false;
  778. $scope.support = function ($event) {
  779. $event.stopPropagation();
  780. $scope.tosupport = true;
  781. $scope.vm.coin = 0;
  782. $scope.index = 0;
  783. };
  784. $scope.cancelSupport = function () {
  785. $scope.tosupport = false;
  786. $scope.toshare = false;
  787. $scope.input.show = false;
  788. };
  789. $scope.toshare = false;
  790. $scope.toRecharge = function(){
  791. $state.go("app.recharge")
  792. };
  793. $scope.share = function (type,$event) {
  794. $scope.toshare = true;
  795. if (type==0) {//分享给朋友
  796. /* Wechat.share({
  797. text: "分享的文字",
  798. scene: Wechat.Scene.SESSION // share to 好友
  799. }, function () {
  800. alert("Success");
  801. }, function (reason) {
  802. alert("Failed: " + reason);
  803. });*/
  804. Wechat.share({
  805. message: {
  806. title:"瞄瞄",
  807. description:"HELLO,这是我的梦想,快来围观吧!",
  808. thumb:"img/icon_cat_h.png",
  809. media: {
  810. type: Wechat.Type.WEBPAGE,
  811. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  812. }
  813. },
  814. scene: Wechat.Scene.SESSION
  815. }, function () {
  816. alert("Success");
  817. }, function (reason) {
  818. alert("Failed: " + reason);
  819. });
  820. }
  821. if(type==1){
  822. Wechat.share({
  823. message: {
  824. title:"瞄瞄",
  825. description:"HELLO,这是我的梦想,快来围观吧!",
  826. thumb:"img/icon_cat_h.png",
  827. media: {
  828. type: Wechat.Type.WEBPAGE,
  829. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  830. }
  831. },
  832. scene: Wechat.Scene.TIMELINE
  833. }, function () {
  834. alert("Success");
  835. }, function (reason) {
  836. alert("Failed: " + reason);
  837. });
  838. }
  839. // $state.go("app.shareDream",{item:$scope.dream});
  840. };
  841. //实时排行
  842. $scope.sort = {
  843. slide: ''
  844. };
  845. $scope.changeType = function (type) {
  846. $ionicScrollDelegate.scrollTop(true);
  847. $scope.type = type;
  848. };
  849. $scope.index = 0;
  850. $scope.vm = {
  851. coin:"",
  852. title:""
  853. };
  854. $scope.timer = '';
  855. var leftTimer = function (countDown) {
  856. if (isNaN(countDown)) {
  857. $scope.timer = '已结束';
  858. return;
  859. }
  860. var day=parseInt(countDown/(24*60*60));
  861. var h=parseInt(countDown/(60*60)%24);
  862. var m=parseInt(countDown/60%60);
  863. var s=parseInt(countDown%60);
  864. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  865. if(day>0) $scope.timer = day+'天';
  866. if(day<0 && h>0) $scope.timer = h+'小时';
  867. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  868. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  869. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  870. $scope.leftTimer = $interval(function () {
  871. if (countDown >= 1) leftTimer(countDown - 1);
  872. },1000);*/
  873. /*if(countDown<=0){
  874. $scope.timer='结束';
  875. }*/
  876. };
  877. $scope.changeIndex = function (index) {
  878. $scope.index = index;
  879. $scope.vm.coin = index*10;
  880. };
  881. $scope.vidEnded = function () {
  882. alert('播放完毕');
  883. };
  884. //实时计算支持乘数
  885. $scope.calcmultiplier = function () {
  886. $scope.multi.promise = $interval(function () {
  887. var date = new Date();
  888. var inter = date.getTime() - $scope.multi.b.getTime();
  889. var minutes = Math.floor(inter / (60 * 1000));
  890. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  891. if (number<=1) {
  892. number = 1;
  893. }
  894. //$scope.multi.result = Math.round(number * 100) / 100;
  895. $scope.multi.result = Math.round(number * 100 / 100);
  896. },1000);
  897. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  898. };
  899. $scope.supportDream = function (data) {
  900. if(!$scope.vm.coin){
  901. msg.error("请选择梦想币数量!");
  902. return ;
  903. }
  904. var data = {
  905. id:id,
  906. coin:$scope.vm.coin
  907. };
  908. homeService.supportDream(data).then(function(result){
  909. $scope.tosupport = false;
  910. $scope.load(id);
  911. homeService.myInfo().then(function(result){
  912. $scope.user = result.data.data;
  913. });
  914. $interval.cancel($scope.multi.promise);
  915. msg.text("发送成功");
  916. })
  917. };
  918. $scope.collectionDream = function(is_collection){
  919. homeService.collectionDream(id,is_collection).then(function(result){
  920. $scope.dream.is_collection=result.data.data;
  921. })
  922. };
  923. $scope.add = function(is_collection){
  924. var data = {
  925. id:id,
  926. title:$scope.vm.title,
  927. pics:$scope.imgs,
  928. video:$scope.video.server
  929. };
  930. homeService.add_interaction(data).then(function(){
  931. $scope.load(id);
  932. $scope.closeModal();
  933. })
  934. };
  935. $scope.showAbout = true;
  936. $scope.hideAbout = false;
  937. $scope.showText = function(){
  938. $scope.aboutStyle = {
  939. "white-space" : "normal"
  940. };
  941. $scope.showAbout = false;
  942. $scope.hideAbout = true;
  943. };
  944. $scope.hideText = function(){
  945. $scope.aboutStyle = {
  946. "white-space" : "nowrap"
  947. };
  948. $scope.showAbout = true;
  949. $scope.hideAbout = false;
  950. };
  951. $scope.input = {
  952. placeholder: '评论',
  953. focus: false,
  954. show:false
  955. };
  956. $scope.replay = function ($event, name) {
  957. $event.stopPropagation();
  958. $scope.input.focus = true;
  959. $scope.input.show = true;
  960. $scope.input.placeholder = "评论" + name+":";
  961. $scope.vm.title='';
  962. };
  963. $scope.submitComment = function (index) {
  964. var interaction = $scope.dream.interactions[index];
  965. var iid = interaction.id;
  966. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  967. $scope.input.focus = true;
  968. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  969. var data = {
  970. id:iid,
  971. content:$scope.vm.comment
  972. };
  973. console.log($scope.vm.comment+" "+iid);
  974. homeService.add_comment(data).then(function(){
  975. $scope.vm.comment = '' ;
  976. $scope.load(id);
  977. $scope.closeModal();
  978. })
  979. };
  980. $scope.bigImage = false;
  981. $scope.showBigImage = function ($event,imageName) {
  982. $event.stopPropagation();
  983. $scope.url = imageName;
  984. $scope.bigImage = true;
  985. };
  986. $scope.hideBigImage = function(){
  987. $scope.bigImage = false;
  988. };
  989. $ionicModal.fromTemplateUrl('qrCode.html', {
  990. scope: $scope,
  991. animation: 'slide-in-up'
  992. }).then(function(modal) {
  993. $scope.qrCodemodal = modal;
  994. });
  995. $ionicModal.fromTemplateUrl('commentPic.html', {
  996. scope: $scope,
  997. animation: 'slide-in-up'
  998. }).then(function(modal) {
  999. $scope.CommentPicmodal = modal;
  1000. });
  1001. $scope.openCode = function() {
  1002. $scope.qrCodemodal.show();
  1003. };
  1004. $scope.closeCode = function() {
  1005. $scope.qrCodemodal.hide();
  1006. };
  1007. $ionicModal.fromTemplateUrl('commentPic.html', {
  1008. scope: $scope,
  1009. animation: 'slide-in-up'
  1010. }).then(function(modal) {
  1011. $scope.CommentPicmodal = modal;
  1012. });
  1013. $scope.openCommentPic = function(pic) {
  1014. $scope.CommentPicmodal.show();
  1015. $scope.commentPicUrl = pic;
  1016. };
  1017. $scope.closeCommentPic = function() {
  1018. $scope.CommentPicmodal.hide();
  1019. };
  1020. $scope.addpict = function () {
  1021. common.chooseImage().then(function (img) {
  1022. common.uploadFiles(img,1).then(function (result) {
  1023. var response = JSON.parse(result.response);
  1024. var file = response.data.file;
  1025. $scope.imgs.push(config.imgServer+file);
  1026. console.log(JSON.stringify(config.imgServer+file));
  1027. }, function (error) {
  1028. msg.error('图片上传失败');
  1029. });
  1030. }, function (error) {
  1031. console.log('图片选择失败');
  1032. });
  1033. };
  1034. $scope.deletefile = function (file) {
  1035. var index = $scope.imgs.indexOf(file);
  1036. $scope.imgs.splice(index, 1);
  1037. common.deletefile(file).then(function () {
  1038. })
  1039. };
  1040. $scope.addvideo = function () {
  1041. common.chooseVideo().then(function (file) {
  1042. common.uploadFiles(file, 2).then(function (result) {
  1043. var response = JSON.parse(result.response);
  1044. $scope.video.server = response.data.file;
  1045. var file = config.imgServer+response.data.file;
  1046. console.log("file:"+file);
  1047. $scope.video.isOK = true;
  1048. $scope.video.file = file;
  1049. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  1050. console.log("vpic:"+$scope.video.vpic);
  1051. }, function (error) {
  1052. msg.error('视频上传失败');
  1053. });
  1054. }, function (erro) {
  1055. console.log('选择视频失败');
  1056. });
  1057. };
  1058. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  1059. scope: $scope,
  1060. animation: 'slide-in-up'
  1061. }).then(function(modal) {
  1062. $scope.rechagemodal = modal;
  1063. });
  1064. $scope.openRechargeModal = function() {
  1065. $scope.rechagemodal.show();
  1066. $scope.vm.money = '';
  1067. };
  1068. $scope.closeRechargeModal = function() {
  1069. $scope.rechagemodal.hide();
  1070. };
  1071. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  1072. scope: $scope,
  1073. animation: 'slide-in-up'
  1074. }).then(function(modal) {
  1075. $scope.modal = modal;
  1076. });
  1077. $scope.openModal = function() {
  1078. $scope.modal.show();
  1079. $scope.vm.title = '';
  1080. $scope.imgs = [];
  1081. $scope.video = {};
  1082. };
  1083. $scope.closeModal = function() {
  1084. $scope.modal.hide();
  1085. };
  1086. //当我们用到模型时,清除它!
  1087. $scope.$on('$destroy', function() {
  1088. $scope.modal.remove();
  1089. });
  1090. $scope.toMessage = function(){
  1091. $state.go("app.my_message");
  1092. }
  1093. }]);
  1094. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  1095. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  1096. var id = $stateParams.id;
  1097. $scope.items = $stateParams.items;
  1098. $scope.$on('$ionicView.beforeEnter', function () {
  1099. $ionicTabsDelegate.showBar(false);
  1100. });
  1101. $scope.attentionUser = function(is_care){
  1102. homeService.attentionUser(id,is_care).then(function(result){
  1103. $scope.items.is_care=result.data.data;
  1104. })
  1105. };
  1106. $scope.next = function (type) {
  1107. //type:1 前一个,type:2 后一个
  1108. if($scope.items.imgs.length>0){
  1109. if(type==1)
  1110. {
  1111. var temp= $scope.items.imgs.splice(0,1);
  1112. $scope.items.imgs.push(temp[0]);
  1113. }
  1114. if (type==2){
  1115. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  1116. $scope.items.imgs.unshift(temp[0]);
  1117. }
  1118. }
  1119. };
  1120. $scope.bigImage = false;
  1121. $scope.showBigImage = function(imageName){
  1122. $scope.url = imageName;
  1123. $scope.bigImage = true;
  1124. };
  1125. $scope.hideBigImage = function(){
  1126. $scope.bigImage = false;
  1127. };
  1128. $scope.cancelSupport = function () {
  1129. $scope.tosupport = false;
  1130. $scope.toshare = false;
  1131. };
  1132. $scope.toshare = false;
  1133. $scope.toshare = false;
  1134. $scope.toRecharge = function(){
  1135. $state.go("app.recharge")
  1136. };
  1137. $scope.share = function (type,$event) {
  1138. $scope.toshare = true;
  1139. if (type==0) {//分享给朋友
  1140. /* Wechat.share({
  1141. text: "分享的文字",
  1142. scene: Wechat.Scene.SESSION // share to 好友
  1143. }, function () {
  1144. alert("Success");
  1145. }, function (reason) {
  1146. alert("Failed: " + reason);
  1147. });*/
  1148. Wechat.share({
  1149. message: {
  1150. title:"瞄瞄",
  1151. description:"HELLO,这是我的个人资料,快来围观吧!",
  1152. thumb:"img/icon_cat_h.png",
  1153. media: {
  1154. type: Wechat.Type.WEBPAGE,
  1155. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  1156. }
  1157. },
  1158. scene: Wechat.Scene.SESSION
  1159. }, function () {
  1160. alert("Success");
  1161. }, function (reason) {
  1162. alert("Failed: " + reason);
  1163. });
  1164. }
  1165. if(type==1){
  1166. Wechat.share({
  1167. message: {
  1168. title:"瞄瞄",
  1169. description:"HELLO,这是我的个人资料,快来围观吧!",
  1170. thumb:"img/icon_cat_h.png",
  1171. media: {
  1172. type: Wechat.Type.WEBPAGE,
  1173. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  1174. }
  1175. },
  1176. scene: Wechat.Scene.TIMELINE
  1177. }, function () {
  1178. alert("Success");
  1179. }, function (reason) {
  1180. alert("Failed: " + reason);
  1181. });
  1182. }
  1183. // $state.go("app.shareDream",{item:$scope.dream});
  1184. };
  1185. $scope.toDetail = function (dream_id) {
  1186. if($scope.items.near_dream==null){
  1187. msg.alert("当前梦想","该用户没有当前梦想");
  1188. }
  1189. if($scope.items.near_dream!=null){
  1190. var dream_id = $scope.items.near_dream.id;
  1191. $state.go('app.home_dreamdetail',{id:dream_id});
  1192. }
  1193. };
  1194. $scope.toOldDream = function(){
  1195. if($scope.items.dreams.length<2){
  1196. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  1197. }
  1198. if($scope.items.dreams.length>1){
  1199. $state.go("app.oldDream",{user_id:$scope.items.user.id});
  1200. }
  1201. };
  1202. $scope.toSupportDream = function(){
  1203. if($scope.items.sup_dreams.length==0){
  1204. msg.alert("支持的梦想","该用户没有支持的梦想");
  1205. }
  1206. if($scope.items.sup_dreams.length!=0){
  1207. $state.go("app.supportDream",{user_id:$scope.items.user.id});
  1208. }
  1209. };
  1210. $scope.collectionDream = function(is_collection){
  1211. homeService.collectionDream(id,is_collection).then(function(result){
  1212. $scope.user.is_collection=result.data.data;
  1213. })
  1214. };
  1215. }]);
  1216. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  1217. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  1218. $scope.$on('$ionicView.beforeEnter', function () {
  1219. $ionicTabsDelegate.showBar(false);
  1220. myService.collect().then(function(result){
  1221. $scope.dreams = result.data.data.dreams;
  1222. });
  1223. });
  1224. $scope.toDetail = function (id) {
  1225. $state.go('app.home_dreamdetail',{id:id});
  1226. };
  1227. }]);
  1228. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1229. , function ($scope,homeService,$stateParams, $state, msg) {
  1230. $scope.dream = $stateParams.item;
  1231. $scope.showAbout = true;
  1232. $scope.hideAbout = false;
  1233. $scope.showText = function(){
  1234. $scope.aboutStyle = {
  1235. "white-space" : "normal"
  1236. };
  1237. $scope.showAbout = false;
  1238. $scope.hideAbout = true;
  1239. };
  1240. $scope.hideText = function(){
  1241. $scope.aboutStyle = {
  1242. "white-space" : "nowrap"
  1243. };
  1244. $scope.showAbout = true;
  1245. $scope.hideAbout = false;
  1246. };
  1247. }]);
  1248. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  1249. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  1250. $scope.$on('$ionicView.beforeEnter', function () {
  1251. $ionicTabsDelegate.showBar(false);
  1252. myService.messageInfo().then(function(result){
  1253. $scope.infos = result.data.data;
  1254. },function(error){
  1255. });
  1256. });
  1257. $scope.notRead = function(){
  1258. myService.notRead().then(function(result){
  1259. myService.messageInfo().then(function(result){
  1260. $scope.infos = result.data.data;
  1261. },function(error){
  1262. });
  1263. },function(error){
  1264. })
  1265. };
  1266. //系统消息
  1267. $scope.systemInfo = function(){
  1268. $state.go("app.message_sys");
  1269. myService.systemInfo().then(function(result){
  1270. },function(error){
  1271. });
  1272. };
  1273. //回复我的
  1274. $scope.replyMy = function(){
  1275. $state.go("app.message_reply");
  1276. myService.replyMy().then(function(result){
  1277. },function(error){
  1278. });
  1279. };
  1280. $scope.personalLetter = function(){
  1281. $state.go("app.letter");
  1282. }
  1283. }]);
  1284. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1285. , function ($scope,homeService,$stateParams, $state, msg) {
  1286. var user_id = $stateParams.user_id;
  1287. $scope.$on('$ionicView.beforeEnter',function(){
  1288. $scope.toUserDetail(user_id);
  1289. });
  1290. $scope.toUserDetail = function(user_id){
  1291. homeService.toUserDetail(user_id).then(function(result){
  1292. $scope.items = result.data.data;
  1293. $scope.user = result.data.data.user;
  1294. $scope.dreams = $scope.user.dreams;
  1295. },function(error){
  1296. })
  1297. };
  1298. $scope.toDetail = function(){
  1299. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1300. };
  1301. }]);
  1302. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1303. , function ($scope,homeService,$stateParams, $state, msg) {
  1304. var user_id = $stateParams.user_id;
  1305. $scope.$on('$ionicView.beforeEnter',function(){
  1306. $scope.toUserDetail(user_id);
  1307. });
  1308. $scope.toUserDetail = function(user_id){
  1309. homeService.toUserDetail(user_id).then(function(result){
  1310. $scope.items = result.data.data;
  1311. $scope.user = result.data.data.user;
  1312. $scope.dreams = $scope.user.sup_dream;
  1313. },function(error){
  1314. })
  1315. };
  1316. $scope.toDetail = function(){
  1317. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1318. }
  1319. }]);
  1320. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1321. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1322. $scope.showMore = function (keyword,index) {
  1323. if(!keyword)return;
  1324. $scope.index = index;
  1325. $scope.search(keyword);
  1326. };
  1327. $scope.search = function (keyword) {
  1328. $scope.vm.keyword = keyword;
  1329. homeService.search(keyword).then(function(result){
  1330. $scope.isResult = true;
  1331. $scope.dream_infos = result.data.data.dream_infos;
  1332. $scope.user_infos = result.data.data.user_infos;
  1333. });
  1334. };
  1335. $scope.toUserDetail = function (id) {
  1336. homeService.toUserDetail(id).then(function(result){
  1337. $scope.items = result.data.data;
  1338. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1339. },function(error){
  1340. //msg.error(msg.data.error)
  1341. })
  1342. };
  1343. $scope.toDetail = function (id) {
  1344. $state.go('app.home_dreamdetail',{id:id});
  1345. };
  1346. $scope.$on('$ionicView.beforeEnter', function () {
  1347. $scope.isResult = false;
  1348. $scope.index = 0;
  1349. $scope.vm = {
  1350. keyword : ""
  1351. };
  1352. $ionicTabsDelegate.showBar(false);
  1353. // $ionicNavBarDelegate.showBackButton(false);
  1354. homeService.search('').then(function(result){
  1355. $scope.hot_searches = result.data.data.hot_searches;
  1356. $scope.history_searches = result.data.data.history_searches;
  1357. });
  1358. });
  1359. }]);
  1360. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1361. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1362. }]);
  1363. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1364. , function ($scope, $state, myService, msg) {
  1365. $scope.$on('$ionicView.beforeEnter', function () {
  1366. myService.myDream().then(function(result){
  1367. console.log(result.data.data);
  1368. $scope.dreams = result.data.data;
  1369. });
  1370. });
  1371. $scope.toDetail = function (id) {
  1372. $state.go('app.home_dreamdetail',{id:id});
  1373. };
  1374. }]);
  1375. })(angular.module('app.controllers'));