home.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  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", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
  170. , function ($scope, $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. homeService.myInfo().then(function(result){
  186. $scope.user = result.data.data;
  187. });
  188. homeService.messageInfo().then(function(result){
  189. $scope.infos = result.data.data;
  190. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  191. $scope.showMessage=0;
  192. }
  193. else {
  194. $scope.showMessage=1;
  195. }
  196. },function(error){
  197. });
  198. });
  199. $scope.$on('$ionicView.leave', function () {
  200. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  201. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  202. });
  203. $scope.toSort = function(){
  204. //$scope.type = 3;
  205. $scope.changeType(3)
  206. };
  207. $scope.load = function (id) {
  208. msg.loading();
  209. homeService.dreamDetail(id).then(function (result) {
  210. msg.hide();
  211. console.log(result);
  212. $scope.showCode = function(codeName){
  213. $scope.url = codeName;
  214. $scope.code = true;
  215. };
  216. $scope.hideCode = function(){
  217. $scope.code = false;
  218. };
  219. $scope.dream = result.data.data;
  220. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  221. $scope.codeBtn = true;
  222. }
  223. if($scope.dream.video){
  224. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  225. $scope.dream.video = config.imgServer+$scope.dream.video;
  226. }
  227. var reg = new RegExp("\n", "g");
  228. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  229. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  230. var date = new Date();
  231. var inter = (end_time.getTime() - date.getTime()) / 1000;
  232. leftTimer(inter);
  233. $scope.multi.a = $scope.dream.a;
  234. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  235. $scope.multi.c = $scope.dream.c;
  236. $scope.multi.promise = $scope.dream.a;
  237. var newtop3user = '' ;
  238. angular.forEach($scope.dream.top3user, function(user) {
  239. newtop3user= newtop3user +user.id+","
  240. });
  241. if(top3user!=''&&newtop3user!=top3user){
  242. //测试动画切换
  243. $timeout(function() {
  244. $scope.sort.slide1 = 'list-grow-animation';
  245. $scope.sort.slide2 = 'slide-in-both-ways';
  246. $scope.sort.slide3 = 'bounce-animation';
  247. }, 50);
  248. }
  249. top3user = newtop3user;
  250. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  251. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  252. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  253. $scope.calcmultiplier();
  254. }, function (error) {
  255. msg.hide();
  256. });
  257. };
  258. $scope.openSupport = function () {
  259. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  260. };
  261. $scope.multi = {
  262. a: '',
  263. b: '',
  264. c: '',
  265. result: 1,
  266. promise:null
  267. };
  268. $scope.type = 1;//tab切换
  269. $scope.tosupport = false;
  270. $scope.support = function ($event) {
  271. $event.stopPropagation();
  272. $scope.tosupport = true;
  273. $scope.vm.coin = 0;
  274. $scope.index = 0;
  275. };
  276. $scope.cancelSupport = function () {
  277. $scope.tosupport = false;
  278. $scope.toshare = false;
  279. $scope.input.show = false;
  280. };
  281. $scope.toshare = false;
  282. $scope.toRecharge = function(){
  283. $state.go("app.recharge")
  284. };
  285. $scope.share = function (type,$event) {
  286. $scope.toshare = true;
  287. if (type==0) {//分享给朋友
  288. /* Wechat.share({
  289. text: "分享的文字",
  290. scene: Wechat.Scene.SESSION // share to 好友
  291. }, function () {
  292. alert("Success");
  293. }, function (reason) {
  294. alert("Failed: " + reason);
  295. });*/
  296. Wechat.share({
  297. message: {
  298. title:"瞄瞄",
  299. description:"HELLO,这是我的梦想,快来围观吧!",
  300. thumb:"img/icon_cat_h.png",
  301. media: {
  302. type: Wechat.Type.WEBPAGE,
  303. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  304. }
  305. },
  306. scene: Wechat.Scene.SESSION
  307. }, function () {
  308. alert("Success");
  309. }, function (reason) {
  310. alert("Failed: " + reason);
  311. });
  312. }
  313. if(type==1){
  314. Wechat.share({
  315. message: {
  316. title:"瞄瞄",
  317. description:"HELLO,这是我的梦想,快来围观吧!",
  318. thumb:"img/icon_cat_h.png",
  319. media: {
  320. type: Wechat.Type.WEBPAGE,
  321. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  322. }
  323. },
  324. scene: Wechat.Scene.TIMELINE
  325. }, function () {
  326. alert("Success");
  327. }, function (reason) {
  328. alert("Failed: " + reason);
  329. });
  330. }
  331. // $state.go("app.shareDream",{item:$scope.dream});
  332. };
  333. //实时排行
  334. $scope.sort = {
  335. slide: ''
  336. };
  337. $scope.changeType = function (type) {
  338. $ionicScrollDelegate.scrollTop(true);
  339. $scope.type = type;
  340. };
  341. $scope.index = 0;
  342. $scope.vm = {
  343. coin:"",
  344. title:""
  345. };
  346. $scope.timer = '';
  347. var leftTimer = function (countDown) {
  348. if (isNaN(countDown)) {
  349. $scope.timer = '已结束';
  350. return;
  351. }
  352. var day=parseInt(countDown/(24*60*60));
  353. var h=parseInt(countDown/(60*60)%24);
  354. var m=parseInt(countDown/60%60);
  355. var s=parseInt(countDown%60);
  356. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  357. if(day>0) $scope.timer = day+'天';
  358. if(day<0 && h>0) $scope.timer = h+'小时';
  359. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  360. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  361. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  362. $scope.leftTimer = $interval(function () {
  363. if (countDown >= 1) leftTimer(countDown - 1);
  364. },1000);*/
  365. /*if(countDown<=0){
  366. $scope.timer='结束';
  367. }*/
  368. };
  369. $scope.changeIndex = function (index) {
  370. $scope.index = index;
  371. $scope.vm.coin = index*10;
  372. };
  373. $scope.vidEnded = function () {
  374. alert('播放完毕');
  375. };
  376. //实时计算支持乘数
  377. $scope.calcmultiplier = function () {
  378. $scope.multi.promise = $interval(function () {
  379. var date = new Date();
  380. var inter = date.getTime() - $scope.multi.b.getTime();
  381. var minutes = Math.floor(inter / (60 * 1000));
  382. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  383. if (number<=1) {
  384. number = 1;
  385. }
  386. //$scope.multi.result = Math.round(number * 100) / 100;
  387. $scope.multi.result = Math.round(number * 100 / 100);
  388. },1000);
  389. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  390. };
  391. $scope.supportDream = function (data) {
  392. if(!$scope.vm.coin){
  393. msg.error("请选择梦想币数量!");
  394. return ;
  395. }
  396. var data = {
  397. id:id,
  398. coin:$scope.vm.coin
  399. };
  400. homeService.supportDream(data).then(function(result){
  401. $scope.tosupport = false;
  402. $scope.load(id);
  403. homeService.myInfo().then(function(result){
  404. $scope.user = result.data.data;
  405. });
  406. $interval.cancel($scope.multi.promise);
  407. msg.text("发送成功");
  408. })
  409. };
  410. $scope.collectionDream = function(is_collection){
  411. homeService.collectionDream(id,is_collection).then(function(result){
  412. $scope.dream.is_collection=result.data.data;
  413. })
  414. };
  415. $scope.add = function(is_collection){
  416. var data = {
  417. id:id,
  418. title:$scope.vm.title,
  419. pics:$scope.imgs,
  420. video:$scope.video.server
  421. };
  422. homeService.add_interaction(data).then(function(){
  423. $scope.load(id);
  424. $scope.closeModal();
  425. })
  426. };
  427. $scope.showAbout = true;
  428. $scope.hideAbout = false;
  429. $scope.showText = function(){
  430. $scope.aboutStyle = {
  431. "white-space" : "normal"
  432. };
  433. $scope.showAbout = false;
  434. $scope.hideAbout = true;
  435. };
  436. $scope.hideText = function(){
  437. $scope.aboutStyle = {
  438. "white-space" : "nowrap"
  439. };
  440. $scope.showAbout = true;
  441. $scope.hideAbout = false;
  442. };
  443. $scope.input = {
  444. placeholder: '评论',
  445. focus: false,
  446. show:false
  447. };
  448. $scope.showmore = function (index) {
  449. if ($scope.dream.interactions[index].showmore) {
  450. $scope.dream.interactions[index].showmore = false;
  451. } else {
  452. $scope.dream.interactions[index].showmore = true;
  453. }
  454. }
  455. $scope.replay = function ($event, name, index,currentindex) {
  456. $event.stopPropagation();
  457. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  458. $scope.input.focus = true;
  459. $scope.input.show = true;
  460. angular.forEach($scope.dream.interactions, function (item) {
  461. item.show = false;
  462. })
  463. $scope.dream.interactions[index].show = true;
  464. $scope.input.placeholder = "评论" + name+":";
  465. $scope.vm.title='';
  466. }
  467. else {
  468. msg.confirm("评论","是否删除评论");
  469. }
  470. };
  471. $scope.submitComment = function (index) {
  472. var interaction = $scope.dream.interactions[index];
  473. var iid = interaction.id;
  474. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  475. $scope.input.focus = true;
  476. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  477. var data = {
  478. id:iid,
  479. content:$scope.vm.comment
  480. };
  481. console.log($scope.vm.comment+" "+iid);
  482. homeService.add_comment(data).then(function(){
  483. $scope.vm.comment = '' ;
  484. $scope.load(id);
  485. $scope.closeModal();
  486. })
  487. };
  488. $scope.bigImage = false;
  489. $scope.showBigImage = function ($event, imageName) {
  490. $event.stopPropagation();
  491. $scope.url = imageName;
  492. $scope.bigImage = true;
  493. };
  494. $scope.hideBigImage = function(){
  495. $scope.bigImage = false;
  496. };
  497. $ionicModal.fromTemplateUrl('qrCode.html', {
  498. scope: $scope,
  499. animation: 'slide-in-up'
  500. }).then(function(modal) {
  501. $scope.qrCodemodal = modal;
  502. });
  503. $scope.openCode = function() {
  504. $scope.qrCodemodal.show();
  505. $scope.vm.money = '';
  506. };
  507. $scope.closeCode = function() {
  508. $scope.qrCodemodal.hide();
  509. };
  510. $ionicModal.fromTemplateUrl('commentPic.html', {
  511. scope: $scope,
  512. animation: 'slide-in-up'
  513. }).then(function(modal) {
  514. $scope.CommentPicmodal = modal;
  515. });
  516. $scope.openCommentPic = function(pic) {
  517. $scope.CommentPicmodal.show();
  518. $scope.commentPicUrl = pic;
  519. };
  520. $scope.closeCommentPic = function() {
  521. $scope.CommentPicmodal.hide();
  522. };
  523. $scope.addpict = function () {
  524. common.chooseImage().then(function (img) {
  525. common.uploadFiles(img,1).then(function (result) {
  526. var response = JSON.parse(result.response);
  527. var file = response.data.file;
  528. $scope.imgs.push(config.imgServer+file);
  529. console.log(JSON.stringify(config.imgServer+file));
  530. }, function (error) {
  531. msg.error('图片上传失败');
  532. });
  533. }, function (error) {
  534. console.log('图片选择失败');
  535. });
  536. };
  537. $scope.deletefile = function (file) {
  538. var index = $scope.imgs.indexOf(file);
  539. $scope.imgs.splice(index, 1);
  540. common.deletefile(file).then(function () {
  541. })
  542. };
  543. $scope.addvideo = function () {
  544. common.chooseVideo().then(function (file) {
  545. common.uploadFiles(file, 2).then(function (result) {
  546. var response = JSON.parse(result.response);
  547. $scope.video.server = response.data.file;
  548. var file = config.imgServer+response.data.file;
  549. console.log("file:"+file);
  550. $scope.video.isOK = true;
  551. $scope.video.file = file;
  552. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  553. console.log("vpic:"+$scope.video.vpic);
  554. }, function (error) {
  555. msg.error('视频上传失败');
  556. });
  557. }, function (erro) {
  558. console.log('选择视频失败');
  559. });
  560. };
  561. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  562. scope: $scope,
  563. animation: 'slide-in-up'
  564. }).then(function(modal) {
  565. $scope.rechagemodal = modal;
  566. });
  567. $scope.openRechargeModal = function() {
  568. $scope.rechagemodal.show();
  569. $scope.vm.money = '';
  570. };
  571. $scope.closeRechargeModal = function() {
  572. $scope.rechagemodal.hide();
  573. };
  574. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  575. scope: $scope,
  576. animation: 'slide-in-up'
  577. }).then(function(modal) {
  578. $scope.modal = modal;
  579. });
  580. $scope.openModal = function() {
  581. $scope.modal.show();
  582. $scope.vm.title = '';
  583. $scope.imgs = [];
  584. $scope.video = {};
  585. };
  586. $scope.closeModal = function() {
  587. $scope.modal.hide();
  588. };
  589. //当我们用到模型时,清除它!
  590. $scope.$on('$destroy', function() {
  591. $scope.modal.remove();
  592. });
  593. $scope.toMessage = function(){
  594. $state.go("app.message");
  595. }
  596. }]);
  597. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  598. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  599. var id = $stateParams.id;
  600. var top3user = '';
  601. $scope.chosedIndex = 0;
  602. $scope.clickAvatar = function(index){
  603. $scope.chosedIndex = index;
  604. homeService.myInfo().then(function(result){
  605. $scope.user = result.data.data;
  606. });
  607. };
  608. // id=5;
  609. $scope.$on('$ionicView.beforeEnter', function () {
  610. $ionicTabsDelegate.showBar(false);
  611. $scope.load(id);
  612. $scope.thisUser = storage.getObject('user');
  613. homeService.myInfo().then(function(result){
  614. $scope.user = result.data.data;
  615. });
  616. homeService.messageInfo().then(function(result){
  617. $scope.infos = result.data.data;
  618. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  619. $scope.showMessage=0;
  620. }
  621. else {
  622. $scope.showMessage=1;
  623. }
  624. },function(error){
  625. });
  626. });
  627. $scope.$on('$ionicView.leave', function () {
  628. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  629. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  630. });
  631. $scope.toSort = function(){
  632. //$scope.type = 3;
  633. $scope.changeType(3)
  634. };
  635. $scope.load = function (id) {
  636. msg.loading();
  637. homeService.dreamDetail(id).then(function (result) {
  638. msg.hide();
  639. console.log(result);
  640. $scope.showCode = function(codeName){
  641. $scope.url = codeName;
  642. $scope.code = true;
  643. };
  644. $scope.hideCode = function(){
  645. $scope.code = false;
  646. };
  647. $scope.dream = result.data.data;
  648. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  649. $scope.codeBtn = true;
  650. }
  651. if($scope.dream.video){
  652. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  653. $scope.dream.video = config.imgServer+$scope.dream.video;
  654. }
  655. var reg = new RegExp("\n", "g");
  656. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  657. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  658. var date = new Date();
  659. var inter = (end_time.getTime() - date.getTime()) / 1000;
  660. leftTimer(inter);
  661. $scope.multi.a = $scope.dream.a;
  662. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  663. $scope.multi.c = $scope.dream.c;
  664. $scope.multi.promise = $scope.dream.a;
  665. var newtop3user = '' ;
  666. angular.forEach($scope.dream.top3user, function(user) {
  667. newtop3user= newtop3user +user.id+","
  668. });
  669. if(top3user!=''&&newtop3user!=top3user){
  670. //测试动画切换
  671. $timeout(function() {
  672. $scope.sort.slide1 = 'list-grow-animation';
  673. $scope.sort.slide2 = 'slide-in-both-ways';
  674. $scope.sort.slide3 = 'bounce-animation';
  675. }, 50);
  676. }
  677. top3user = newtop3user;
  678. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  679. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  680. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  681. $scope.calcmultiplier();
  682. }, function (error) {
  683. msg.hide();
  684. });
  685. };
  686. $scope.openSupport = function () {
  687. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  688. };
  689. $scope.multi = {
  690. a: '',
  691. b: '',
  692. c: '',
  693. result: 1,
  694. promise:null
  695. };
  696. $scope.type = 1;//tab切换
  697. $scope.tosupport = false;
  698. $scope.support = function ($event) {
  699. $event.stopPropagation();
  700. $scope.tosupport = true;
  701. $scope.vm.coin = 0;
  702. $scope.index = 0;
  703. };
  704. $scope.cancelSupport = function () {
  705. $scope.tosupport = false;
  706. $scope.toshare = false;
  707. $scope.input.show = false;
  708. };
  709. $scope.toshare = false;
  710. $scope.toRecharge = function(){
  711. $state.go("app.recharge")
  712. };
  713. $scope.share = function (type,$event) {
  714. $scope.toshare = true;
  715. if (type==0) {//分享给朋友
  716. /* Wechat.share({
  717. text: "分享的文字",
  718. scene: Wechat.Scene.SESSION // share to 好友
  719. }, function () {
  720. alert("Success");
  721. }, function (reason) {
  722. alert("Failed: " + reason);
  723. });*/
  724. Wechat.share({
  725. message: {
  726. title:"瞄瞄",
  727. description:"HELLO,这是我的梦想,快来围观吧!",
  728. thumb:"img/icon_cat_h.png",
  729. media: {
  730. type: Wechat.Type.WEBPAGE,
  731. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  732. }
  733. },
  734. scene: Wechat.Scene.SESSION
  735. }, function () {
  736. alert("Success");
  737. }, function (reason) {
  738. alert("Failed: " + reason);
  739. });
  740. }
  741. if(type==1){
  742. Wechat.share({
  743. message: {
  744. title:"瞄瞄",
  745. description:"HELLO,这是我的梦想,快来围观吧!",
  746. thumb:"img/icon_cat_h.png",
  747. media: {
  748. type: Wechat.Type.WEBPAGE,
  749. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  750. }
  751. },
  752. scene: Wechat.Scene.TIMELINE
  753. }, function () {
  754. alert("Success");
  755. }, function (reason) {
  756. alert("Failed: " + reason);
  757. });
  758. }
  759. // $state.go("app.shareDream",{item:$scope.dream});
  760. };
  761. //实时排行
  762. $scope.sort = {
  763. slide: ''
  764. };
  765. $scope.changeType = function (type) {
  766. $ionicScrollDelegate.scrollTop(true);
  767. $scope.type = type;
  768. };
  769. $scope.index = 0;
  770. $scope.vm = {
  771. coin:"",
  772. title:""
  773. };
  774. $scope.timer = '';
  775. var leftTimer = function (countDown) {
  776. if (isNaN(countDown)) {
  777. $scope.timer = '已结束';
  778. return;
  779. }
  780. var day=parseInt(countDown/(24*60*60));
  781. var h=parseInt(countDown/(60*60)%24);
  782. var m=parseInt(countDown/60%60);
  783. var s=parseInt(countDown%60);
  784. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  785. if(day>0) $scope.timer = day+'天';
  786. if(day<0 && h>0) $scope.timer = h+'小时';
  787. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  788. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  789. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  790. $scope.leftTimer = $interval(function () {
  791. if (countDown >= 1) leftTimer(countDown - 1);
  792. },1000);*/
  793. /*if(countDown<=0){
  794. $scope.timer='结束';
  795. }*/
  796. };
  797. $scope.changeIndex = function (index) {
  798. $scope.index = index;
  799. $scope.vm.coin = index*10;
  800. };
  801. $scope.vidEnded = function () {
  802. alert('播放完毕');
  803. };
  804. //实时计算支持乘数
  805. $scope.calcmultiplier = function () {
  806. $scope.multi.promise = $interval(function () {
  807. var date = new Date();
  808. var inter = date.getTime() - $scope.multi.b.getTime();
  809. var minutes = Math.floor(inter / (60 * 1000));
  810. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  811. if (number<=1) {
  812. number = 1;
  813. }
  814. //$scope.multi.result = Math.round(number * 100) / 100;
  815. $scope.multi.result = Math.round(number * 100 / 100);
  816. },1000);
  817. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  818. };
  819. $scope.supportDream = function (data) {
  820. if(!$scope.vm.coin){
  821. msg.error("请选择梦想币数量!");
  822. return ;
  823. }
  824. var data = {
  825. id:id,
  826. coin:$scope.vm.coin
  827. };
  828. homeService.supportDream(data).then(function(result){
  829. $scope.tosupport = false;
  830. $scope.load(id);
  831. homeService.myInfo().then(function(result){
  832. $scope.user = result.data.data;
  833. });
  834. $interval.cancel($scope.multi.promise);
  835. msg.text("发送成功");
  836. })
  837. };
  838. $scope.collectionDream = function(is_collection){
  839. homeService.collectionDream(id,is_collection).then(function(result){
  840. $scope.dream.is_collection=result.data.data;
  841. })
  842. };
  843. $scope.add = function(is_collection){
  844. var data = {
  845. id:id,
  846. title:$scope.vm.title,
  847. pics:$scope.imgs,
  848. video:$scope.video.server
  849. };
  850. homeService.add_interaction(data).then(function(){
  851. $scope.load(id);
  852. $scope.closeModal();
  853. })
  854. };
  855. $scope.showAbout = true;
  856. $scope.hideAbout = false;
  857. $scope.showText = function(){
  858. $scope.aboutStyle = {
  859. "white-space" : "normal"
  860. };
  861. $scope.showAbout = false;
  862. $scope.hideAbout = true;
  863. };
  864. $scope.hideText = function(){
  865. $scope.aboutStyle = {
  866. "white-space" : "nowrap"
  867. };
  868. $scope.showAbout = true;
  869. $scope.hideAbout = false;
  870. };
  871. $scope.input = {
  872. placeholder: '评论',
  873. focus: false,
  874. show:false
  875. };
  876. $scope.replay = function ($event, name) {
  877. $event.stopPropagation();
  878. $scope.input.focus = true;
  879. $scope.input.show = true;
  880. $scope.input.placeholder = "评论" + name+":";
  881. $scope.vm.title='';
  882. };
  883. $scope.submitComment = function (index) {
  884. var interaction = $scope.dream.interactions[index];
  885. var iid = interaction.id;
  886. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  887. $scope.input.focus = true;
  888. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  889. var data = {
  890. id:iid,
  891. content:$scope.vm.comment
  892. };
  893. console.log($scope.vm.comment+" "+iid);
  894. homeService.add_comment(data).then(function(){
  895. $scope.vm.comment = '' ;
  896. $scope.load(id);
  897. $scope.closeModal();
  898. })
  899. };
  900. $scope.bigImage = false;
  901. $scope.showBigImage = function ($event,imageName) {
  902. $event.stopPropagation();
  903. $scope.url = imageName;
  904. $scope.bigImage = true;
  905. };
  906. $scope.hideBigImage = function(){
  907. $scope.bigImage = false;
  908. };
  909. $ionicModal.fromTemplateUrl('qrCode.html', {
  910. scope: $scope,
  911. animation: 'slide-in-up'
  912. }).then(function(modal) {
  913. $scope.qrCodemodal = modal;
  914. });
  915. $ionicModal.fromTemplateUrl('commentPic.html', {
  916. scope: $scope,
  917. animation: 'slide-in-up'
  918. }).then(function(modal) {
  919. $scope.CommentPicmodal = modal;
  920. });
  921. $scope.openCode = function() {
  922. $scope.qrCodemodal.show();
  923. };
  924. $scope.closeCode = function() {
  925. $scope.qrCodemodal.hide();
  926. };
  927. $ionicModal.fromTemplateUrl('commentPic.html', {
  928. scope: $scope,
  929. animation: 'slide-in-up'
  930. }).then(function(modal) {
  931. $scope.CommentPicmodal = modal;
  932. });
  933. $scope.openCommentPic = function(pic) {
  934. $scope.CommentPicmodal.show();
  935. $scope.commentPicUrl = pic;
  936. };
  937. $scope.closeCommentPic = function() {
  938. $scope.CommentPicmodal.hide();
  939. };
  940. $scope.addpict = function () {
  941. common.chooseImage().then(function (img) {
  942. common.uploadFiles(img,1).then(function (result) {
  943. var response = JSON.parse(result.response);
  944. var file = response.data.file;
  945. $scope.imgs.push(config.imgServer+file);
  946. console.log(JSON.stringify(config.imgServer+file));
  947. }, function (error) {
  948. msg.error('图片上传失败');
  949. });
  950. }, function (error) {
  951. console.log('图片选择失败');
  952. });
  953. };
  954. $scope.deletefile = function (file) {
  955. var index = $scope.imgs.indexOf(file);
  956. $scope.imgs.splice(index, 1);
  957. common.deletefile(file).then(function () {
  958. })
  959. };
  960. $scope.addvideo = function () {
  961. common.chooseVideo().then(function (file) {
  962. common.uploadFiles(file, 2).then(function (result) {
  963. var response = JSON.parse(result.response);
  964. $scope.video.server = response.data.file;
  965. var file = config.imgServer+response.data.file;
  966. console.log("file:"+file);
  967. $scope.video.isOK = true;
  968. $scope.video.file = file;
  969. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  970. console.log("vpic:"+$scope.video.vpic);
  971. }, function (error) {
  972. msg.error('视频上传失败');
  973. });
  974. }, function (erro) {
  975. console.log('选择视频失败');
  976. });
  977. };
  978. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  979. scope: $scope,
  980. animation: 'slide-in-up'
  981. }).then(function(modal) {
  982. $scope.rechagemodal = modal;
  983. });
  984. $scope.openRechargeModal = function() {
  985. $scope.rechagemodal.show();
  986. $scope.vm.money = '';
  987. };
  988. $scope.closeRechargeModal = function() {
  989. $scope.rechagemodal.hide();
  990. };
  991. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  992. scope: $scope,
  993. animation: 'slide-in-up'
  994. }).then(function(modal) {
  995. $scope.modal = modal;
  996. });
  997. $scope.openModal = function() {
  998. $scope.modal.show();
  999. $scope.vm.title = '';
  1000. $scope.imgs = [];
  1001. $scope.video = {};
  1002. };
  1003. $scope.closeModal = function() {
  1004. $scope.modal.hide();
  1005. };
  1006. //当我们用到模型时,清除它!
  1007. $scope.$on('$destroy', function() {
  1008. $scope.modal.remove();
  1009. });
  1010. $scope.toMessage = function(){
  1011. $state.go("app.my_message");
  1012. }
  1013. }]);
  1014. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  1015. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  1016. var id = $stateParams.id;
  1017. $scope.items = $stateParams.items;
  1018. $scope.$on('$ionicView.beforeEnter', function () {
  1019. $ionicTabsDelegate.showBar(false);
  1020. });
  1021. $scope.attentionUser = function(is_care){
  1022. homeService.attentionUser(id,is_care).then(function(result){
  1023. $scope.items.is_care=result.data.data;
  1024. })
  1025. };
  1026. $scope.next = function (type) {
  1027. //type:1 前一个,type:2 后一个
  1028. if($scope.items.imgs.length>0){
  1029. if(type==1)
  1030. {
  1031. var temp= $scope.items.imgs.splice(0,1);
  1032. $scope.items.imgs.push(temp[0]);
  1033. }
  1034. if (type==2){
  1035. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  1036. $scope.items.imgs.unshift(temp[0]);
  1037. }
  1038. }
  1039. };
  1040. $scope.bigImage = false;
  1041. $scope.showBigImage = function(imageName){
  1042. $scope.url = imageName;
  1043. $scope.bigImage = true;
  1044. };
  1045. $scope.hideBigImage = function(){
  1046. $scope.bigImage = false;
  1047. };
  1048. $scope.cancelSupport = function () {
  1049. $scope.tosupport = false;
  1050. $scope.toshare = false;
  1051. };
  1052. $scope.toshare = false;
  1053. $scope.toshare = false;
  1054. $scope.toRecharge = function(){
  1055. $state.go("app.recharge")
  1056. };
  1057. $scope.share = function (type,$event) {
  1058. $scope.toshare = true;
  1059. if (type==0) {//分享给朋友
  1060. /* Wechat.share({
  1061. text: "分享的文字",
  1062. scene: Wechat.Scene.SESSION // share to 好友
  1063. }, function () {
  1064. alert("Success");
  1065. }, function (reason) {
  1066. alert("Failed: " + reason);
  1067. });*/
  1068. Wechat.share({
  1069. message: {
  1070. title:"瞄瞄",
  1071. description:"HELLO,这是我的个人资料,快来围观吧!",
  1072. thumb:"img/icon_cat_h.png",
  1073. media: {
  1074. type: Wechat.Type.WEBPAGE,
  1075. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  1076. }
  1077. },
  1078. scene: Wechat.Scene.SESSION
  1079. }, function () {
  1080. alert("Success");
  1081. }, function (reason) {
  1082. alert("Failed: " + reason);
  1083. });
  1084. }
  1085. if(type==1){
  1086. Wechat.share({
  1087. message: {
  1088. title:"瞄瞄",
  1089. description:"HELLO,这是我的个人资料,快来围观吧!",
  1090. thumb:"img/icon_cat_h.png",
  1091. media: {
  1092. type: Wechat.Type.WEBPAGE,
  1093. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  1094. }
  1095. },
  1096. scene: Wechat.Scene.TIMELINE
  1097. }, function () {
  1098. alert("Success");
  1099. }, function (reason) {
  1100. alert("Failed: " + reason);
  1101. });
  1102. }
  1103. // $state.go("app.shareDream",{item:$scope.dream});
  1104. };
  1105. $scope.toDetail = function (dream_id) {
  1106. if($scope.items.near_dream==null){
  1107. msg.alert("当前梦想","该用户没有当前梦想");
  1108. }
  1109. if($scope.items.near_dream!=null){
  1110. var dream_id = $scope.items.near_dream.id;
  1111. $state.go('app.home_dreamdetail',{id:dream_id});
  1112. }
  1113. };
  1114. $scope.toOldDream = function(){
  1115. if($scope.items.dreams.length<2){
  1116. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  1117. }
  1118. if($scope.items.dreams.length>1){
  1119. $state.go("app.oldDream",{user_id:$scope.items.user.id});
  1120. }
  1121. };
  1122. $scope.toSupportDream = function(){
  1123. if($scope.items.sup_dreams.length==0){
  1124. msg.alert("支持的梦想","该用户没有支持的梦想");
  1125. }
  1126. if($scope.items.sup_dreams.length!=0){
  1127. $state.go("app.supportDream",{user_id:$scope.items.user.id});
  1128. }
  1129. };
  1130. $scope.collectionDream = function(is_collection){
  1131. homeService.collectionDream(id,is_collection).then(function(result){
  1132. $scope.user.is_collection=result.data.data;
  1133. })
  1134. };
  1135. }]);
  1136. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  1137. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  1138. $scope.$on('$ionicView.beforeEnter', function () {
  1139. $ionicTabsDelegate.showBar(false);
  1140. myService.collect().then(function(result){
  1141. $scope.dreams = result.data.data.dreams;
  1142. });
  1143. });
  1144. $scope.toDetail = function (id) {
  1145. $state.go('app.home_dreamdetail',{id:id});
  1146. };
  1147. }]);
  1148. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1149. , function ($scope,homeService,$stateParams, $state, msg) {
  1150. $scope.dream = $stateParams.item;
  1151. $scope.showAbout = true;
  1152. $scope.hideAbout = false;
  1153. $scope.showText = function(){
  1154. $scope.aboutStyle = {
  1155. "white-space" : "normal"
  1156. };
  1157. $scope.showAbout = false;
  1158. $scope.hideAbout = true;
  1159. };
  1160. $scope.hideText = function(){
  1161. $scope.aboutStyle = {
  1162. "white-space" : "nowrap"
  1163. };
  1164. $scope.showAbout = true;
  1165. $scope.hideAbout = false;
  1166. };
  1167. }]);
  1168. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  1169. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  1170. $scope.$on('$ionicView.beforeEnter', function () {
  1171. $ionicTabsDelegate.showBar(false);
  1172. myService.messageInfo().then(function(result){
  1173. $scope.infos = result.data.data;
  1174. },function(error){
  1175. });
  1176. });
  1177. $scope.notRead = function(){
  1178. myService.notRead().then(function(result){
  1179. myService.messageInfo().then(function(result){
  1180. $scope.infos = result.data.data;
  1181. },function(error){
  1182. });
  1183. },function(error){
  1184. })
  1185. };
  1186. //系统消息
  1187. $scope.systemInfo = function(){
  1188. $state.go("app.message_sys");
  1189. myService.systemInfo().then(function(result){
  1190. },function(error){
  1191. });
  1192. };
  1193. //回复我的
  1194. $scope.replyMy = function(){
  1195. $state.go("app.message_reply");
  1196. myService.replyMy().then(function(result){
  1197. },function(error){
  1198. });
  1199. };
  1200. $scope.personalLetter = function(){
  1201. $state.go("app.letter");
  1202. }
  1203. }]);
  1204. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1205. , function ($scope,homeService,$stateParams, $state, msg) {
  1206. var user_id = $stateParams.user_id;
  1207. $scope.$on('$ionicView.beforeEnter',function(){
  1208. $scope.toUserDetail(user_id);
  1209. });
  1210. $scope.toUserDetail = function(user_id){
  1211. homeService.toUserDetail(user_id).then(function(result){
  1212. $scope.items = result.data.data;
  1213. $scope.user = result.data.data.user;
  1214. $scope.dreams = $scope.user.dreams;
  1215. },function(error){
  1216. })
  1217. };
  1218. $scope.toDetail = function(){
  1219. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1220. };
  1221. }]);
  1222. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1223. , function ($scope,homeService,$stateParams, $state, msg) {
  1224. var user_id = $stateParams.user_id;
  1225. $scope.$on('$ionicView.beforeEnter',function(){
  1226. $scope.toUserDetail(user_id);
  1227. });
  1228. $scope.toUserDetail = function(user_id){
  1229. homeService.toUserDetail(user_id).then(function(result){
  1230. $scope.items = result.data.data;
  1231. $scope.user = result.data.data.user;
  1232. $scope.dreams = $scope.user.sup_dream;
  1233. },function(error){
  1234. })
  1235. };
  1236. $scope.toDetail = function(){
  1237. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1238. }
  1239. }]);
  1240. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1241. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1242. $scope.showMore = function (keyword,index) {
  1243. if(!keyword)return;
  1244. $scope.index = index;
  1245. $scope.search(keyword);
  1246. };
  1247. $scope.search = function (keyword) {
  1248. $scope.vm.keyword = keyword;
  1249. homeService.search(keyword).then(function(result){
  1250. $scope.isResult = true;
  1251. $scope.dream_infos = result.data.data.dream_infos;
  1252. $scope.user_infos = result.data.data.user_infos;
  1253. });
  1254. };
  1255. $scope.toUserDetail = function (id) {
  1256. homeService.toUserDetail(id).then(function(result){
  1257. $scope.items = result.data.data;
  1258. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1259. },function(error){
  1260. //msg.error(msg.data.error)
  1261. })
  1262. };
  1263. $scope.toDetail = function (id) {
  1264. $state.go('app.home_dreamdetail',{id:id});
  1265. };
  1266. $scope.$on('$ionicView.beforeEnter', function () {
  1267. $scope.isResult = false;
  1268. $scope.index = 0;
  1269. $scope.vm = {
  1270. keyword : ""
  1271. };
  1272. $ionicTabsDelegate.showBar(false);
  1273. // $ionicNavBarDelegate.showBackButton(false);
  1274. homeService.search('').then(function(result){
  1275. $scope.hot_searches = result.data.data.hot_searches;
  1276. $scope.history_searches = result.data.data.history_searches;
  1277. });
  1278. });
  1279. }]);
  1280. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1281. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1282. }]);
  1283. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1284. , function ($scope, $state, myService, msg) {
  1285. $scope.$on('$ionicView.beforeEnter', function () {
  1286. myService.myDream().then(function(result){
  1287. console.log(result.data.data);
  1288. $scope.dreams = result.data.data;
  1289. });
  1290. });
  1291. $scope.toDetail = function (id) {
  1292. $state.go('app.home_dreamdetail',{id:id});
  1293. };
  1294. }]);
  1295. })(angular.module('app.controllers'));