home.js 57 KB

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