home.js 43 KB

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