home.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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. $scope.showmore = function (index) {
  695. if ($scope.dream.interactions[index].showmore) {
  696. $scope.dream.interactions[index].showmore = false;
  697. } else {
  698. $scope.dream.interactions[index].showmore = true;
  699. }
  700. };
  701. $scope.replay = function ($event, name, to_userid, index) {
  702. $event.stopPropagation();
  703. $scope.input.focus = true;
  704. $scope.input.show = true;
  705. $scope.toshare = false;
  706. angular.forEach($scope.dream.interactions, function (item) {
  707. item.show = false;
  708. });
  709. $scope.dream.interactions[index].show = true;
  710. $scope.dream.interactions[index].focus = true;
  711. $scope.input.placeholder = "评论" + name+":";
  712. $scope.to_userid = to_userid;
  713. $scope.vm.title='';
  714. $scope.vm.comment='';
  715. };
  716. $scope.replayOther = function ($event, name, to_userid, index,currentindex) {
  717. $event.stopPropagation();
  718. $scope.toshare = false;
  719. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  720. $scope.input.focus = true;
  721. $scope.input.show = true;
  722. angular.forEach($scope.dream.interactions, function (item) {
  723. item.show = false;
  724. });
  725. $scope.dream.interactions[index].show = true;
  726. $scope.dream.interactions[index].focus = true;
  727. $scope.input.placeholder = "评论" + name;
  728. $scope.to_userid = to_userid;
  729. $scope.vm.title='';
  730. $scope.vm.comment='';
  731. }
  732. else if($scope.timer!='已结束') {
  733. msg.confirm("评论","是否删除评论").then(function(result){
  734. if(result==true)
  735. {
  736. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  737. msg.text("删除成功");
  738. $scope.load(id);
  739. },function(error){
  740. msg.error(error.data.message);
  741. })
  742. }
  743. });
  744. }
  745. };
  746. $scope.ios={
  747. isIOS:ionic.Platform.isIOS(),
  748. productid:''
  749. }
  750. //充值
  751. $scope.charge = function(number){
  752. if($scope.ios.isIOS){
  753. if (number<2){
  754. msg.text('请选择充值金额');
  755. return;
  756. }
  757. console.log('购买productid:'+number);
  758. msg.loading();
  759. inAppPurchase
  760. .buy(number)
  761. .then(function (data) {
  762. msg.hide();
  763. console.log('购买then:'+JSON.stringify(data));
  764. return inAppPurchase.consume(data.productType, data.receipt, data.signature);
  765. })
  766. .then(function (data) {
  767. msg.hide();
  768. myService.orderIos(number).then(function (result) {
  769. console.log('服务器端购买成功:'+number);
  770. }, function (erro) {
  771. });
  772. console.log('购买成功:'+number);
  773. msg.success('购买成功');
  774. $timeout(function () {
  775. $scope.closeRechargeModal();
  776. }, 1000);
  777. })
  778. .catch(function (err) {
  779. msg.hide();
  780. console.log('购买失败:'+JSON.stringify(err));
  781. $timeout(function () {
  782. $scope.closeRechargeModal();
  783. }, 1000);
  784. // alert('购买失败:'+JSON.stringify(err));
  785. });
  786. }else{
  787. if (!number) {
  788. msg.text('请输入充值金额');
  789. return;
  790. }
  791. homeService.charge(number,2).then(function (result) {
  792. //todo:result需要返回支付宝或者微信的签名信息
  793. console.log("result: " + JSON.stringify(result));
  794. var payInfo = result.data.data;
  795. if ($scope.vm.payType == 1) { //支付宝
  796. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  797. $scope.clicksub = false;
  798. if (e.resultStatus == '9000') {
  799. alert(orderID);
  800. $timeout(function () {
  801. $scope.closeRechargeModal();
  802. }, 1000);
  803. homeService.myInfo().then(function (result) {
  804. $scope.user = result.data.data;
  805. });
  806. } else {
  807. msg.error("支付失败");
  808. // msg.error("支付失败:" + JSON.stringify(e));
  809. }
  810. }, function error(e) {
  811. $scope.clicksub = false;
  812. // msg.error("支付失败:" + JSON.stringify(e));
  813. msg.error("支付失败");
  814. });
  815. }
  816. if ($scope.vm.payType == 2) { //微信
  817. // var obj = JSON.parse(payInfo);
  818. var obj = payInfo.orderString;
  819. // console.log("obj: " + JSON.stringify(obj));
  820. var params = {
  821. partnerid: obj.partnerid, // merchant id
  822. prepayid: obj.prepayid, // prepay id
  823. noncestr: obj.noncestr, // nonce
  824. timestamp: obj.timestamp, // timestamp
  825. sign: obj.sign, // signed string
  826. };
  827. // console.log("result: " + JSON.stringify(params));
  828. Wechat.sendPaymentRequest(params, function (r) {
  829. // $scope.clicksub = false;
  830. $timeout(function () {
  831. $scope.closeRechargeModal();
  832. }, 1000);
  833. $scope.load(id,dream_user_id,interaction_id);
  834. // courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  835. // homeService.myInfo().then(function (result) {
  836. // $scope.user = result.data.data;
  837. // });
  838. // }, function (erro) {
  839. // // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  840. // });
  841. }, function (reason) {
  842. $scope.clicksub = false;
  843. // msg.alert("支付失败:" + JSON.stringify(reason));
  844. });
  845. }
  846. });
  847. }
  848. };
  849. $scope.submitComment = function (index,to_userid) {
  850. var interaction = $scope.dream.interactions[index];
  851. var iid = interaction.id;
  852. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  853. $scope.input.focus = true;
  854. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  855. var data = {
  856. id:iid,
  857. content:$scope.vm.comment,
  858. comment_user_id:to_userid,
  859. to_user_id: $scope.dream.user.id
  860. };
  861. if($scope.timer=='已结束'){
  862. msg.alert("评论","该梦想已结束,不支持评论");
  863. }
  864. else {
  865. homeService.add_comment(data).then(function(){
  866. msg.success('评论成功');
  867. $scope.vm.comment = '' ;
  868. $scope.load(id);
  869. $scope.closeModal();
  870. });
  871. }
  872. };
  873. $scope.bigImage = false;
  874. $scope.showBigImage = function ($event, imageName) {
  875. $event.stopPropagation();
  876. $scope.url = imageName;
  877. $scope.bigImage = true;
  878. };
  879. $scope.hideBigImage = function(){
  880. $scope.bigImage = false;
  881. };
  882. $ionicModal.fromTemplateUrl('qrCode.html', {
  883. scope: $scope,
  884. animation: 'slide-in-up'
  885. }).then(function(modal) {
  886. $scope.qrCodemodal = modal;
  887. });
  888. $scope.openCode = function($event) {
  889. $event.stopPropagation();
  890. $scope.qrCodemodal.show();
  891. $scope.vm.money = '';
  892. };
  893. $scope.closeCode = function() {
  894. $scope.qrCodemodal.hide();
  895. };
  896. $ionicModal.fromTemplateUrl('commentPic.html', {
  897. scope: $scope,
  898. animation: 'slide-in-up'
  899. }).then(function(modal) {
  900. $scope.CommentPicmodal = modal;
  901. });
  902. $scope.openCommentPic = function(pic,$event) {
  903. $event.stopPropagation();
  904. $scope.CommentPicmodal.show();
  905. $scope.commentPicUrl = pic;
  906. };
  907. $scope.closeCommentPic = function() {
  908. $scope.CommentPicmodal.hide();
  909. };
  910. $scope.addpict = function () {
  911. common.chooseImage().then(function (img) {
  912. common.uploadFiles(img,1).then(function (result) {
  913. var response = JSON.parse(result.response);
  914. var file = config.imgServer + response.data.file;
  915. $scope.imgs.push(file);
  916. }, function (error) {
  917. msg.error('图片上传失败');
  918. });
  919. }, function (error) {
  920. console.log('图片选择失败');
  921. });
  922. };
  923. $scope.deletefile = function (file) {
  924. var index = $scope.imgs.indexOf(file);
  925. $scope.imgs.splice(index, 1);
  926. common.deletefile(file).then(function () {
  927. })
  928. };
  929. $scope.addvideo = function () {
  930. common.chooseVideo().then(function (file) {
  931. msg.loading();
  932. common.uploadFiles(file, 2).then(function (result) {
  933. msg.hide();
  934. var response = JSON.parse(result.response);
  935. $scope.video.server = response.data.file;
  936. var file = config.imgServer+response.data.file;
  937. $scope.video.isOK = true;
  938. $scope.video.file = file;
  939. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  940. }, function (error) {
  941. //msg.error('视频上传失败');
  942. msg.hide();
  943. msg.error(JSON.stringify(error));
  944. });
  945. }, function (erro) {
  946. console.log('选择视频失败');
  947. });
  948. };
  949. $scope.deletevideo = function (file) {
  950. $scope.video = {};
  951. common.deletefile(file).then(function (res) {
  952. },function(erro){
  953. alert(JSON.stringify(erro));
  954. })
  955. };
  956. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  957. scope: $scope,
  958. animation: 'slide-in-up'
  959. }).then(function(modal) {
  960. $scope.rechagemodal = modal;
  961. });
  962. $scope.openRechargeModal = function() {
  963. $scope.rechagemodal.show();
  964. $scope.vm.money = '';
  965. if($scope.ios.isIOS){
  966. var productIds = ['apple10001','apple102','apple103','apple104']; // <- Add your product Ids here
  967. msg.loading();
  968. inAppPurchase.getProducts(productIds).then(function (products) {
  969. msg.hide();
  970. $scope.products = products;
  971. console.log('products:'+JSON.stringify(products));
  972. }).catch(function (err) {
  973. msg.hide();
  974. console.log(err);
  975. });
  976. }
  977. };
  978. $scope.closeRechargeModal = function() {
  979. $scope.rechagemodal.hide();
  980. };
  981. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  982. scope: $scope,
  983. animation: 'slide-in-up'
  984. }).then(function(modal) {
  985. $scope.modal = modal;
  986. });
  987. $scope.openModal = function() {
  988. $scope.modal.show();
  989. $scope.vm.title = '';
  990. $scope.imgs = [];
  991. $scope.video = {};
  992. };
  993. $scope.closeModal = function() {
  994. $scope.modal.hide();
  995. };
  996. //当我们用到模型时,清除它!
  997. $scope.$on('$destroy', function() {
  998. $scope.modal.remove();
  999. $scope.rechagemodal.remove();
  1000. });
  1001. $scope.toMessage = function(){
  1002. if($location.path()=="/app/home/dreamdetail"){
  1003. $state.go("app.message");
  1004. }
  1005. else {
  1006. $state.go("app.my_message");
  1007. }
  1008. }
  1009. }]);
  1010. app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$timeout", "$ionicScrollDelegate", "$interval"
  1011. , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $timeout, $ionicScrollDelegate, $interval) {
  1012. var id = $stateParams.id;
  1013. $scope.items = $stateParams.items;
  1014. $scope.$on('$ionicView.beforeEnter', function () {
  1015. $ionicTabsDelegate.showBar(false);
  1016. });
  1017. $scope.attentionUser = function(is_care){
  1018. homeService.attentionUser(id,is_care).then(function(result){
  1019. $scope.items.is_care=result.data.data;
  1020. })
  1021. };
  1022. $scope.next = function (type) {
  1023. //type:1 前一个,type:2 后一个
  1024. if($scope.items.imgs.length>0){
  1025. if(type==1)
  1026. {
  1027. var temp= $scope.items.imgs.splice(0,1);
  1028. $scope.items.imgs.push(temp[0]);
  1029. }
  1030. if (type==2){
  1031. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  1032. $scope.items.imgs.unshift(temp[0]);
  1033. }
  1034. }
  1035. };
  1036. $scope.bigImage = false;
  1037. $scope.showBigImage = function(imageName,imageIndex){
  1038. $scope.url = imageName;
  1039. $scope.imageIndex = imageIndex;
  1040. $scope.bigImage = true;
  1041. };
  1042. $scope.hideBigImage = function(){
  1043. $scope.bigImage = false;
  1044. };
  1045. $scope.swipeLeft = function (imageIndex) {
  1046. if ($scope.imageIndex < $scope.items.imgs.length - 1 && $scope.imageIndex >= 0)
  1047. $scope.imageIndex = $scope.imageIndex + 1;
  1048. else {
  1049. //如果图片已经是最后一张图片了,则取index = 0
  1050. $scope.imageIndex = 0;
  1051. }
  1052. //替换url,展示图片
  1053. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  1054. $scope.bigImage = true; //显示大图
  1055. };
  1056. $scope.swipeRight = function (imageIndex) {
  1057. if ($scope.imageIndex <= $scope.items.imgs.length - 1 && $scope.imageIndex > 0)
  1058. $scope.imageIndex = $scope.imageIndex - 1;
  1059. else {
  1060. //如果图片已经是第一张图片了,则取index = Images.length-1
  1061. $scope.imageIndex = $scope.items.imgs.length - 1;
  1062. }
  1063. //替换url,展示图片
  1064. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  1065. $scope.bigImage = true; //显示大图
  1066. };
  1067. $scope.cancelSupport = function () {
  1068. $scope.tosupport = false;
  1069. $scope.toshare = false;
  1070. };
  1071. $scope.toshare = false;
  1072. $scope.toRecharge = function(){
  1073. $state.go("app.recharge")
  1074. };
  1075. $scope.toDetail = function (dream_id) {
  1076. if($scope.items.near_dream==null){
  1077. msg.alert("当前梦想","该用户没有当前梦想");
  1078. }
  1079. if($scope.items.near_dream!=null){
  1080. var dream_id = $scope.items.near_dream.id;
  1081. if($location.path()=="/app/home/userDetail"){
  1082. $state.go('app.home_dreamdetail',{id:dream_id});
  1083. }
  1084. else {
  1085. $state.go('app.my_dreamdetail',{id:dream_id});
  1086. }
  1087. }
  1088. };
  1089. $scope.toOldDream = function(){
  1090. if($scope.items.dreams.length<2){
  1091. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  1092. }
  1093. if($scope.items.dreams.length>1){
  1094. if($location.path()=="/app/home/userDetail"){
  1095. $state.go('app.oldDream',{user_id:$scope.items.user.id});
  1096. }
  1097. else {
  1098. $state.go('app.myOldDream',{user_id:$scope.items.user.id});
  1099. }
  1100. }
  1101. };
  1102. $scope.toSupportDream = function(){
  1103. if($scope.items.sup_dreams.length==0){
  1104. msg.alert("支持的梦想","该用户没有支持的梦想");
  1105. }
  1106. if($scope.items.sup_dreams.length!=0){
  1107. if($scope.items.dreams.length>1){
  1108. if($location.path()=="/app/home/userDetail"){
  1109. $state.go('app.supportDream',{user_id:$scope.items.user.id});
  1110. }
  1111. else {
  1112. $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
  1113. }
  1114. }
  1115. }
  1116. };
  1117. $scope.collectionDream = function(is_collection){
  1118. homeService.collectionDream(id,is_collection).then(function(result){
  1119. $scope.user.is_collection=result.data.data;
  1120. })
  1121. };
  1122. }]);
  1123. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  1124. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  1125. $scope.$on('$ionicView.beforeEnter', function () {
  1126. $ionicTabsDelegate.showBar(false);
  1127. myService.collect().then(function(result){
  1128. $scope.dreams = result.data.data.dreams;
  1129. });
  1130. });
  1131. $scope.toDetail = function (id) {
  1132. $state.go('app.home_dreamdetail',{id:id});
  1133. };
  1134. }]);
  1135. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1136. , function ($scope,homeService,$stateParams, $state, msg) {
  1137. $scope.dream = $stateParams.item;
  1138. $scope.showAbout = true;
  1139. $scope.hideAbout = false;
  1140. $scope.showText = function(){
  1141. $scope.aboutStyle = {
  1142. "white-space" : "normal"
  1143. };
  1144. $scope.showAbout = false;
  1145. $scope.hideAbout = true;
  1146. };
  1147. $scope.hideText = function(){
  1148. $scope.aboutStyle = {
  1149. "white-space" : "nowrap"
  1150. };
  1151. $scope.showAbout = true;
  1152. $scope.hideAbout = false;
  1153. };
  1154. }]);
  1155. //app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  1156. // , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  1157. // $scope.$on('$ionicView.beforeEnter', function () {
  1158. // $ionicTabsDelegate.showBar(false);
  1159. // myService.messageInfo().then(function(result){
  1160. // $scope.infos = result.data.data;
  1161. // },function(error){
  1162. //
  1163. // });
  1164. // });
  1165. // $scope.notRead = function(){
  1166. // myService.notRead().then(function(result){
  1167. // myService.messageInfo().then(function(result){
  1168. // $scope.infos = result.data.data;
  1169. // },function(error){
  1170. //
  1171. // });
  1172. // },function(error){
  1173. //
  1174. // })
  1175. // };
  1176. // //系统消息
  1177. // $scope.systemInfo = function(){
  1178. // $state.go("app.message_sys");
  1179. // myService.systemInfo().then(function(result){
  1180. // },function(error){
  1181. //
  1182. // });
  1183. // };
  1184. // //回复我的
  1185. // $scope.replyMy = function(){
  1186. // $state.go("app.message_reply");
  1187. // myService.replyMy().then(function(result){
  1188. //
  1189. // },function(error){
  1190. //
  1191. // });
  1192. // };
  1193. // $scope.personalLetter = function(){
  1194. // $state.go("app.letter");
  1195. // }
  1196. // }]);
  1197. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1198. , function ($scope,homeService,$stateParams, $state, msg) {
  1199. var user_id = $stateParams.user_id;
  1200. $scope.$on('$ionicView.beforeEnter',function(){
  1201. $scope.toUserDetail(user_id);
  1202. });
  1203. $scope.toUserDetail = function(user_id){
  1204. homeService.toUserDetail(user_id).then(function(result){
  1205. $scope.items = result.data.data;
  1206. $scope.user = result.data.data.user;
  1207. $scope.dreams = $scope.user.dreams;
  1208. },function(error){
  1209. })
  1210. };
  1211. $scope.toDetail = function(id){
  1212. $state.go('app.home_dreamdetail',{id:id});
  1213. // $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1214. };
  1215. }]);
  1216. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1217. , function ($scope,homeService,$stateParams, $state, msg) {
  1218. var user_id = $stateParams.user_id;
  1219. $scope.$on('$ionicView.beforeEnter',function(){
  1220. $scope.toUserDetail(user_id);
  1221. });
  1222. $scope.toUserDetail = function(user_id){
  1223. homeService.toUserDetail(user_id).then(function(result){
  1224. $scope.items = result.data.data;
  1225. $scope.user = result.data.data.user;
  1226. $scope.dreams = $scope.user.sup_dream;
  1227. },function(error){
  1228. })
  1229. };
  1230. $scope.toDetail = function(id){
  1231. $state.go('app.home_dreamdetail',{id:id});
  1232. // $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1233. }
  1234. }]);
  1235. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1236. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1237. $scope.showMore = function (keyword,index) {
  1238. if(!keyword)return;
  1239. $scope.index = index;
  1240. $scope.search(keyword);
  1241. };
  1242. $scope.search = function (keyword) {
  1243. $scope.vm.keyword = keyword;
  1244. homeService.search(keyword).then(function(result){
  1245. $scope.isResult = true;
  1246. $scope.dream_infos = result.data.data.dream_infos;
  1247. $scope.user_infos = result.data.data.user_infos;
  1248. });
  1249. };
  1250. $scope.toUserDetail = function (id) {
  1251. homeService.toUserDetail(id).then(function(result){
  1252. $scope.items = result.data.data;
  1253. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1254. },function(error){
  1255. //msg.error(msg.data.error)
  1256. })
  1257. };
  1258. $scope.toDetail = function (id) {
  1259. $state.go('app.home_dreamdetail',{id:id});
  1260. };
  1261. $scope.$on('$ionicView.beforeEnter', function () {
  1262. $scope.isResult = false;
  1263. $scope.index = 0;
  1264. $scope.vm = {
  1265. keyword : ""
  1266. };
  1267. $ionicTabsDelegate.showBar(false);
  1268. // $ionicNavBarDelegate.showBackButton(false);
  1269. homeService.search('').then(function(result){
  1270. $scope.hot_searches = result.data.data.hot_searches;
  1271. $scope.history_searches = result.data.data.history_searches;
  1272. });
  1273. });
  1274. }]);
  1275. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1276. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1277. }]);
  1278. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1279. , function ($scope, $state, myService, msg) {
  1280. $scope.$on('$ionicView.beforeEnter', function () {
  1281. myService.myDream().then(function(result){
  1282. console.log(result.data.data);
  1283. $scope.dreams = result.data.data;
  1284. });
  1285. });
  1286. $scope.toDetail = function (id) {
  1287. $state.go('app.home_dreamdetail',{id:id});
  1288. };
  1289. }]);
  1290. app.controller('contactHomeCtrl', ["$scope","$ionicTabsDelegate","$stateParams","$location", "$ionicHistory","$timeout","$state", "myService", "msg","storage"
  1291. , function ($scope,$ionicTabsDelegate,$stateParams,$location,$ionicHistory, $timeout,$state,myService, msg, storage) {
  1292. $scope.user_name = $stateParams.user_name;
  1293. $scope.dream_id = $stateParams.dream_id;
  1294. $scope.dream_name = $stateParams.dream_name;
  1295. $scope.vm={
  1296. content:"",
  1297. email:""
  1298. };
  1299. $scope.contact = function(){
  1300. var data={
  1301. data:{
  1302. content: $scope.vm.content,
  1303. email: $scope.vm.email,
  1304. dream_id: $scope.dream_id
  1305. }
  1306. };
  1307. myService.contact(data).then(function(result){
  1308. msg.text("发送成功");
  1309. $timeout(function(){
  1310. if($location.path()=='/app/home/contact'){
  1311. $ionicHistory.goBack();
  1312. }
  1313. else{
  1314. $state.go("app.my");
  1315. }
  1316. },1000);
  1317. $scope.vm={
  1318. content:"",
  1319. email:""
  1320. }
  1321. },function(error){
  1322. msg.error(error.data.message);
  1323. })
  1324. }
  1325. }]);
  1326. })(angular.module('app.controllers'));