home.js 43 KB

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