home.js 43 KB

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