home.js 44 KB

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