home.js 47 KB

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