home.js 43 KB

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