home.js 58 KB

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