home.js 48 KB

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