home.js 43 KB

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