home.js 47 KB

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