home.js 43 KB

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