home.js 45 KB

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