home.js 50 KB

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