home.js 42 KB

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