home.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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,7:>18
  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. //分享给朋友
  295. Wechat.share({
  296. message: {
  297. title: $scope.dream.name,
  298. description: $scope.dream.about,
  299. thumb: "q8.9026.com/base/img/share/icon_cat_h.png",
  300. media: {
  301. type: Wechat.Type.WEBPAGE,
  302. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  303. }
  304. },
  305. scene: Wechat.Scene.SESSION
  306. }, function () {
  307. alert("分享成功");
  308. }, function (reason) {
  309. alert("分享失败");
  310. });
  311. }
  312. if(type==1){
  313. Wechat.share({
  314. message: {
  315. title: $scope.dream.name,
  316. description: $scope.dream.about,
  317. thumb: "q8.9026.com/base/img/share/icon_cat_h.png",
  318. media: {
  319. type: Wechat.Type.WEBPAGE,
  320. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  321. }
  322. },
  323. scene: Wechat.Scene.TIMELINE
  324. }, function () {
  325. alert("分享","分享成功");
  326. }, function (reason) {
  327. alert("分享","分享失败");
  328. });
  329. }
  330. };
  331. //实时排行
  332. $scope.sort = {
  333. slide: ''
  334. };
  335. $scope.changeType = function (type) {
  336. $ionicScrollDelegate.scrollTop(true);
  337. $scope.type = type;
  338. };
  339. $scope.index = 0;
  340. $scope.vm = {
  341. coin:"",
  342. title:""
  343. };
  344. $scope.timer = '';
  345. var leftTimer = function (countDown) {
  346. if (isNaN(countDown)) {
  347. $scope.timer = '已结束';
  348. return;
  349. }
  350. var day=parseInt(countDown/(24*60*60));
  351. var h=parseInt(countDown/(60*60)%24);
  352. var m=parseInt(countDown/60%60);
  353. var s=parseInt(countDown%60);
  354. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  355. if(day>0) $scope.timer = day+'天';
  356. if(day<0 && h>0) $scope.timer = h+'小时';
  357. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  358. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  359. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  360. $scope.leftTimer = $interval(function () {
  361. if (countDown >= 1) leftTimer(countDown - 1);
  362. },1000);*/
  363. /*if(countDown<=0){
  364. $scope.timer='结束';
  365. }*/
  366. };
  367. $scope.changeIndex = function (index) {
  368. $scope.index = index;
  369. $scope.vm.coin = index*10;
  370. };
  371. $scope.vidEnded = function () {
  372. alert('播放完毕');
  373. };
  374. //实时计算支持乘数
  375. $scope.calcmultiplier = function () {
  376. $scope.multi.promise = $interval(function () {
  377. var date = new Date();
  378. var inter = date.getTime() - $scope.multi.b.getTime();
  379. var minutes = Math.floor(inter / (60 * 1000));
  380. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  381. if (number<=1) {
  382. number = 1;
  383. }
  384. //$scope.multi.result = Math.round(number * 100) / 100;
  385. $scope.multi.result = Math.round(number * 100 / 100);
  386. },1000);
  387. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  388. };
  389. $scope.supportDream = function (data) {
  390. if(!$scope.vm.coin){
  391. msg.error("请选择梦想币数量!");
  392. return ;
  393. }
  394. var data = {
  395. id:id,
  396. coin:$scope.vm.coin
  397. };
  398. homeService.supportDream(data).then(function(result){
  399. $scope.tosupport = false;
  400. $scope.load(id);
  401. homeService.myInfo().then(function(result){
  402. $scope.user = result.data.data;
  403. });
  404. $interval.cancel($scope.multi.promise);
  405. msg.text("发送成功");
  406. })
  407. };
  408. $scope.collectionDream = function(is_collection){
  409. homeService.collectionDream(id,is_collection).then(function(result){
  410. $scope.dream.is_collection=result.data.data;
  411. })
  412. };
  413. $scope.add = function(is_collection){
  414. var data = {
  415. id:id,
  416. title:$scope.vm.title,
  417. pics:$scope.imgs,
  418. video:$scope.video.server
  419. };
  420. homeService.add_interaction(data).then(function(){
  421. $scope.load(id);
  422. $scope.closeModal();
  423. })
  424. };
  425. $scope.showAbout = true;
  426. $scope.hideAbout = false;
  427. $scope.showText = function(){
  428. $scope.aboutStyle = {
  429. "white-space" : "normal"
  430. };
  431. $scope.showAbout = false;
  432. $scope.hideAbout = true;
  433. };
  434. $scope.hideText = function(){
  435. $scope.aboutStyle = {
  436. "white-space" : "nowrap"
  437. };
  438. $scope.showAbout = true;
  439. $scope.hideAbout = false;
  440. };
  441. $scope.input = {
  442. placeholder: '评论',
  443. focus: false,
  444. show:false
  445. };
  446. $scope.showmore = function (index) {
  447. if ($scope.dream.interactions[index].showmore) {
  448. $scope.dream.interactions[index].showmore = false;
  449. } else {
  450. $scope.dream.interactions[index].showmore = true;
  451. }
  452. }
  453. $scope.replay = function ($event, name, index) {
  454. $event.stopPropagation();
  455. $scope.input.focus = true;
  456. $scope.input.show = true;
  457. angular.forEach($scope.dream.interactions, function (item) {
  458. item.show = false;
  459. })
  460. $scope.dream.interactions[index].show = true;
  461. $scope.dream.interactions[index].focus = true;
  462. $scope.input.placeholder = "评论" + name+":";
  463. $scope.vm.title='';
  464. $scope.vm.comment='';
  465. }
  466. $scope.replayOther = function ($event, name, index,currentindex) {
  467. $event.stopPropagation();
  468. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  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. else {
  481. msg.confirm("评论","是否删除评论").then(function(result){
  482. if(result==true)
  483. {
  484. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  485. msg.text("删除成功");
  486. $scope.load(id);
  487. },function(error){
  488. msg.error(error.data.message);
  489. })
  490. }
  491. });
  492. }
  493. };
  494. $scope.testcharge = function(number){
  495. if (!number) {
  496. msg.text('请输入充值金额');
  497. return;
  498. }
  499. homeService.testcharge(number,2).then(function (result) {
  500. msg.text("充值成功");
  501. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  502. $timeout(function () {
  503. $scope.closeRechargeModal();
  504. }, 500);
  505. homeService.myInfo().then(function (result) {
  506. $scope.user = result.data.data;
  507. });
  508. })
  509. }
  510. //充值
  511. $scope.charge = function(number){
  512. if (!number) {
  513. msg.text('请输入充值金额');
  514. return;
  515. }
  516. homeService.charge(number,2).then(function (result) {
  517. //todo:result需要返回支付宝或者微信的签名信息
  518. console.log("result: " + JSON.stringify(result));
  519. var payInfo = result.data;
  520. if ($scope.vm.payType == 1) { //支付宝
  521. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  522. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  523. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  524. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  525. //当e.resultStatus为9000时,请去服务端验证支付结果
  526. $scope.clicksub = false;
  527. if (e.resultStatus == '9000') {
  528. alert(orderID);
  529. //支付成功
  530. // $state.go('app.my');
  531. } else {
  532. msg.error("支付失败");
  533. // msg.error("支付失败:" + JSON.stringify(e));
  534. }
  535. }, function error(e) {
  536. $scope.clicksub = false;
  537. // msg.error("支付失败:" + JSON.stringify(e));
  538. msg.error("支付失败");
  539. });
  540. }
  541. if ($scope.vm.payType == 2) { //微信
  542. var obj = JSON.parse(payInfo);
  543. var params = {
  544. partnerid: obj.partnerid, // merchant id
  545. prepayid: obj.prepayid, // prepay id
  546. noncestr: obj.noncestr, // nonce
  547. timestamp: obj.timestamp, // timestamp
  548. sign: obj.sign, // signed string
  549. };
  550. Wechat.sendPaymentRequest(params, function (r) {
  551. $scope.clicksub = false;
  552. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  553. // alert(result);
  554. //支付成功
  555. // $state.go('app.my');
  556. }, function (erro) {
  557. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  558. });
  559. }, function (reason) {
  560. $scope.clicksub = false;
  561. msg.alert("支付失败:" + JSON.stringify(reason));
  562. });
  563. }
  564. // msg.text("充值成功");
  565. // $state.go('app.my');
  566. });
  567. };
  568. $scope.submitComment = function (index) {
  569. var interaction = $scope.dream.interactions[index];
  570. var iid = interaction.id;
  571. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  572. $scope.input.focus = true;
  573. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  574. var data = {
  575. id:iid,
  576. content:$scope.vm.comment
  577. };
  578. console.log($scope.vm.comment+" "+iid);
  579. homeService.add_comment(data).then(function(){
  580. $scope.vm.comment = '' ;
  581. $scope.load(id);
  582. $scope.closeModal();
  583. })
  584. debugger;
  585. };
  586. $scope.bigImage = false;
  587. $scope.showBigImage = function ($event, imageName) {
  588. $event.stopPropagation();
  589. $scope.url = imageName;
  590. $scope.bigImage = true;
  591. };
  592. $scope.hideBigImage = function(){
  593. $scope.bigImage = false;
  594. };
  595. $ionicModal.fromTemplateUrl('qrCode.html', {
  596. scope: $scope,
  597. animation: 'slide-in-up'
  598. }).then(function(modal) {
  599. $scope.qrCodemodal = modal;
  600. });
  601. $scope.openCode = function($event) {
  602. $event.stopPropagation();
  603. $scope.qrCodemodal.show();
  604. $scope.vm.money = '';
  605. };
  606. $scope.closeCode = function() {
  607. $scope.qrCodemodal.hide();
  608. };
  609. $ionicModal.fromTemplateUrl('commentPic.html', {
  610. scope: $scope,
  611. animation: 'slide-in-up'
  612. }).then(function(modal) {
  613. $scope.CommentPicmodal = modal;
  614. });
  615. $scope.openCommentPic = function(pic,$event) {
  616. $event.stopPropagation();
  617. $scope.CommentPicmodal.show();
  618. $scope.commentPicUrl = pic;
  619. };
  620. $scope.closeCommentPic = function() {
  621. $scope.CommentPicmodal.hide();
  622. };
  623. $scope.addpict = function () {
  624. common.chooseImage().then(function (img) {
  625. common.uploadFiles(img,1).then(function (result) {
  626. var response = JSON.parse(result.response);
  627. var file = response.data.file;
  628. $scope.imgs.push(config.imgServer+file);
  629. console.log(JSON.stringify(config.imgServer+file));
  630. }, function (error) {
  631. msg.error('图片上传失败');
  632. });
  633. }, function (error) {
  634. console.log('图片选择失败');
  635. });
  636. };
  637. $scope.deletefile = function (file) {
  638. var index = $scope.imgs.indexOf(file);
  639. $scope.imgs.splice(index, 1);
  640. common.deletefile(file).then(function () {
  641. })
  642. };
  643. $scope.addvideo = function () {
  644. common.chooseVideo().then(function (file) {
  645. common.uploadFiles(file, 2).then(function (result) {
  646. var response = JSON.parse(result.response);
  647. $scope.video.server = response.data.file;
  648. var file = config.imgServer+response.data.file;
  649. console.log("file:"+file);
  650. $scope.video.isOK = true;
  651. $scope.video.file = file;
  652. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  653. console.log("vpic:"+$scope.video.vpic);
  654. }, function (error) {
  655. msg.error('视频上传失败');
  656. });
  657. }, function (erro) {
  658. console.log('选择视频失败');
  659. });
  660. };
  661. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  662. scope: $scope,
  663. animation: 'slide-in-up'
  664. }).then(function(modal) {
  665. $scope.rechagemodal = modal;
  666. });
  667. $scope.openRechargeModal = function() {
  668. $scope.rechagemodal.show();
  669. $scope.vm.money = '';
  670. };
  671. $scope.closeRechargeModal = function() {
  672. $scope.rechagemodal.hide();
  673. };
  674. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  675. scope: $scope,
  676. animation: 'slide-in-up'
  677. }).then(function(modal) {
  678. $scope.modal = modal;
  679. });
  680. $scope.openModal = function() {
  681. $scope.modal.show();
  682. $scope.vm.title = '';
  683. $scope.imgs = [];
  684. $scope.video = {};
  685. };
  686. $scope.closeModal = function() {
  687. $scope.modal.hide();
  688. };
  689. //当我们用到模型时,清除它!
  690. $scope.$on('$destroy', function() {
  691. $scope.modal.remove();
  692. });
  693. $scope.toMessage = function(){
  694. //var dreamdetailUrl = $location.path();
  695. if($location.path()=="/app/home/dreamdetail"){
  696. $state.go("app.message");
  697. }
  698. else {
  699. $state.go("app.my_message");
  700. }
  701. }
  702. }]);
  703. app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  704. , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  705. var id = $stateParams.id;
  706. $scope.items = $stateParams.items;
  707. $scope.$on('$ionicView.beforeEnter', function () {
  708. $ionicTabsDelegate.showBar(false);
  709. });
  710. $scope.attentionUser = function(is_care){
  711. homeService.attentionUser(id,is_care).then(function(result){
  712. $scope.items.is_care=result.data.data;
  713. })
  714. };
  715. $scope.next = function (type) {
  716. //type:1 前一个,type:2 后一个
  717. if($scope.items.imgs.length>0){
  718. if(type==1)
  719. {
  720. var temp= $scope.items.imgs.splice(0,1);
  721. $scope.items.imgs.push(temp[0]);
  722. }
  723. if (type==2){
  724. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  725. $scope.items.imgs.unshift(temp[0]);
  726. }
  727. }
  728. };
  729. $scope.bigImage = false;
  730. $scope.showBigImage = function(imageName){
  731. $scope.url = imageName;
  732. $scope.bigImage = true;
  733. };
  734. $scope.hideBigImage = function(){
  735. $scope.bigImage = false;
  736. };
  737. $scope.cancelSupport = function () {
  738. $scope.tosupport = false;
  739. $scope.toshare = false;
  740. };
  741. $scope.toshare = false;
  742. $scope.toshare = false;
  743. $scope.toRecharge = function(){
  744. $state.go("app.recharge")
  745. };
  746. $scope.toDetail = function (dream_id) {
  747. if($scope.items.near_dream==null){
  748. msg.alert("当前梦想","该用户没有当前梦想");
  749. }
  750. if($scope.items.near_dream!=null){
  751. var dream_id = $scope.items.near_dream.id;
  752. if($location.path()=="/app/home/userDetail"){
  753. $state.go('app.home_dreamdetail',{id:dream_id});
  754. }
  755. else {
  756. $state.go('app.my_dreamdetail',{id:dream_id});
  757. }
  758. }
  759. };
  760. $scope.toOldDream = function(){
  761. if($scope.items.dreams.length<2){
  762. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  763. }
  764. if($scope.items.dreams.length>1){
  765. if($location.path()=="/app/home/userDetail"){
  766. $state.go('app.oldDream',{user_id:$scope.items.user.id});
  767. }
  768. else {
  769. $state.go('app.myOldDream',{user_id:$scope.items.user.id});
  770. }
  771. }
  772. };
  773. $scope.toSupportDream = function(){
  774. if($scope.items.sup_dreams.length==0){
  775. msg.alert("支持的梦想","该用户没有支持的梦想");
  776. }
  777. if($scope.items.sup_dreams.length!=0){
  778. if($scope.items.dreams.length>1){
  779. if($location.path()=="/app/home/userDetail"){
  780. $state.go('app.supportDream',{user_id:$scope.items.user.id});
  781. }
  782. else {
  783. $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
  784. }
  785. }
  786. }
  787. };
  788. $scope.collectionDream = function(is_collection){
  789. homeService.collectionDream(id,is_collection).then(function(result){
  790. $scope.user.is_collection=result.data.data;
  791. })
  792. };
  793. }]);
  794. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  795. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  796. $scope.$on('$ionicView.beforeEnter', function () {
  797. $ionicTabsDelegate.showBar(false);
  798. myService.collect().then(function(result){
  799. $scope.dreams = result.data.data.dreams;
  800. });
  801. });
  802. $scope.toDetail = function (id) {
  803. $state.go('app.home_dreamdetail',{id:id});
  804. };
  805. }]);
  806. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  807. , function ($scope,homeService,$stateParams, $state, msg) {
  808. $scope.dream = $stateParams.item;
  809. $scope.showAbout = true;
  810. $scope.hideAbout = false;
  811. $scope.showText = function(){
  812. $scope.aboutStyle = {
  813. "white-space" : "normal"
  814. };
  815. $scope.showAbout = false;
  816. $scope.hideAbout = true;
  817. };
  818. $scope.hideText = function(){
  819. $scope.aboutStyle = {
  820. "white-space" : "nowrap"
  821. };
  822. $scope.showAbout = true;
  823. $scope.hideAbout = false;
  824. };
  825. }]);
  826. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  827. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  828. $scope.$on('$ionicView.beforeEnter', function () {
  829. $ionicTabsDelegate.showBar(false);
  830. myService.messageInfo().then(function(result){
  831. $scope.infos = result.data.data;
  832. },function(error){
  833. });
  834. });
  835. $scope.notRead = function(){
  836. myService.notRead().then(function(result){
  837. myService.messageInfo().then(function(result){
  838. $scope.infos = result.data.data;
  839. },function(error){
  840. });
  841. },function(error){
  842. })
  843. };
  844. //系统消息
  845. $scope.systemInfo = function(){
  846. $state.go("app.message_sys");
  847. myService.systemInfo().then(function(result){
  848. },function(error){
  849. });
  850. };
  851. //回复我的
  852. $scope.replyMy = function(){
  853. $state.go("app.message_reply");
  854. myService.replyMy().then(function(result){
  855. },function(error){
  856. });
  857. };
  858. $scope.personalLetter = function(){
  859. $state.go("app.letter");
  860. }
  861. }]);
  862. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  863. , function ($scope,homeService,$stateParams, $state, msg) {
  864. var user_id = $stateParams.user_id;
  865. $scope.$on('$ionicView.beforeEnter',function(){
  866. $scope.toUserDetail(user_id);
  867. });
  868. $scope.toUserDetail = function(user_id){
  869. homeService.toUserDetail(user_id).then(function(result){
  870. $scope.items = result.data.data;
  871. $scope.user = result.data.data.user;
  872. $scope.dreams = $scope.user.dreams;
  873. },function(error){
  874. })
  875. };
  876. $scope.toDetail = function(){
  877. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  878. };
  879. }]);
  880. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  881. , function ($scope,homeService,$stateParams, $state, msg) {
  882. var user_id = $stateParams.user_id;
  883. $scope.$on('$ionicView.beforeEnter',function(){
  884. $scope.toUserDetail(user_id);
  885. });
  886. $scope.toUserDetail = function(user_id){
  887. homeService.toUserDetail(user_id).then(function(result){
  888. $scope.items = result.data.data;
  889. $scope.user = result.data.data.user;
  890. $scope.dreams = $scope.user.sup_dream;
  891. },function(error){
  892. })
  893. };
  894. $scope.toDetail = function(){
  895. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  896. }
  897. }]);
  898. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  899. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  900. $scope.showMore = function (keyword,index) {
  901. if(!keyword)return;
  902. $scope.index = index;
  903. $scope.search(keyword);
  904. };
  905. $scope.search = function (keyword) {
  906. $scope.vm.keyword = keyword;
  907. homeService.search(keyword).then(function(result){
  908. $scope.isResult = true;
  909. $scope.dream_infos = result.data.data.dream_infos;
  910. $scope.user_infos = result.data.data.user_infos;
  911. });
  912. };
  913. $scope.toUserDetail = function (id) {
  914. homeService.toUserDetail(id).then(function(result){
  915. $scope.items = result.data.data;
  916. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  917. },function(error){
  918. //msg.error(msg.data.error)
  919. })
  920. };
  921. $scope.toDetail = function (id) {
  922. $state.go('app.home_dreamdetail',{id:id});
  923. };
  924. $scope.$on('$ionicView.beforeEnter', function () {
  925. $scope.isResult = false;
  926. $scope.index = 0;
  927. $scope.vm = {
  928. keyword : ""
  929. };
  930. $ionicTabsDelegate.showBar(false);
  931. // $ionicNavBarDelegate.showBackButton(false);
  932. homeService.search('').then(function(result){
  933. $scope.hot_searches = result.data.data.hot_searches;
  934. $scope.history_searches = result.data.data.history_searches;
  935. });
  936. });
  937. }]);
  938. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  939. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  940. }]);
  941. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  942. , function ($scope, $state, myService, msg) {
  943. $scope.$on('$ionicView.beforeEnter', function () {
  944. myService.myDream().then(function(result){
  945. console.log(result.data.data);
  946. $scope.dreams = result.data.data;
  947. });
  948. });
  949. $scope.toDetail = function (id) {
  950. $state.go('app.home_dreamdetail',{id:id});
  951. };
  952. }]);
  953. })(angular.module('app.controllers'));