home.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. $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", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
  203. , function ($scope,$location, $ionicHistory,$timeout,$state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $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.beforeEnter', function () {
  225. msg.loading();
  226. $ionicTabsDelegate.showBar(false);
  227. $scope.load(id,dream_user_id,interaction_id);
  228. $scope.thisUser = storage.getObject('user');
  229. $scope.vm.payType = 2;
  230. homeService.myInfo().then(function(result){
  231. $scope.user = result.data.data;
  232. });
  233. homeService.messageInfo().then(function(result){
  234. $scope.infos = result.data.data;
  235. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  236. $scope.showMessage=0;
  237. }
  238. else {
  239. $scope.showMessage=1;
  240. }
  241. },function(error){
  242. });
  243. });
  244. $scope.toUserDetail = function (id) {
  245. homeService.toUserDetail(id).then(function(result){
  246. $scope.items = result.data.data;
  247. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  248. },function(error){
  249. //msg.error(msg.data.error)
  250. })
  251. };
  252. $scope.$on('$ionicView.leave', function () {
  253. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  254. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  255. });
  256. $scope.toSort = function(){
  257. //$scope.type = 3;
  258. $scope.changeType(3)
  259. };
  260. $scope.destroyInter = function(id,dream_id){
  261. msg.confirm("互动","是否删除该评论").then(function(result){
  262. if(result==true)
  263. {
  264. homeService.destroyInter(id).then(function(result){
  265. msg.text('删除成功');
  266. $scope.load(dream_id);
  267. },function(error){
  268. msg.error(error.data.message);
  269. });
  270. }
  271. });
  272. };
  273. $scope.load = function (id,dream_user_id,interaction_id) {
  274. homeService.dreamDetail(id,dream_user_id,interaction_id).then(function (result) {
  275. console.log(result);
  276. $scope.showCode = function(codeName){
  277. $scope.url = codeName;
  278. $scope.code = true;
  279. };
  280. $scope.hideCode = function(){
  281. $scope.code = false;
  282. };
  283. $scope.dream = result.data.data;
  284. //if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  285. // $scope.codeBtn = true;
  286. //}
  287. if($scope.timer=='已结束'){
  288. $scope.codeBtn = true;
  289. }
  290. if($scope.dream.video){
  291. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  292. $scope.dream.video = config.imgServer+$scope.dream.video;
  293. }
  294. var reg = new RegExp("\n", "g");
  295. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  296. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  297. var date = new Date();
  298. var inter = (end_time.getTime() - date.getTime()) / 1000;
  299. leftTimer(inter);
  300. $scope.multi.a = $scope.dream.a;
  301. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  302. $scope.multi.c = $scope.dream.c;
  303. $scope.multi.promise = $scope.dream.a;
  304. var newtop3user = '' ;
  305. angular.forEach($scope.dream.top3user, function(user) {
  306. newtop3user= newtop3user +user.id+","
  307. });
  308. if(top3user!=''&&newtop3user!=top3user){
  309. //测试动画切换
  310. $timeout(function() {
  311. $scope.sort.slide1 = 'list-grow-animation';
  312. $scope.sort.slide2 = 'slide-in-both-ways';
  313. $scope.sort.slide3 = 'bounce-animation';
  314. }, 50);
  315. }
  316. top3user = newtop3user;
  317. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  318. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  319. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  320. $scope.calcmultiplier();
  321. msg.hide();
  322. }, function (error) {
  323. msg.hide();
  324. });
  325. };
  326. $scope.openSupport = function () {
  327. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  328. };
  329. $scope.multi = {
  330. a: '',
  331. b: '',
  332. c: '',
  333. result: 1,
  334. promise:null
  335. };
  336. $scope.tosupport = false;
  337. $scope.support = function ($event) {
  338. $event.stopPropagation();
  339. $scope.tosupport = true;
  340. $scope.vm.coin = 0;
  341. $scope.index = 0;
  342. };
  343. $scope.cancelSupport = function () {
  344. $scope.tosupport = false;
  345. $scope.toshare = false;
  346. $scope.input.show = false;
  347. };
  348. $scope.toshare = false;
  349. $scope.toRecharge = function(){
  350. $state.go("app.recharge")
  351. };
  352. $scope.share = function (type,$event) {
  353. $scope.toshare = true;
  354. if (type==0) {
  355. //分享给朋友
  356. Wechat.share({
  357. message: {
  358. title: $scope.dream.name,
  359. description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '<br/>' + $scope.dream.about,
  360. thumb: "q8.9026.com/base/img/share/icon_cat_h.png",
  361. media: {
  362. type: Wechat.Type.WEBPAGE,
  363. webpageUrl: config.server + "/admin/share/view?id=" + id
  364. }
  365. },
  366. scene: Wechat.Scene.SESSION
  367. }, function () {
  368. alert("分享成功");
  369. }, function (reason) {
  370. alert("分享失败");
  371. });
  372. }
  373. if(type==1){
  374. Wechat.share({
  375. message: {
  376. title: $scope.dream.name,
  377. description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '<br/>' + $scope.dream.about,
  378. thumb: "q8.9026.com/base/img/share/icon_cat_h.png",
  379. media: {
  380. type: Wechat.Type.WEBPAGE,
  381. webpageUrl: config.server + "/admin/share/view?id=" + id
  382. }
  383. },
  384. scene: Wechat.Scene.TIMELINE
  385. }, function () {
  386. alert("分享","分享成功");
  387. }, function (reason) {
  388. alert("分享","分享失败");
  389. });
  390. }
  391. };
  392. //实时排行
  393. $scope.sort = {
  394. slide: ''
  395. };
  396. $scope.changeType = function (type) {
  397. $ionicScrollDelegate.scrollTop(true);
  398. $scope.type = type;
  399. };
  400. $scope.index = 0;
  401. $scope.vm = {
  402. coin:"",
  403. title:""
  404. };
  405. $scope.timer = '';
  406. var leftTimer = function (countDown) {
  407. if (isNaN(countDown)) {
  408. $scope.timer = '已结束';
  409. return;
  410. }
  411. var day=parseInt(countDown/(24*60*60));
  412. var h=parseInt(countDown/(60*60)%24);
  413. var m=parseInt(countDown/60%60);
  414. var s=parseInt(countDown%60);
  415. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  416. if(day>0) $scope.timer = day+'天';
  417. if(day<0 && h>0) $scope.timer = h+'小时';
  418. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  419. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  420. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  421. $scope.leftTimer = $interval(function () {
  422. if (countDown >= 1) leftTimer(countDown - 1);
  423. },1000);*/
  424. /*if(countDown<=0){
  425. $scope.timer='结束';
  426. }*/
  427. };
  428. $scope.changeIndex = function (index) {
  429. $scope.index = index;
  430. $scope.vm.coin = index*10;
  431. };
  432. $scope.vidEnded = function () {
  433. alert('播放完毕');
  434. };
  435. //实时计算支持乘数
  436. $scope.calcmultiplier = function () {
  437. $scope.multi.promise = $interval(function () {
  438. var date = new Date();
  439. var inter = date.getTime() - $scope.multi.b.getTime();
  440. var minutes = Math.floor(inter / (60 * 1000));
  441. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  442. if (number<=1) {
  443. number = 1;
  444. }
  445. $scope.multi.result = Math.round(number * 100 / 100);
  446. },1000);
  447. };
  448. $scope.supportDream = function (data) {
  449. if(!$scope.vm.coin){
  450. msg.error("请选择梦想币数量!");
  451. return ;
  452. }
  453. var data = {
  454. id:id,
  455. coin:$scope.vm.coin
  456. };
  457. homeService.supportDream(data).then(function(result){
  458. $scope.tosupport = false;
  459. $scope.load(id);
  460. homeService.myInfo().then(function(result){
  461. $scope.user = result.data.data;
  462. });
  463. $interval.cancel($scope.multi.promise);
  464. msg.text("发送成功");
  465. });
  466. };
  467. $scope.collectionDream = function(is_collection){
  468. homeService.collectionDream(id,is_collection).then(function(result){
  469. $scope.dream.is_collection=result.data.data;
  470. })
  471. };
  472. $scope.add = function(is_collection){
  473. var data = {
  474. id:id,
  475. title:$scope.vm.title,
  476. pics:$scope.imgs,
  477. video:$scope.video.file
  478. };
  479. homeService.add_interaction(data).then(function(){
  480. $scope.load(id);
  481. $scope.closeModal();
  482. })
  483. };
  484. $scope.showAbout = true;
  485. $scope.hideAbout = false;
  486. $scope.showText = function(){
  487. $scope.aboutStyle = {
  488. "white-space" : "normal"
  489. };
  490. $scope.showAbout = false;
  491. $scope.hideAbout = true;
  492. };
  493. $scope.hideText = function(){
  494. $scope.aboutStyle = {
  495. "white-space" : "nowrap"
  496. };
  497. $scope.showAbout = true;
  498. $scope.hideAbout = false;
  499. };
  500. $scope.input = {
  501. placeholder: '评论',
  502. focus: false,
  503. show:false
  504. };
  505. $scope.showmore = function (index) {
  506. if ($scope.dream.interactions[index].showmore) {
  507. $scope.dream.interactions[index].showmore = false;
  508. } else {
  509. $scope.dream.interactions[index].showmore = true;
  510. }
  511. };
  512. $scope.replay = function ($event, name, to_userid, index) {
  513. $event.stopPropagation();
  514. $scope.input.focus = true;
  515. $scope.input.show = true;
  516. angular.forEach($scope.dream.interactions, function (item) {
  517. item.show = false;
  518. });
  519. $scope.dream.interactions[index].show = true;
  520. $scope.dream.interactions[index].focus = true;
  521. $scope.input.placeholder = "评论" + name+":";
  522. $scope.to_userid = to_userid;
  523. $scope.vm.title='';
  524. $scope.vm.comment='';
  525. };
  526. $scope.replayOther = function ($event, name, to_userid, index,currentindex) {
  527. $event.stopPropagation();
  528. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  529. $scope.input.focus = true;
  530. $scope.input.show = true;
  531. angular.forEach($scope.dream.interactions, function (item) {
  532. item.show = false;
  533. });
  534. $scope.dream.interactions[index].show = true;
  535. $scope.dream.interactions[index].focus = true;
  536. $scope.input.placeholder = "评论" + name;
  537. $scope.to_userid = to_userid;
  538. $scope.vm.title='';
  539. $scope.vm.comment='';
  540. }
  541. else if($scope.timer!='已结束') {
  542. msg.confirm("评论","是否删除评论").then(function(result){
  543. if(result==true)
  544. {
  545. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  546. msg.text("删除成功");
  547. $scope.load(id);
  548. },function(error){
  549. msg.error(error.data.message);
  550. })
  551. }
  552. });
  553. }
  554. };
  555. //充值
  556. $scope.charge = function(number){
  557. if (!number) {
  558. msg.text('请输入充值金额');
  559. return;
  560. }
  561. homeService.charge(number,2).then(function (result) {
  562. //todo:result需要返回支付宝或者微信的签名信息
  563. console.log("result: " + JSON.stringify(result));
  564. var payInfo = result.data.data;
  565. if ($scope.vm.payType == 1) { //支付宝
  566. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  567. $scope.clicksub = false;
  568. if (e.resultStatus == '9000') {
  569. alert(orderID);
  570. $timeout(function () {
  571. $scope.closeRechargeModal();
  572. }, 500);
  573. homeService.myInfo().then(function (result) {
  574. $scope.user = result.data.data;
  575. });
  576. } else {
  577. msg.error("支付失败");
  578. // msg.error("支付失败:" + JSON.stringify(e));
  579. }
  580. }, function error(e) {
  581. $scope.clicksub = false;
  582. // msg.error("支付失败:" + JSON.stringify(e));
  583. msg.error("支付失败");
  584. });
  585. }
  586. if ($scope.vm.payType == 2) { //微信
  587. // var obj = JSON.parse(payInfo);
  588. var obj = payInfo.orderString;
  589. // console.log("obj: " + JSON.stringify(obj));
  590. var params = {
  591. partnerid: obj.partnerid, // merchant id
  592. prepayid: obj.prepayid, // prepay id
  593. noncestr: obj.noncestr, // nonce
  594. timestamp: obj.timestamp, // timestamp
  595. sign: obj.sign, // signed string
  596. };
  597. // console.log("result: " + JSON.stringify(params));
  598. Wechat.sendPaymentRequest(params, function (r) {
  599. $scope.clicksub = false;
  600. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  601. $timeout(function () {
  602. $scope.closeRechargeModal();
  603. }, 500);
  604. homeService.myInfo().then(function (result) {
  605. $scope.user = result.data.data;
  606. });
  607. }, function (erro) {
  608. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  609. });
  610. }, function (reason) {
  611. $scope.clicksub = false;
  612. // msg.alert("支付失败:" + JSON.stringify(reason));
  613. });
  614. }
  615. });
  616. };
  617. $scope.submitComment = function (index,to_userid) {
  618. var interaction = $scope.dream.interactions[index];
  619. var iid = interaction.id;
  620. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  621. $scope.input.focus = true;
  622. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  623. var data = {
  624. id:iid,
  625. content:$scope.vm.comment,
  626. comment_user_id:to_userid,
  627. to_user_id: $scope.dream.user.id
  628. };
  629. if($scope.timer=='已结束'){
  630. msg.alert("评论","该梦想已结束,不支持评论");
  631. }
  632. else {
  633. homeService.add_comment(data).then(function(){
  634. msg.success('评论成功');
  635. $scope.vm.comment = '' ;
  636. $scope.load(id);
  637. $scope.closeModal();
  638. });
  639. }
  640. };
  641. $scope.bigImage = false;
  642. $scope.showBigImage = function ($event, imageName) {
  643. $event.stopPropagation();
  644. $scope.url = imageName;
  645. $scope.bigImage = true;
  646. };
  647. $scope.hideBigImage = function(){
  648. $scope.bigImage = false;
  649. };
  650. $ionicModal.fromTemplateUrl('qrCode.html', {
  651. scope: $scope,
  652. animation: 'slide-in-up'
  653. }).then(function(modal) {
  654. $scope.qrCodemodal = modal;
  655. });
  656. $scope.openCode = function($event) {
  657. $event.stopPropagation();
  658. $scope.qrCodemodal.show();
  659. $scope.vm.money = '';
  660. };
  661. $scope.closeCode = function() {
  662. $scope.qrCodemodal.hide();
  663. };
  664. $ionicModal.fromTemplateUrl('commentPic.html', {
  665. scope: $scope,
  666. animation: 'slide-in-up'
  667. }).then(function(modal) {
  668. $scope.CommentPicmodal = modal;
  669. });
  670. $scope.openCommentPic = function(pic,$event) {
  671. $event.stopPropagation();
  672. $scope.CommentPicmodal.show();
  673. $scope.commentPicUrl = pic;
  674. };
  675. $scope.closeCommentPic = function() {
  676. $scope.CommentPicmodal.hide();
  677. };
  678. $scope.addpict = function () {
  679. common.chooseImage().then(function (img) {
  680. common.uploadFiles(img,1).then(function (result) {
  681. var response = JSON.parse(result.response);
  682. var file = config.imgServer + response.data.file;
  683. $scope.imgs.push(file);
  684. }, function (error) {
  685. msg.error('图片上传失败');
  686. });
  687. }, function (error) {
  688. console.log('图片选择失败');
  689. });
  690. };
  691. $scope.deletefile = function (file) {
  692. var index = $scope.imgs.indexOf(file);
  693. $scope.imgs.splice(index, 1);
  694. common.deletefile(file).then(function () {
  695. })
  696. };
  697. $scope.addvideo = function () {
  698. common.chooseVideo().then(function (file) {
  699. common.uploadFiles(file, 2).then(function (result) {
  700. var response = JSON.parse(result.response);
  701. var file = config.imgServer+response.data.file;
  702. //console.log("file:"+file);
  703. $scope.video.isOK = true;
  704. $scope.video.file = response.data.file;
  705. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  706. //console.log("vpic:"+$scope.video.vpic);
  707. }, function (error) {
  708. msg.error('视频上传失败');
  709. });
  710. }, function (erro) {
  711. console.log('选择视频失败');
  712. });
  713. };
  714. $scope.deletevideo = function (file) {
  715. common.deletefile(file).then(function () {
  716. })
  717. };
  718. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  719. scope: $scope,
  720. animation: 'slide-in-up'
  721. }).then(function(modal) {
  722. $scope.rechagemodal = modal;
  723. });
  724. $scope.openRechargeModal = function() {
  725. $scope.rechagemodal.show();
  726. $scope.vm.money = '';
  727. };
  728. $scope.closeRechargeModal = function() {
  729. $scope.rechagemodal.hide();
  730. };
  731. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  732. scope: $scope,
  733. animation: 'slide-in-up'
  734. }).then(function(modal) {
  735. $scope.modal = modal;
  736. });
  737. $scope.openModal = function() {
  738. $scope.modal.show();
  739. $scope.vm.title = '';
  740. $scope.imgs = [];
  741. $scope.video = {};
  742. };
  743. $scope.closeModal = function() {
  744. $scope.modal.hide();
  745. };
  746. //当我们用到模型时,清除它!
  747. $scope.$on('$destroy', function() {
  748. $scope.modal.remove();
  749. });
  750. $scope.toMessage = function(){
  751. if($location.path()=="/app/home/dreamdetail"){
  752. $state.go("app.message");
  753. }
  754. else {
  755. $state.go("app.my_message");
  756. }
  757. }
  758. }]);
  759. app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  760. , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  761. var id = $stateParams.id;
  762. $scope.items = $stateParams.items;
  763. $scope.$on('$ionicView.beforeEnter', function () {
  764. $ionicTabsDelegate.showBar(false);
  765. });
  766. $scope.attentionUser = function(is_care){
  767. homeService.attentionUser(id,is_care).then(function(result){
  768. $scope.items.is_care=result.data.data;
  769. })
  770. };
  771. $scope.next = function (type) {
  772. //type:1 前一个,type:2 后一个
  773. if($scope.items.imgs.length>0){
  774. if(type==1)
  775. {
  776. var temp= $scope.items.imgs.splice(0,1);
  777. $scope.items.imgs.push(temp[0]);
  778. }
  779. if (type==2){
  780. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  781. $scope.items.imgs.unshift(temp[0]);
  782. }
  783. }
  784. };
  785. $scope.bigImage = false;
  786. $scope.showBigImage = function(imageName,imageIndex){
  787. $scope.url = imageName;
  788. $scope.imageIndex = imageIndex;
  789. $scope.bigImage = true;
  790. };
  791. $scope.hideBigImage = function(){
  792. $scope.bigImage = false;
  793. };
  794. $scope.swipeLeft = function (imageIndex) {
  795. if ($scope.imageIndex < $scope.items.imgs.length - 1 && $scope.imageIndex >= 0)
  796. $scope.imageIndex = $scope.imageIndex + 1;
  797. else {
  798. //如果图片已经是最后一张图片了,则取index = 0
  799. $scope.imageIndex = 0;
  800. }
  801. //替换url,展示图片
  802. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  803. $scope.bigImage = true; //显示大图
  804. };
  805. $scope.swipeRight = function (imageIndex) {
  806. if ($scope.imageIndex <= $scope.items.imgs.length - 1 && $scope.imageIndex > 0)
  807. $scope.imageIndex = $scope.imageIndex - 1;
  808. else {
  809. //如果图片已经是第一张图片了,则取index = Images.length-1
  810. $scope.imageIndex = $scope.items.imgs.length - 1;
  811. }
  812. //替换url,展示图片
  813. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  814. $scope.bigImage = true; //显示大图
  815. };
  816. $scope.cancelSupport = function () {
  817. $scope.tosupport = false;
  818. $scope.toshare = false;
  819. };
  820. $scope.toshare = false;
  821. $scope.toshare = false;
  822. $scope.toRecharge = function(){
  823. $state.go("app.recharge")
  824. };
  825. $scope.toDetail = function (dream_id) {
  826. if($scope.items.near_dream==null){
  827. msg.alert("当前梦想","该用户没有当前梦想");
  828. }
  829. if($scope.items.near_dream!=null){
  830. var dream_id = $scope.items.near_dream.id;
  831. if($location.path()=="/app/home/userDetail"){
  832. $state.go('app.home_dreamdetail',{id:dream_id});
  833. }
  834. else {
  835. $state.go('app.my_dreamdetail',{id:dream_id});
  836. }
  837. }
  838. };
  839. $scope.toOldDream = function(){
  840. if($scope.items.dreams.length<2){
  841. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  842. }
  843. if($scope.items.dreams.length>1){
  844. if($location.path()=="/app/home/userDetail"){
  845. $state.go('app.oldDream',{user_id:$scope.items.user.id});
  846. }
  847. else {
  848. $state.go('app.myOldDream',{user_id:$scope.items.user.id});
  849. }
  850. }
  851. };
  852. $scope.toSupportDream = function(){
  853. if($scope.items.sup_dreams.length==0){
  854. msg.alert("支持的梦想","该用户没有支持的梦想");
  855. }
  856. if($scope.items.sup_dreams.length!=0){
  857. if($scope.items.dreams.length>1){
  858. if($location.path()=="/app/home/userDetail"){
  859. $state.go('app.supportDream',{user_id:$scope.items.user.id});
  860. }
  861. else {
  862. $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
  863. }
  864. }
  865. }
  866. };
  867. $scope.collectionDream = function(is_collection){
  868. homeService.collectionDream(id,is_collection).then(function(result){
  869. $scope.user.is_collection=result.data.data;
  870. })
  871. };
  872. }]);
  873. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  874. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  875. $scope.$on('$ionicView.beforeEnter', function () {
  876. $ionicTabsDelegate.showBar(false);
  877. myService.collect().then(function(result){
  878. $scope.dreams = result.data.data.dreams;
  879. });
  880. });
  881. $scope.toDetail = function (id) {
  882. $state.go('app.home_dreamdetail',{id:id});
  883. };
  884. }]);
  885. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  886. , function ($scope,homeService,$stateParams, $state, msg) {
  887. $scope.dream = $stateParams.item;
  888. $scope.showAbout = true;
  889. $scope.hideAbout = false;
  890. $scope.showText = function(){
  891. $scope.aboutStyle = {
  892. "white-space" : "normal"
  893. };
  894. $scope.showAbout = false;
  895. $scope.hideAbout = true;
  896. };
  897. $scope.hideText = function(){
  898. $scope.aboutStyle = {
  899. "white-space" : "nowrap"
  900. };
  901. $scope.showAbout = true;
  902. $scope.hideAbout = false;
  903. };
  904. }]);
  905. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  906. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  907. $scope.$on('$ionicView.beforeEnter', function () {
  908. $ionicTabsDelegate.showBar(false);
  909. myService.messageInfo().then(function(result){
  910. $scope.infos = result.data.data;
  911. },function(error){
  912. });
  913. });
  914. $scope.notRead = function(){
  915. myService.notRead().then(function(result){
  916. myService.messageInfo().then(function(result){
  917. $scope.infos = result.data.data;
  918. },function(error){
  919. });
  920. },function(error){
  921. })
  922. };
  923. //系统消息
  924. $scope.systemInfo = function(){
  925. $state.go("app.message_sys");
  926. myService.systemInfo().then(function(result){
  927. },function(error){
  928. });
  929. };
  930. //回复我的
  931. $scope.replyMy = function(){
  932. $state.go("app.message_reply");
  933. myService.replyMy().then(function(result){
  934. },function(error){
  935. });
  936. };
  937. $scope.personalLetter = function(){
  938. $state.go("app.letter");
  939. }
  940. }]);
  941. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  942. , function ($scope,homeService,$stateParams, $state, msg) {
  943. var user_id = $stateParams.user_id;
  944. $scope.$on('$ionicView.beforeEnter',function(){
  945. $scope.toUserDetail(user_id);
  946. });
  947. $scope.toUserDetail = function(user_id){
  948. homeService.toUserDetail(user_id).then(function(result){
  949. $scope.items = result.data.data;
  950. $scope.user = result.data.data.user;
  951. $scope.dreams = $scope.user.dreams;
  952. },function(error){
  953. })
  954. };
  955. $scope.toDetail = function(){
  956. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  957. };
  958. }]);
  959. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  960. , function ($scope,homeService,$stateParams, $state, msg) {
  961. var user_id = $stateParams.user_id;
  962. $scope.$on('$ionicView.beforeEnter',function(){
  963. $scope.toUserDetail(user_id);
  964. });
  965. $scope.toUserDetail = function(user_id){
  966. homeService.toUserDetail(user_id).then(function(result){
  967. $scope.items = result.data.data;
  968. $scope.user = result.data.data.user;
  969. $scope.dreams = $scope.user.sup_dream;
  970. },function(error){
  971. })
  972. };
  973. $scope.toDetail = function(){
  974. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  975. }
  976. }]);
  977. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  978. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  979. $scope.showMore = function (keyword,index) {
  980. if(!keyword)return;
  981. $scope.index = index;
  982. $scope.search(keyword);
  983. };
  984. $scope.search = function (keyword) {
  985. $scope.vm.keyword = keyword;
  986. homeService.search(keyword).then(function(result){
  987. $scope.isResult = true;
  988. $scope.dream_infos = result.data.data.dream_infos;
  989. $scope.user_infos = result.data.data.user_infos;
  990. });
  991. };
  992. $scope.toUserDetail = function (id) {
  993. homeService.toUserDetail(id).then(function(result){
  994. $scope.items = result.data.data;
  995. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  996. },function(error){
  997. //msg.error(msg.data.error)
  998. })
  999. };
  1000. $scope.toDetail = function (id) {
  1001. $state.go('app.home_dreamdetail',{id:id});
  1002. };
  1003. $scope.$on('$ionicView.beforeEnter', function () {
  1004. $scope.isResult = false;
  1005. $scope.index = 0;
  1006. $scope.vm = {
  1007. keyword : ""
  1008. };
  1009. $ionicTabsDelegate.showBar(false);
  1010. // $ionicNavBarDelegate.showBackButton(false);
  1011. homeService.search('').then(function(result){
  1012. $scope.hot_searches = result.data.data.hot_searches;
  1013. $scope.history_searches = result.data.data.history_searches;
  1014. });
  1015. });
  1016. }]);
  1017. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1018. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1019. }]);
  1020. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1021. , function ($scope, $state, myService, msg) {
  1022. $scope.$on('$ionicView.beforeEnter', function () {
  1023. myService.myDream().then(function(result){
  1024. console.log(result.data.data);
  1025. $scope.dreams = result.data.data;
  1026. });
  1027. });
  1028. $scope.toDetail = function (id) {
  1029. $state.go('app.home_dreamdetail',{id:id});
  1030. };
  1031. }]);
  1032. })(angular.module('app.controllers'));