home.js 45 KB

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