home.js 44 KB

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