home.js 42 KB

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