home.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  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. });
  235. $scope.$on('$ionicView.beforeEnter', function () {
  236. $scope.video = {};
  237. msg.loading();
  238. $ionicTabsDelegate.showBar(false);
  239. $scope.load(id,dream_user_id,interaction_id);
  240. $scope.thisUser = storage.getObject('user');
  241. $scope.vm.payType = 2;
  242. homeService.myInfo().then(function(result){
  243. $scope.user = result.data.data;
  244. });
  245. homeService.messageInfo().then(function(result){
  246. $scope.infos = result.data.data;
  247. if($scope.infos.dream_info.number==0 && $scope.infos.sup_info.number==0 && $scope.infos.system_info.number==0){
  248. $scope.showMessage=0;
  249. }
  250. else {
  251. $scope.showMessage=1;
  252. }
  253. },function(error){
  254. });
  255. });
  256. $scope.toUserDetail = function (id) {
  257. homeService.toUserDetail(id).then(function(result){
  258. $scope.items = result.data.data;
  259. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  260. },function(error){
  261. //msg.error(msg.data.error)
  262. })
  263. };
  264. $scope.$on('$ionicView.leave', function () {
  265. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  266. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  267. });
  268. $scope.toSort = function(){
  269. //$scope.type = 3;
  270. $scope.changeType(3)
  271. };
  272. $scope.destroyInter = function(id,dream_id){
  273. msg.confirm("互动","是否删除该评论").then(function(result){
  274. if(result==true)
  275. {
  276. homeService.destroyInter(id).then(function(result){
  277. msg.text('删除成功');
  278. $scope.load(dream_id);
  279. },function(error){
  280. msg.error(error.data.message);
  281. });
  282. }
  283. });
  284. };
  285. $scope.load = function (id,dream_user_id,interaction_id) {
  286. homeService.dreamDetail(id,dream_user_id,interaction_id).then(function (result) {
  287. console.log(result);
  288. $scope.showCode = function(codeName){
  289. $scope.url = codeName;
  290. $scope.code = true;
  291. };
  292. $scope.hideCode = function(){
  293. $scope.code = false;
  294. };
  295. $scope.dream = result.data.data;
  296. //if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  297. // $scope.codeBtn = true;
  298. //}
  299. if($scope.timer=='已结束'){
  300. $scope.codeBtn = true;
  301. }
  302. if($scope.dream.video){
  303. if($scope.dream.video.indexOf('http')<0){
  304. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  305. $scope.dream.video = config.imgServer+$scope.dream.video;
  306. }
  307. else {
  308. //$scope.dream.vpic = $scope.dream.video+'upload/vpic/'+'.jpg';
  309. $scope.dream.vpic = $scope.dream.video.replace(/attachment/,'upload/vpic/')+'.jpg';
  310. $scope.dream.video = $scope.dream.video;
  311. }
  312. }
  313. var reg = new RegExp("\n", "g");
  314. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  315. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  316. var date = new Date();
  317. var inter = (end_time.getTime() - date.getTime()) / 1000;
  318. leftTimer(inter);
  319. $scope.multi.a = $scope.dream.a;
  320. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  321. $scope.multi.c = $scope.dream.c;
  322. $scope.multi.promise = $scope.dream.a;
  323. var newtop3user = '' ;
  324. angular.forEach($scope.dream.top3user, function(user) {
  325. newtop3user= newtop3user +user.id+","
  326. });
  327. if(top3user!=''&&newtop3user!=top3user){
  328. //测试动画切换
  329. $timeout(function() {
  330. $scope.sort.slide1 = 'list-grow-animation';
  331. $scope.sort.slide2 = 'slide-in-both-ways';
  332. $scope.sort.slide3 = 'bounce-animation';
  333. }, 50);
  334. }
  335. top3user = newtop3user;
  336. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  337. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  338. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  339. //$scope.calcmultiplier();
  340. msg.hide();
  341. }, function (error) {
  342. msg.hide();
  343. });
  344. };
  345. $scope.openSupport = function () {
  346. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  347. };
  348. $scope.multi = {
  349. a: '',
  350. b: '',
  351. c: '',
  352. result: 1,
  353. promise:null
  354. };
  355. $scope.tosupport = false;
  356. $scope.support = function ($event) {
  357. $event.stopPropagation();
  358. $scope.tosupport = true;
  359. $scope.vm.coin = 0;
  360. $scope.index = 0;
  361. };
  362. $scope.cancelSupport = function () {
  363. $scope.tosupport = false;
  364. $scope.toshare = false;
  365. $scope.input.show = false;
  366. };
  367. $scope.toshare = false;
  368. $scope.toRecharge = function(){
  369. $state.go("app.recharge")
  370. };
  371. $scope.share = function (type,$event) {
  372. $scope.toshare = true;
  373. if (type==0) {
  374. //分享给朋友
  375. Wechat.share({
  376. message: {
  377. title: $scope.dream.name,
  378. description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '\n' + $scope.dream.about,
  379. thumb: $scope.dream.imgs[0].pic,
  380. media: {
  381. type: Wechat.Type.WEBPAGE,
  382. webpageUrl: config.server + "/admin/share/view?id=" + id + '&user_id = ' + $scope.user.id
  383. }
  384. },
  385. scene: Wechat.Scene.SESSION
  386. }, function () {
  387. //msg.alert('分享','分享成功');
  388. msg.success('分享成功');
  389. }, function (reason) {
  390. //msg.alert('分享','分享失败');
  391. msg.error('分享失败');
  392. });
  393. }
  394. if(type==1){
  395. Wechat.share({
  396. message: {
  397. title: $scope.dream.name,
  398. description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '\n' + $scope.dream.about,
  399. thumb: $scope.dream.imgs[0].pic,
  400. media: {
  401. type: Wechat.Type.WEBPAGE,
  402. webpageUrl: config.server + "/admin/share/view?id=" + id
  403. }
  404. },
  405. scene: Wechat.Scene.TIMELINE
  406. }, function () {
  407. msg.success('分享成功');
  408. }, function (reason) {
  409. msg.error('分享失败');
  410. });
  411. }
  412. };
  413. //实时排行
  414. $scope.sort = {
  415. slide: ''
  416. };
  417. $scope.changeType = function (type) {
  418. $ionicScrollDelegate.scrollTop(true);
  419. $scope.type = type;
  420. };
  421. $scope.index = 0;
  422. $scope.vm = {
  423. coin:"",
  424. title:""
  425. };
  426. $scope.timer = '';
  427. var leftTimer = function (countDown) {
  428. if (isNaN(countDown)) {
  429. $scope.timer = '已结束';
  430. return;
  431. }
  432. var day=parseInt(countDown/(24*60*60));
  433. var h=parseInt(countDown/(60*60)%24);
  434. var m=parseInt(countDown/60%60);
  435. var s=parseInt(countDown%60);
  436. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  437. if(day>0) $scope.timer = day+'天';
  438. if(day<0 && h>0) $scope.timer = h+'小时';
  439. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  440. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  441. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  442. $scope.leftTimer = $interval(function () {
  443. if (countDown >= 1) leftTimer(countDown - 1);
  444. },1000);*/
  445. /*if(countDown<=0){
  446. $scope.timer='结束';
  447. }*/
  448. };
  449. $scope.changeIndex = function (index) {
  450. $scope.index = index;
  451. $scope.vm.coin = index*10;
  452. };
  453. $scope.vidEnded = function () {
  454. alert('播放完毕');
  455. };
  456. //实时计算支持乘数
  457. //$scope.calcmultiplier = function () {
  458. // $scope.multi.promise = $interval(function () {
  459. //
  460. // var date = new Date();
  461. // var inter = date.getTime() - $scope.multi.b.getTime();
  462. // var minutes = Math.floor(inter / (60 * 1000));
  463. // var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  464. // if (number<=1) {
  465. // number = 1;
  466. // }
  467. // $scope.multi.result = Math.round(number * 100 / 100);
  468. // },1000);
  469. //};
  470. $scope.supportDream = function (data) {
  471. if(!$scope.vm.coin){
  472. msg.error("请选择梦想币数量!");
  473. return ;
  474. }
  475. var data = {
  476. id:id,
  477. coin:$scope.vm.coin
  478. };
  479. homeService.supportDream(data).then(function(result){
  480. $scope.tosupport = false;
  481. $scope.load(id);
  482. homeService.myInfo().then(function(result){
  483. $scope.user = result.data.data;
  484. });
  485. $interval.cancel($scope.multi.promise);
  486. msg.text("发送成功",1000);
  487. //$ionicLoading.show({template:'发送成功'});
  488. //$timeout(function(){
  489. // debugger;
  490. // $ionicLoading.hide();
  491. //}, 20000);
  492. });
  493. };
  494. $scope.collectionDream = function(is_collection){
  495. homeService.collectionDream(id,is_collection).then(function(result){
  496. $scope.dream.is_collection=result.data.data;
  497. })
  498. };
  499. $scope.add = function(is_collection){
  500. var data = {
  501. id:id,
  502. title:$scope.vm.title,
  503. pics:$scope.imgs,
  504. video:$scope.video.file
  505. };
  506. homeService.add_interaction(data).then(function(){
  507. $scope.load(id);
  508. $scope.closeModal();
  509. })
  510. };
  511. $scope.showAbout = true;
  512. $scope.hideAbout = false;
  513. $scope.showText = function(){
  514. $scope.aboutStyle = {
  515. "white-space" : "normal"
  516. };
  517. $scope.showAbout = false;
  518. $scope.hideAbout = true;
  519. };
  520. $scope.hideText = function(){
  521. $scope.aboutStyle = {
  522. "white-space" : "nowrap"
  523. };
  524. $scope.showAbout = true;
  525. $scope.hideAbout = false;
  526. };
  527. $scope.input = {
  528. placeholder: '评论',
  529. focus: false,
  530. show:false
  531. };
  532. $scope.showmore = function (index) {
  533. if ($scope.dream.interactions[index].showmore) {
  534. $scope.dream.interactions[index].showmore = false;
  535. } else {
  536. $scope.dream.interactions[index].showmore = true;
  537. }
  538. };
  539. $scope.replay = function ($event, name, to_userid, index) {
  540. $event.stopPropagation();
  541. $scope.input.focus = true;
  542. $scope.input.show = true;
  543. angular.forEach($scope.dream.interactions, function (item) {
  544. item.show = false;
  545. });
  546. $scope.dream.interactions[index].show = true;
  547. $scope.dream.interactions[index].focus = true;
  548. $scope.input.placeholder = "评论" + name+":";
  549. $scope.to_userid = to_userid;
  550. $scope.vm.title='';
  551. $scope.vm.comment='';
  552. };
  553. $scope.replayOther = function ($event, name, to_userid, index,currentindex) {
  554. $event.stopPropagation();
  555. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  556. $scope.input.focus = true;
  557. $scope.input.show = true;
  558. angular.forEach($scope.dream.interactions, function (item) {
  559. item.show = false;
  560. });
  561. $scope.dream.interactions[index].show = true;
  562. $scope.dream.interactions[index].focus = true;
  563. $scope.input.placeholder = "评论" + name;
  564. $scope.to_userid = to_userid;
  565. $scope.vm.title='';
  566. $scope.vm.comment='';
  567. }
  568. else if($scope.timer!='已结束') {
  569. msg.confirm("评论","是否删除评论").then(function(result){
  570. if(result==true)
  571. {
  572. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  573. msg.text("删除成功");
  574. $scope.load(id);
  575. },function(error){
  576. msg.error(error.data.message);
  577. })
  578. }
  579. });
  580. }
  581. };
  582. //充值
  583. $scope.charge = function(number){
  584. if (!number) {
  585. msg.text('请输入充值金额');
  586. return;
  587. }
  588. homeService.charge(number,2).then(function (result) {
  589. //todo:result需要返回支付宝或者微信的签名信息
  590. console.log("result: " + JSON.stringify(result));
  591. var payInfo = result.data.data;
  592. if ($scope.vm.payType == 1) { //支付宝
  593. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  594. $scope.clicksub = false;
  595. if (e.resultStatus == '9000') {
  596. alert(orderID);
  597. $timeout(function () {
  598. $scope.closeRechargeModal();
  599. }, 1000);
  600. homeService.myInfo().then(function (result) {
  601. $scope.user = result.data.data;
  602. });
  603. } else {
  604. msg.error("支付失败");
  605. // msg.error("支付失败:" + JSON.stringify(e));
  606. }
  607. }, function error(e) {
  608. $scope.clicksub = false;
  609. // msg.error("支付失败:" + JSON.stringify(e));
  610. msg.error("支付失败");
  611. });
  612. }
  613. if ($scope.vm.payType == 2) { //微信
  614. // var obj = JSON.parse(payInfo);
  615. var obj = payInfo.orderString;
  616. // console.log("obj: " + JSON.stringify(obj));
  617. var params = {
  618. partnerid: obj.partnerid, // merchant id
  619. prepayid: obj.prepayid, // prepay id
  620. noncestr: obj.noncestr, // nonce
  621. timestamp: obj.timestamp, // timestamp
  622. sign: obj.sign, // signed string
  623. };
  624. // console.log("result: " + JSON.stringify(params));
  625. Wechat.sendPaymentRequest(params, function (r) {
  626. // $scope.clicksub = false;
  627. $timeout(function () {
  628. $scope.closeRechargeModal();
  629. }, 1000);
  630. $scope.load(id,dream_user_id,interaction_id);
  631. // courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  632. // homeService.myInfo().then(function (result) {
  633. // $scope.user = result.data.data;
  634. // });
  635. // }, function (erro) {
  636. // // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  637. // });
  638. }, function (reason) {
  639. $scope.clicksub = false;
  640. // msg.alert("支付失败:" + JSON.stringify(reason));
  641. });
  642. }
  643. });
  644. };
  645. $scope.submitComment = function (index,to_userid) {
  646. var interaction = $scope.dream.interactions[index];
  647. var iid = interaction.id;
  648. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  649. $scope.input.focus = true;
  650. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  651. var data = {
  652. id:iid,
  653. content:$scope.vm.comment,
  654. comment_user_id:to_userid,
  655. to_user_id: $scope.dream.user.id
  656. };
  657. if($scope.timer=='已结束'){
  658. msg.alert("评论","该梦想已结束,不支持评论");
  659. }
  660. else {
  661. homeService.add_comment(data).then(function(){
  662. msg.success('评论成功');
  663. $scope.vm.comment = '' ;
  664. $scope.load(id);
  665. $scope.closeModal();
  666. });
  667. }
  668. };
  669. $scope.bigImage = false;
  670. $scope.showBigImage = function ($event, imageName) {
  671. $event.stopPropagation();
  672. $scope.url = imageName;
  673. $scope.bigImage = true;
  674. };
  675. $scope.hideBigImage = function(){
  676. $scope.bigImage = false;
  677. };
  678. $ionicModal.fromTemplateUrl('qrCode.html', {
  679. scope: $scope,
  680. animation: 'slide-in-up'
  681. }).then(function(modal) {
  682. $scope.qrCodemodal = modal;
  683. });
  684. $scope.openCode = function($event) {
  685. $event.stopPropagation();
  686. $scope.qrCodemodal.show();
  687. $scope.vm.money = '';
  688. };
  689. $scope.closeCode = function() {
  690. $scope.qrCodemodal.hide();
  691. };
  692. $ionicModal.fromTemplateUrl('commentPic.html', {
  693. scope: $scope,
  694. animation: 'slide-in-up'
  695. }).then(function(modal) {
  696. $scope.CommentPicmodal = modal;
  697. });
  698. $scope.openCommentPic = function(pic,$event) {
  699. $event.stopPropagation();
  700. $scope.CommentPicmodal.show();
  701. $scope.commentPicUrl = pic;
  702. };
  703. $scope.closeCommentPic = function() {
  704. $scope.CommentPicmodal.hide();
  705. };
  706. $scope.addpict = function () {
  707. common.chooseImage().then(function (img) {
  708. common.uploadFiles(img,1).then(function (result) {
  709. var response = JSON.parse(result.response);
  710. var file = config.imgServer + response.data.file;
  711. $scope.imgs.push(file);
  712. }, function (error) {
  713. msg.error('图片上传失败');
  714. });
  715. }, function (error) {
  716. console.log('图片选择失败');
  717. });
  718. };
  719. $scope.deletefile = function (file) {
  720. var index = $scope.imgs.indexOf(file);
  721. $scope.imgs.splice(index, 1);
  722. common.deletefile(file).then(function () {
  723. })
  724. };
  725. $scope.addvideo = function () {
  726. common.chooseVideo().then(function (file) {
  727. msg.loading();
  728. common.uploadFiles(file, 2).then(function (result) {
  729. msg.hide();
  730. var response = JSON.parse(result.response);
  731. $scope.video.server = response.data.file;
  732. var file = config.imgServer+response.data.file;
  733. $scope.video.isOK = true;
  734. $scope.video.file = response.data.file;
  735. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  736. }, function (error) {
  737. //msg.error('视频上传失败');
  738. msg.hide();
  739. });
  740. }, function (erro) {
  741. console.log('选择视频失败');
  742. });
  743. };
  744. $scope.deletevideo = function (file) {
  745. $scope.video = {};
  746. common.deletefile(file).then(function (res) {
  747. },function(erro){
  748. alert(JSON.stringify(erro));
  749. })
  750. };
  751. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  752. scope: $scope,
  753. animation: 'slide-in-up'
  754. }).then(function(modal) {
  755. $scope.rechagemodal = modal;
  756. });
  757. $scope.openRechargeModal = function() {
  758. $scope.rechagemodal.show();
  759. $scope.vm.money = '';
  760. };
  761. $scope.closeRechargeModal = function() {
  762. $scope.rechagemodal.hide();
  763. };
  764. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  765. scope: $scope,
  766. animation: 'slide-in-up'
  767. }).then(function(modal) {
  768. $scope.modal = modal;
  769. });
  770. $scope.openModal = function() {
  771. $scope.modal.show();
  772. $scope.vm.title = '';
  773. $scope.imgs = [];
  774. $scope.video = {};
  775. };
  776. $scope.closeModal = function() {
  777. $scope.modal.hide();
  778. };
  779. //当我们用到模型时,清除它!
  780. $scope.$on('$destroy', function() {
  781. $scope.modal.remove();
  782. });
  783. $scope.toMessage = function(){
  784. if($location.path()=="/app/home/dreamdetail"){
  785. $state.go("app.message");
  786. }
  787. else {
  788. $state.go("app.my_message");
  789. }
  790. }
  791. }]);
  792. app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  793. , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  794. var id = $stateParams.id;
  795. $scope.items = $stateParams.items;
  796. $scope.$on('$ionicView.beforeEnter', function () {
  797. $ionicTabsDelegate.showBar(false);
  798. });
  799. $scope.attentionUser = function(is_care){
  800. homeService.attentionUser(id,is_care).then(function(result){
  801. $scope.items.is_care=result.data.data;
  802. })
  803. };
  804. $scope.next = function (type) {
  805. //type:1 前一个,type:2 后一个
  806. if($scope.items.imgs.length>0){
  807. if(type==1)
  808. {
  809. var temp= $scope.items.imgs.splice(0,1);
  810. $scope.items.imgs.push(temp[0]);
  811. }
  812. if (type==2){
  813. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  814. $scope.items.imgs.unshift(temp[0]);
  815. }
  816. }
  817. };
  818. $scope.bigImage = false;
  819. $scope.showBigImage = function(imageName,imageIndex){
  820. $scope.url = imageName;
  821. $scope.imageIndex = imageIndex;
  822. $scope.bigImage = true;
  823. };
  824. $scope.hideBigImage = function(){
  825. $scope.bigImage = false;
  826. };
  827. $scope.swipeLeft = function (imageIndex) {
  828. if ($scope.imageIndex < $scope.items.imgs.length - 1 && $scope.imageIndex >= 0)
  829. $scope.imageIndex = $scope.imageIndex + 1;
  830. else {
  831. //如果图片已经是最后一张图片了,则取index = 0
  832. $scope.imageIndex = 0;
  833. }
  834. //替换url,展示图片
  835. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  836. $scope.bigImage = true; //显示大图
  837. };
  838. $scope.swipeRight = function (imageIndex) {
  839. if ($scope.imageIndex <= $scope.items.imgs.length - 1 && $scope.imageIndex > 0)
  840. $scope.imageIndex = $scope.imageIndex - 1;
  841. else {
  842. //如果图片已经是第一张图片了,则取index = Images.length-1
  843. $scope.imageIndex = $scope.items.imgs.length - 1;
  844. }
  845. //替换url,展示图片
  846. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  847. $scope.bigImage = true; //显示大图
  848. };
  849. $scope.cancelSupport = function () {
  850. $scope.tosupport = false;
  851. $scope.toshare = false;
  852. };
  853. $scope.toshare = false;
  854. $scope.toshare = false;
  855. $scope.toRecharge = function(){
  856. $state.go("app.recharge")
  857. };
  858. $scope.toDetail = function (dream_id) {
  859. if($scope.items.near_dream==null){
  860. msg.alert("当前梦想","该用户没有当前梦想");
  861. }
  862. if($scope.items.near_dream!=null){
  863. var dream_id = $scope.items.near_dream.id;
  864. if($location.path()=="/app/home/userDetail"){
  865. $state.go('app.home_dreamdetail',{id:dream_id});
  866. }
  867. else {
  868. $state.go('app.my_dreamdetail',{id:dream_id});
  869. }
  870. }
  871. };
  872. $scope.toOldDream = function(){
  873. if($scope.items.dreams.length<2){
  874. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  875. }
  876. if($scope.items.dreams.length>1){
  877. if($location.path()=="/app/home/userDetail"){
  878. $state.go('app.oldDream',{user_id:$scope.items.user.id});
  879. }
  880. else {
  881. $state.go('app.myOldDream',{user_id:$scope.items.user.id});
  882. }
  883. }
  884. };
  885. $scope.toSupportDream = function(){
  886. if($scope.items.sup_dreams.length==0){
  887. msg.alert("支持的梦想","该用户没有支持的梦想");
  888. }
  889. if($scope.items.sup_dreams.length!=0){
  890. if($scope.items.dreams.length>1){
  891. if($location.path()=="/app/home/userDetail"){
  892. $state.go('app.supportDream',{user_id:$scope.items.user.id});
  893. }
  894. else {
  895. $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
  896. }
  897. }
  898. }
  899. };
  900. $scope.collectionDream = function(is_collection){
  901. homeService.collectionDream(id,is_collection).then(function(result){
  902. $scope.user.is_collection=result.data.data;
  903. })
  904. };
  905. }]);
  906. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  907. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  908. $scope.$on('$ionicView.beforeEnter', function () {
  909. $ionicTabsDelegate.showBar(false);
  910. myService.collect().then(function(result){
  911. $scope.dreams = result.data.data.dreams;
  912. });
  913. });
  914. $scope.toDetail = function (id) {
  915. $state.go('app.home_dreamdetail',{id:id});
  916. };
  917. }]);
  918. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  919. , function ($scope,homeService,$stateParams, $state, msg) {
  920. $scope.dream = $stateParams.item;
  921. $scope.showAbout = true;
  922. $scope.hideAbout = false;
  923. $scope.showText = function(){
  924. $scope.aboutStyle = {
  925. "white-space" : "normal"
  926. };
  927. $scope.showAbout = false;
  928. $scope.hideAbout = true;
  929. };
  930. $scope.hideText = function(){
  931. $scope.aboutStyle = {
  932. "white-space" : "nowrap"
  933. };
  934. $scope.showAbout = true;
  935. $scope.hideAbout = false;
  936. };
  937. }]);
  938. //app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  939. // , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  940. // $scope.$on('$ionicView.beforeEnter', function () {
  941. // $ionicTabsDelegate.showBar(false);
  942. // myService.messageInfo().then(function(result){
  943. // $scope.infos = result.data.data;
  944. // },function(error){
  945. //
  946. // });
  947. // });
  948. // $scope.notRead = function(){
  949. // myService.notRead().then(function(result){
  950. // myService.messageInfo().then(function(result){
  951. // $scope.infos = result.data.data;
  952. // },function(error){
  953. //
  954. // });
  955. // },function(error){
  956. //
  957. // })
  958. // };
  959. // //系统消息
  960. // $scope.systemInfo = function(){
  961. // $state.go("app.message_sys");
  962. // myService.systemInfo().then(function(result){
  963. // },function(error){
  964. //
  965. // });
  966. // };
  967. // //回复我的
  968. // $scope.replyMy = function(){
  969. // $state.go("app.message_reply");
  970. // myService.replyMy().then(function(result){
  971. //
  972. // },function(error){
  973. //
  974. // });
  975. // };
  976. // $scope.personalLetter = function(){
  977. // $state.go("app.letter");
  978. // }
  979. // }]);
  980. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  981. , function ($scope,homeService,$stateParams, $state, msg) {
  982. var user_id = $stateParams.user_id;
  983. $scope.$on('$ionicView.beforeEnter',function(){
  984. $scope.toUserDetail(user_id);
  985. });
  986. $scope.toUserDetail = function(user_id){
  987. homeService.toUserDetail(user_id).then(function(result){
  988. $scope.items = result.data.data;
  989. $scope.user = result.data.data.user;
  990. $scope.dreams = $scope.user.dreams;
  991. },function(error){
  992. })
  993. };
  994. $scope.toDetail = function(){
  995. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  996. };
  997. }]);
  998. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  999. , function ($scope,homeService,$stateParams, $state, msg) {
  1000. var user_id = $stateParams.user_id;
  1001. $scope.$on('$ionicView.beforeEnter',function(){
  1002. $scope.toUserDetail(user_id);
  1003. });
  1004. $scope.toUserDetail = function(user_id){
  1005. homeService.toUserDetail(user_id).then(function(result){
  1006. $scope.items = result.data.data;
  1007. $scope.user = result.data.data.user;
  1008. $scope.dreams = $scope.user.sup_dream;
  1009. },function(error){
  1010. })
  1011. };
  1012. $scope.toDetail = function(){
  1013. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1014. }
  1015. }]);
  1016. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1017. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1018. $scope.showMore = function (keyword,index) {
  1019. if(!keyword)return;
  1020. $scope.index = index;
  1021. $scope.search(keyword);
  1022. };
  1023. $scope.search = function (keyword) {
  1024. $scope.vm.keyword = keyword;
  1025. homeService.search(keyword).then(function(result){
  1026. $scope.isResult = true;
  1027. $scope.dream_infos = result.data.data.dream_infos;
  1028. $scope.user_infos = result.data.data.user_infos;
  1029. });
  1030. };
  1031. $scope.toUserDetail = function (id) {
  1032. homeService.toUserDetail(id).then(function(result){
  1033. $scope.items = result.data.data;
  1034. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1035. },function(error){
  1036. //msg.error(msg.data.error)
  1037. })
  1038. };
  1039. $scope.toDetail = function (id) {
  1040. $state.go('app.home_dreamdetail',{id:id});
  1041. };
  1042. $scope.$on('$ionicView.beforeEnter', function () {
  1043. $scope.isResult = false;
  1044. $scope.index = 0;
  1045. $scope.vm = {
  1046. keyword : ""
  1047. };
  1048. $ionicTabsDelegate.showBar(false);
  1049. // $ionicNavBarDelegate.showBackButton(false);
  1050. homeService.search('').then(function(result){
  1051. $scope.hot_searches = result.data.data.hot_searches;
  1052. $scope.history_searches = result.data.data.history_searches;
  1053. });
  1054. });
  1055. }]);
  1056. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1057. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1058. }]);
  1059. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1060. , function ($scope, $state, myService, msg) {
  1061. $scope.$on('$ionicView.beforeEnter', function () {
  1062. myService.myDream().then(function(result){
  1063. console.log(result.data.data);
  1064. $scope.dreams = result.data.data;
  1065. });
  1066. });
  1067. $scope.toDetail = function (id) {
  1068. $state.go('app.home_dreamdetail',{id:id});
  1069. };
  1070. }]);
  1071. })(angular.module('app.controllers'));