home.js 42 KB

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