home.js 43 KB

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