home.js 41 KB

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