home.js 45 KB

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