home.js 41 KB

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