home.js 46 KB

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