home.js 42 KB

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