home.js 46 KB

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