home.js 46 KB

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