home.js 42 KB

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