home.js 44 KB

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