home.js 42 KB

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