home.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. if (type==0) {
  540. //分享给朋友
  541. Wechat.share({
  542. message: {
  543. title: $scope.dream.name,
  544. description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '\n' + $scope.dream.about,
  545. thumb: $scope.dream.imgs[0].pic,
  546. media: {
  547. type: Wechat.Type.WEBPAGE,
  548. webpageUrl: config.server + "/admin/share/view?id=" + id + '&user_id = ' + $scope.user.id
  549. }
  550. },
  551. scene: Wechat.Scene.SESSION
  552. }, function () {
  553. $scope.toshare = false;
  554. msg.success('分享成功');
  555. }, function (reason) {
  556. $scope.toshare = false;
  557. msg.error('分享失败');
  558. msg.alert(reason);
  559. });
  560. }
  561. if(type==1){
  562. // 分享到朋友圈
  563. Wechat.share({
  564. message: {
  565. title: $scope.dream.name,
  566. description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '\n' + $scope.dream.about,
  567. thumb: $scope.dream.imgs[0].pic,
  568. media: {
  569. type: Wechat.Type.WEBPAGE,
  570. webpageUrl: config.server + "/admin/share/view?id=" + id
  571. }
  572. },
  573. scene: Wechat.Scene.TIMELINE
  574. }, function () {
  575. $scope.toshare = false;
  576. msg.success('分享成功');
  577. }, function (reason) {
  578. $scope.toshare = false;
  579. msg.error('分享失败');
  580. msg.alert(reason);
  581. });
  582. }
  583. };
  584. //实时排行
  585. $scope.sort = {
  586. slide: ''
  587. };
  588. $scope.changeType = function (type) {
  589. $ionicScrollDelegate.scrollTop(true);
  590. $scope.type = type;
  591. $scope.toshare = false;
  592. };
  593. $scope.index = 0;
  594. $scope.vm = {
  595. coin:"",
  596. title:""
  597. };
  598. $scope.timer = '';
  599. var leftTimer = function (countDown) {
  600. if (isNaN(countDown)) {
  601. $scope.timer = '已结束';
  602. return;
  603. }
  604. if (countDown<=0) {
  605. $scope.timer = '已结束';
  606. return;
  607. }
  608. var day=parseInt(countDown/(24*60*60));
  609. var h=parseInt(countDown/(60*60)%24);
  610. var m=parseInt(countDown/60%60);
  611. var s=parseInt(countDown%60);
  612. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  613. if(day>0) $scope.timer = day+'天';
  614. if(day<0 && h>0) $scope.timer = h+'小时';
  615. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  616. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  617. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  618. $scope.leftTimer = $interval(function () {
  619. if (countDown >= 1) leftTimer(countDown - 1);
  620. },1000);*/
  621. /*if(countDown<=0){
  622. $scope.timer='结束';
  623. }*/
  624. };
  625. $scope.changeIndex = function (index) {
  626. $scope.index = index;
  627. $scope.vm.coin = index*10;
  628. };
  629. $scope.vidEnded = function () {
  630. alert('播放完毕');
  631. };
  632. //实时计算支持乘数
  633. //$scope.calcmultiplier = function () {
  634. // $scope.multi.promise = $interval(function () {
  635. //
  636. // var date = new Date();
  637. // var inter = date.getTime() - $scope.multi.b.getTime();
  638. // var minutes = Math.floor(inter / (60 * 1000));
  639. // var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  640. // if (number<=1) {
  641. // number = 1;
  642. // }
  643. // $scope.multi.result = Math.round(number * 100 / 100);
  644. // },1000);
  645. //};
  646. $scope.supportDream = function (data) {
  647. if(!$scope.vm.coin){
  648. msg.error("请选择梦想币数量!");
  649. return ;
  650. }
  651. var data = {
  652. id:id,
  653. coin:$scope.vm.coin
  654. };
  655. homeService.supportDream(data).then(function(result){
  656. $scope.tosupport = false;
  657. $scope.load(id);
  658. homeService.myInfo().then(function(result){
  659. $scope.user = result.data.data;
  660. });
  661. $interval.cancel($scope.multi.promise);
  662. msg.text("发送成功",1000);
  663. });
  664. };
  665. $scope.collectionDream = function(is_collection){
  666. homeService.collectionDream(id,is_collection).then(function(result){
  667. $scope.dream.is_collection=result.data.data;
  668. })
  669. };
  670. $scope.add = function(is_collection){
  671. var data = {
  672. id:id,
  673. title:$scope.vm.title,
  674. pics:$scope.imgs,
  675. video:$scope.video.server
  676. };
  677. homeService.add_interaction(data).then(function(){
  678. $scope.load(id);
  679. $scope.closeModal();
  680. })
  681. };
  682. $scope.showAbout = true;
  683. $scope.hideAbout = false;
  684. $scope.showText = function(){
  685. $scope.aboutStyle = {
  686. "white-space" : "normal"
  687. };
  688. $scope.showAbout = false;
  689. $scope.hideAbout = true;
  690. };
  691. $scope.hideText = function(){
  692. $scope.aboutStyle = {
  693. "white-space" : "nowrap"
  694. };
  695. $scope.showAbout = true;
  696. $scope.hideAbout = false;
  697. };
  698. $scope.input = {
  699. placeholder: '评论',
  700. focus: false,
  701. show:false
  702. };
  703. $scope.showmore = function (index) {
  704. if ($scope.dream.interactions[index].showmore) {
  705. $scope.dream.interactions[index].showmore = false;
  706. } else {
  707. $scope.dream.interactions[index].showmore = true;
  708. }
  709. };
  710. $scope.replay = function ($event, name, to_userid, index) {
  711. $event.stopPropagation();
  712. $scope.input.focus = true;
  713. $scope.input.show = true;
  714. $scope.toshare = false;
  715. angular.forEach($scope.dream.interactions, function (item) {
  716. item.show = false;
  717. });
  718. $scope.dream.interactions[index].show = true;
  719. $scope.dream.interactions[index].focus = true;
  720. $scope.input.placeholder = "评论" + name+":";
  721. $scope.to_userid = to_userid;
  722. $scope.vm.title='';
  723. $scope.vm.comment='';
  724. };
  725. $scope.replayOther = function ($event, name, to_userid, index,currentindex) {
  726. $event.stopPropagation();
  727. $scope.toshare = false;
  728. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  729. $scope.input.focus = true;
  730. $scope.input.show = true;
  731. angular.forEach($scope.dream.interactions, function (item) {
  732. item.show = false;
  733. });
  734. $scope.dream.interactions[index].show = true;
  735. $scope.dream.interactions[index].focus = true;
  736. $scope.input.placeholder = "评论" + name;
  737. $scope.to_userid = to_userid;
  738. $scope.vm.title='';
  739. $scope.vm.comment='';
  740. }
  741. else if($scope.timer!='已结束') {
  742. msg.confirm("评论","是否删除评论").then(function(result){
  743. if(result==true)
  744. {
  745. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  746. msg.text("删除成功");
  747. $scope.load(id);
  748. },function(error){
  749. msg.error(error.data.message);
  750. })
  751. }
  752. });
  753. }
  754. };
  755. $scope.ios={
  756. isIOS:ionic.Platform.isIOS(),
  757. productid:''
  758. }
  759. //充值
  760. $scope.charge = function(number){
  761. if($scope.ios.isIOS){
  762. if (number<2){
  763. msg.text('请选择充值金额');
  764. return;
  765. }
  766. console.log('购买productid:'+number);
  767. msg.loading();
  768. inAppPurchase
  769. .buy(number)
  770. .then(function (data) {
  771. msg.hide();
  772. console.log('购买then:'+JSON.stringify(data));
  773. return inAppPurchase.consume(data.productType, data.receipt, data.signature);
  774. })
  775. .then(function (data) {
  776. msg.hide();
  777. myService.orderIos(number).then(function (result) {
  778. console.log('服务器端购买成功:'+number);
  779. }, function (erro) {
  780. });
  781. console.log('购买成功:'+number);
  782. msg.success('购买成功');
  783. $timeout(function () {
  784. $scope.closeRechargeModal();
  785. }, 1000);
  786. })
  787. .catch(function (err) {
  788. msg.hide();
  789. console.log('购买失败:'+JSON.stringify(err));
  790. $timeout(function () {
  791. $scope.closeRechargeModal();
  792. }, 1000);
  793. // alert('购买失败:'+JSON.stringify(err));
  794. });
  795. }else{
  796. if (!number) {
  797. msg.text('请输入充值金额');
  798. return;
  799. }
  800. homeService.charge(number,2).then(function (result) {
  801. //todo:result需要返回支付宝或者微信的签名信息
  802. console.log("result: " + JSON.stringify(result));
  803. var payInfo = result.data.data;
  804. if ($scope.vm.payType == 1) { //支付宝
  805. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  806. $scope.clicksub = false;
  807. if (e.resultStatus == '9000') {
  808. alert(orderID);
  809. $timeout(function () {
  810. $scope.closeRechargeModal();
  811. }, 1000);
  812. homeService.myInfo().then(function (result) {
  813. $scope.user = result.data.data;
  814. });
  815. } else {
  816. msg.error("支付失败");
  817. // msg.error("支付失败:" + JSON.stringify(e));
  818. }
  819. }, function error(e) {
  820. $scope.clicksub = false;
  821. // msg.error("支付失败:" + JSON.stringify(e));
  822. msg.error("支付失败");
  823. });
  824. }
  825. if ($scope.vm.payType == 2) { //微信
  826. // var obj = JSON.parse(payInfo);
  827. var obj = payInfo.orderString;
  828. // console.log("obj: " + JSON.stringify(obj));
  829. var params = {
  830. partnerid: obj.partnerid, // merchant id
  831. prepayid: obj.prepayid, // prepay id
  832. noncestr: obj.noncestr, // nonce
  833. timestamp: obj.timestamp, // timestamp
  834. sign: obj.sign, // signed string
  835. };
  836. // console.log("result: " + JSON.stringify(params));
  837. Wechat.sendPaymentRequest(params, function (r) {
  838. // $scope.clicksub = false;
  839. $timeout(function () {
  840. $scope.closeRechargeModal();
  841. }, 1000);
  842. $scope.load(id,dream_user_id,interaction_id);
  843. // courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  844. // homeService.myInfo().then(function (result) {
  845. // $scope.user = result.data.data;
  846. // });
  847. // }, function (erro) {
  848. // // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  849. // });
  850. }, function (reason) {
  851. $scope.clicksub = false;
  852. // msg.alert("支付失败:" + JSON.stringify(reason));
  853. });
  854. }
  855. });
  856. }
  857. };
  858. $scope.submitComment = function (index,to_userid) {
  859. var interaction = $scope.dream.interactions[index];
  860. var iid = interaction.id;
  861. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  862. $scope.input.focus = true;
  863. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  864. var data = {
  865. id:iid,
  866. content:$scope.vm.comment,
  867. comment_user_id:to_userid,
  868. to_user_id: $scope.dream.user.id
  869. };
  870. if($scope.timer=='已结束'){
  871. msg.alert("评论","该梦想已结束,不支持评论");
  872. }
  873. else {
  874. homeService.add_comment(data).then(function(){
  875. msg.success('评论成功');
  876. $scope.vm.comment = '' ;
  877. $scope.load(id);
  878. $scope.closeModal();
  879. });
  880. }
  881. };
  882. $scope.bigImage = false;
  883. $scope.showBigImage = function ($event, imageName) {
  884. $event.stopPropagation();
  885. $scope.url = imageName;
  886. $scope.bigImage = true;
  887. };
  888. $scope.hideBigImage = function(){
  889. $scope.bigImage = false;
  890. };
  891. $ionicModal.fromTemplateUrl('qrCode.html', {
  892. scope: $scope,
  893. animation: 'slide-in-up'
  894. }).then(function(modal) {
  895. $scope.qrCodemodal = modal;
  896. });
  897. $scope.openCode = function($event) {
  898. $event.stopPropagation();
  899. $scope.qrCodemodal.show();
  900. $scope.vm.money = '';
  901. };
  902. $scope.closeCode = function() {
  903. $scope.qrCodemodal.hide();
  904. };
  905. $ionicModal.fromTemplateUrl('commentPic.html', {
  906. scope: $scope,
  907. animation: 'slide-in-up'
  908. }).then(function(modal) {
  909. $scope.CommentPicmodal = modal;
  910. });
  911. $scope.openCommentPic = function(pic,$event) {
  912. $event.stopPropagation();
  913. $scope.CommentPicmodal.show();
  914. $scope.commentPicUrl = pic;
  915. };
  916. $scope.closeCommentPic = function() {
  917. $scope.CommentPicmodal.hide();
  918. };
  919. $scope.addpict = function () {
  920. common.chooseImage().then(function (img) {
  921. common.uploadFiles(img,1).then(function (result) {
  922. var response = JSON.parse(result.response);
  923. var file = config.imgServer + response.data.file;
  924. $scope.imgs.push(file);
  925. }, function (error) {
  926. msg.error('图片上传失败');
  927. });
  928. }, function (error) {
  929. console.log('图片选择失败');
  930. });
  931. };
  932. $scope.deletefile = function (file) {
  933. var index = $scope.imgs.indexOf(file);
  934. $scope.imgs.splice(index, 1);
  935. common.deletefile(file).then(function () {
  936. })
  937. };
  938. $scope.addvideo = function () {
  939. common.chooseVideo().then(function (file) {
  940. msg.loading();
  941. common.uploadFiles(file, 2).then(function (result) {
  942. msg.hide();
  943. var response = JSON.parse(result.response);
  944. $scope.video.server = response.data.file;
  945. var file = config.imgServer+response.data.file;
  946. $scope.video.isOK = true;
  947. $scope.video.file = file;
  948. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  949. }, function (error) {
  950. //msg.error('视频上传失败');
  951. msg.hide();
  952. msg.error(JSON.stringify(error));
  953. });
  954. }, function (erro) {
  955. console.log('选择视频失败');
  956. });
  957. };
  958. $scope.deletevideo = function (file) {
  959. $scope.video = {};
  960. common.deletefile(file).then(function (res) {
  961. },function(erro){
  962. alert(JSON.stringify(erro));
  963. })
  964. };
  965. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  966. scope: $scope,
  967. animation: 'slide-in-up'
  968. }).then(function(modal) {
  969. $scope.rechagemodal = modal;
  970. });
  971. $scope.openRechargeModal = function() {
  972. $scope.rechagemodal.show();
  973. $scope.vm.money = '';
  974. if($scope.ios.isIOS){
  975. var productIds = ['apple10001','apple102','apple103','apple104']; // <- Add your product Ids here
  976. msg.loading();
  977. inAppPurchase.getProducts(productIds).then(function (products) {
  978. msg.hide();
  979. $scope.products = products;
  980. console.log('products:'+JSON.stringify(products));
  981. }).catch(function (err) {
  982. msg.hide();
  983. console.log(err);
  984. });
  985. }
  986. };
  987. $scope.closeRechargeModal = function() {
  988. $scope.rechagemodal.hide();
  989. };
  990. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  991. scope: $scope,
  992. animation: 'slide-in-up'
  993. }).then(function(modal) {
  994. $scope.modal = modal;
  995. });
  996. $scope.openModal = function() {
  997. $scope.modal.show();
  998. $scope.vm.title = '';
  999. $scope.imgs = [];
  1000. $scope.video = {};
  1001. };
  1002. $scope.closeModal = function() {
  1003. $scope.modal.hide();
  1004. };
  1005. //当我们用到模型时,清除它!
  1006. $scope.$on('$destroy', function() {
  1007. $scope.modal.remove();
  1008. $scope.rechagemodal.remove();
  1009. });
  1010. $scope.toMessage = function(){
  1011. if($location.path()=="/app/home/dreamdetail"){
  1012. $state.go("app.message");
  1013. }
  1014. else {
  1015. $state.go("app.my_message");
  1016. }
  1017. }
  1018. }]);
  1019. app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$timeout", "$ionicScrollDelegate", "$interval"
  1020. , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $timeout, $ionicScrollDelegate, $interval) {
  1021. var id = $stateParams.id;
  1022. $scope.items = $stateParams.items;
  1023. $scope.$on('$ionicView.beforeEnter', function () {
  1024. $ionicTabsDelegate.showBar(false);
  1025. });
  1026. $scope.attentionUser = function(is_care){
  1027. homeService.attentionUser(id,is_care).then(function(result){
  1028. $scope.items.is_care=result.data.data;
  1029. })
  1030. };
  1031. $scope.next = function (type) {
  1032. //type:1 前一个,type:2 后一个
  1033. if($scope.items.imgs.length>0){
  1034. if(type==1)
  1035. {
  1036. var temp= $scope.items.imgs.splice(0,1);
  1037. $scope.items.imgs.push(temp[0]);
  1038. }
  1039. if (type==2){
  1040. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  1041. $scope.items.imgs.unshift(temp[0]);
  1042. }
  1043. }
  1044. };
  1045. $scope.bigImage = false;
  1046. $scope.showBigImage = function(imageName,imageIndex){
  1047. $scope.url = imageName;
  1048. $scope.imageIndex = imageIndex;
  1049. $scope.bigImage = true;
  1050. };
  1051. $scope.hideBigImage = function(){
  1052. $scope.bigImage = false;
  1053. };
  1054. $scope.swipeLeft = function (imageIndex) {
  1055. if ($scope.imageIndex < $scope.items.imgs.length - 1 && $scope.imageIndex >= 0)
  1056. $scope.imageIndex = $scope.imageIndex + 1;
  1057. else {
  1058. //如果图片已经是最后一张图片了,则取index = 0
  1059. $scope.imageIndex = 0;
  1060. }
  1061. //替换url,展示图片
  1062. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  1063. $scope.bigImage = true; //显示大图
  1064. };
  1065. $scope.swipeRight = function (imageIndex) {
  1066. if ($scope.imageIndex <= $scope.items.imgs.length - 1 && $scope.imageIndex > 0)
  1067. $scope.imageIndex = $scope.imageIndex - 1;
  1068. else {
  1069. //如果图片已经是第一张图片了,则取index = Images.length-1
  1070. $scope.imageIndex = $scope.items.imgs.length - 1;
  1071. }
  1072. //替换url,展示图片
  1073. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  1074. $scope.bigImage = true; //显示大图
  1075. };
  1076. $scope.cancelSupport = function () {
  1077. $scope.tosupport = false;
  1078. $scope.toshare = false;
  1079. };
  1080. $scope.toshare = false;
  1081. $scope.toRecharge = function(){
  1082. $state.go("app.recharge")
  1083. };
  1084. $scope.toDetail = function (dream_id) {
  1085. if($scope.items.near_dream==null){
  1086. msg.alert("当前梦想","该用户没有当前梦想");
  1087. }
  1088. if($scope.items.near_dream!=null){
  1089. var dream_id = $scope.items.near_dream.id;
  1090. if($location.path()=="/app/home/userDetail"){
  1091. $state.go('app.home_dreamdetail',{id:dream_id});
  1092. }
  1093. else {
  1094. $state.go('app.my_dreamdetail',{id:dream_id});
  1095. }
  1096. }
  1097. };
  1098. $scope.toOldDream = function(){
  1099. if($scope.items.dreams.length<2){
  1100. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  1101. }
  1102. if($scope.items.dreams.length>1){
  1103. if($location.path()=="/app/home/userDetail"){
  1104. $state.go('app.oldDream',{user_id:$scope.items.user.id});
  1105. }
  1106. else {
  1107. $state.go('app.myOldDream',{user_id:$scope.items.user.id});
  1108. }
  1109. }
  1110. };
  1111. $scope.toSupportDream = function(){
  1112. if($scope.items.sup_dreams.length==0){
  1113. msg.alert("支持的梦想","该用户没有支持的梦想");
  1114. }
  1115. if($scope.items.sup_dreams.length!=0){
  1116. if($scope.items.dreams.length>1){
  1117. if($location.path()=="/app/home/userDetail"){
  1118. $state.go('app.supportDream',{user_id:$scope.items.user.id});
  1119. }
  1120. else {
  1121. $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
  1122. }
  1123. }
  1124. }
  1125. };
  1126. $scope.collectionDream = function(is_collection){
  1127. homeService.collectionDream(id,is_collection).then(function(result){
  1128. $scope.user.is_collection=result.data.data;
  1129. })
  1130. };
  1131. }]);
  1132. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  1133. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  1134. $scope.$on('$ionicView.beforeEnter', function () {
  1135. $ionicTabsDelegate.showBar(false);
  1136. myService.collect().then(function(result){
  1137. $scope.dreams = result.data.data.dreams;
  1138. });
  1139. });
  1140. $scope.toDetail = function (id) {
  1141. $state.go('app.home_dreamdetail',{id:id});
  1142. };
  1143. }]);
  1144. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1145. , function ($scope,homeService,$stateParams, $state, msg) {
  1146. $scope.dream = $stateParams.item;
  1147. $scope.showAbout = true;
  1148. $scope.hideAbout = false;
  1149. $scope.showText = function(){
  1150. $scope.aboutStyle = {
  1151. "white-space" : "normal"
  1152. };
  1153. $scope.showAbout = false;
  1154. $scope.hideAbout = true;
  1155. };
  1156. $scope.hideText = function(){
  1157. $scope.aboutStyle = {
  1158. "white-space" : "nowrap"
  1159. };
  1160. $scope.showAbout = true;
  1161. $scope.hideAbout = false;
  1162. };
  1163. }]);
  1164. //app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  1165. // , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  1166. // $scope.$on('$ionicView.beforeEnter', function () {
  1167. // $ionicTabsDelegate.showBar(false);
  1168. // myService.messageInfo().then(function(result){
  1169. // $scope.infos = result.data.data;
  1170. // },function(error){
  1171. //
  1172. // });
  1173. // });
  1174. // $scope.notRead = function(){
  1175. // myService.notRead().then(function(result){
  1176. // myService.messageInfo().then(function(result){
  1177. // $scope.infos = result.data.data;
  1178. // },function(error){
  1179. //
  1180. // });
  1181. // },function(error){
  1182. //
  1183. // })
  1184. // };
  1185. // //系统消息
  1186. // $scope.systemInfo = function(){
  1187. // $state.go("app.message_sys");
  1188. // myService.systemInfo().then(function(result){
  1189. // },function(error){
  1190. //
  1191. // });
  1192. // };
  1193. // //回复我的
  1194. // $scope.replyMy = function(){
  1195. // $state.go("app.message_reply");
  1196. // myService.replyMy().then(function(result){
  1197. //
  1198. // },function(error){
  1199. //
  1200. // });
  1201. // };
  1202. // $scope.personalLetter = function(){
  1203. // $state.go("app.letter");
  1204. // }
  1205. // }]);
  1206. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1207. , function ($scope,homeService,$stateParams, $state, msg) {
  1208. var user_id = $stateParams.user_id;
  1209. $scope.$on('$ionicView.beforeEnter',function(){
  1210. $scope.toUserDetail(user_id);
  1211. });
  1212. $scope.toUserDetail = function(user_id){
  1213. homeService.toUserDetail(user_id).then(function(result){
  1214. $scope.items = result.data.data;
  1215. $scope.user = result.data.data.user;
  1216. $scope.dreams = $scope.user.dreams;
  1217. },function(error){
  1218. })
  1219. };
  1220. $scope.toDetail = function(id){
  1221. $state.go('app.home_dreamdetail',{id:id});
  1222. // $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1223. };
  1224. }]);
  1225. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1226. , function ($scope,homeService,$stateParams, $state, msg) {
  1227. var user_id = $stateParams.user_id;
  1228. $scope.$on('$ionicView.beforeEnter',function(){
  1229. $scope.toUserDetail(user_id);
  1230. });
  1231. $scope.toUserDetail = function(user_id){
  1232. homeService.toUserDetail(user_id).then(function(result){
  1233. $scope.items = result.data.data;
  1234. $scope.user = result.data.data.user;
  1235. $scope.dreams = $scope.user.sup_dream;
  1236. },function(error){
  1237. })
  1238. };
  1239. $scope.toDetail = function(id){
  1240. $state.go('app.home_dreamdetail',{id:id});
  1241. // $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1242. }
  1243. }]);
  1244. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1245. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1246. $scope.showMore = function (keyword,index) {
  1247. if(!keyword)return;
  1248. $scope.index = index;
  1249. $scope.search(keyword);
  1250. };
  1251. $scope.search = function (keyword) {
  1252. $scope.vm.keyword = keyword;
  1253. homeService.search(keyword).then(function(result){
  1254. $scope.isResult = true;
  1255. $scope.dream_infos = result.data.data.dream_infos;
  1256. $scope.user_infos = result.data.data.user_infos;
  1257. });
  1258. };
  1259. $scope.toUserDetail = function (id) {
  1260. homeService.toUserDetail(id).then(function(result){
  1261. $scope.items = result.data.data;
  1262. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1263. },function(error){
  1264. //msg.error(msg.data.error)
  1265. })
  1266. };
  1267. $scope.toDetail = function (id) {
  1268. $state.go('app.home_dreamdetail',{id:id});
  1269. };
  1270. $scope.$on('$ionicView.beforeEnter', function () {
  1271. $scope.isResult = false;
  1272. $scope.index = 0;
  1273. $scope.vm = {
  1274. keyword : ""
  1275. };
  1276. $ionicTabsDelegate.showBar(false);
  1277. // $ionicNavBarDelegate.showBackButton(false);
  1278. homeService.search('').then(function(result){
  1279. $scope.hot_searches = result.data.data.hot_searches;
  1280. $scope.history_searches = result.data.data.history_searches;
  1281. });
  1282. });
  1283. }]);
  1284. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1285. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1286. }]);
  1287. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1288. , function ($scope, $state, myService, msg) {
  1289. $scope.$on('$ionicView.beforeEnter', function () {
  1290. myService.myDream().then(function(result){
  1291. console.log(result.data.data);
  1292. $scope.dreams = result.data.data;
  1293. });
  1294. });
  1295. $scope.toDetail = function (id) {
  1296. $state.go('app.home_dreamdetail',{id:id});
  1297. };
  1298. }]);
  1299. })(angular.module('app.controllers'));