home.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. (function (app) {
  2. app.controller('homeCtrl', ["$scope", "$ionicTabsDelegate", "$http", 'config', "$state", "msg", "$ionicPopover", "homeService", "$ionicPopup", "$timeout", "$ionicSideMenuDelegate"
  3. , function ($scope, $ionicTabsDelegate, $http, config, $state, msg, $ionicPopover, homeService, $ionicPopup, $timeout, $ionicSideMenuDelegate) {
  4. $scope.$on('$ionicView.beforeEnter', function () {
  5. $ionicTabsDelegate.showBar(true);
  6. $scope.load(true);
  7. homeService.messageInfo().then(function(result){
  8. $scope.infos = result.data.data;
  9. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  10. $scope.showMessage=0;
  11. }
  12. else {
  13. $scope.showMessage=1;
  14. }
  15. },function(error){
  16. });
  17. });
  18. $scope.type = 'hot';//tab切换
  19. //$scope.chosedIndex = 0;
  20. $scope.clickAvatar = function(id){
  21. homeService.toUserDetail(id).then(function(result){
  22. $scope.items = result.data.data;
  23. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  24. },function(error){
  25. //msg.error(msg.data.error)
  26. });
  27. };
  28. $ionicPopover.fromTemplateUrl('my-popover.html', {
  29. scope: $scope
  30. }).then(function (popover) {
  31. $scope.popover = popover;
  32. });
  33. $scope.toggleLeftSideMenu = function () {
  34. $ionicSideMenuDelegate.toggleLeft();
  35. };
  36. $scope.openPopover = function ($event) {
  37. $scope.popover.show($event);
  38. };
  39. $scope.closePopover = function () {
  40. $scope.popover.hide();
  41. };
  42. $scope.changetype = function (type) {
  43. $scope.type = type;
  44. $scope.load(true);
  45. };
  46. $scope.toDetail = function (id) {
  47. $state.go('app.home_dreamdetail',{id:id});
  48. };
  49. $scope.toUserDetail = function (id) {
  50. homeService.toUserDetail(id).then(function(result){
  51. $scope.items = result.data.data;
  52. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  53. },function(error){
  54. //msg.error(msg.data.error)
  55. })
  56. };
  57. $scope.changeFilter = function (input) {
  58. switch (input) {
  59. case '1':
  60. if ($scope.filter.sex == 1) {
  61. $scope.filter.sex = 0;
  62. } else {
  63. $scope.filter.sex = 1;
  64. }
  65. break;
  66. case '2':
  67. if ($scope.filter.sex == 2) {
  68. $scope.filter.sex = 0;
  69. } else {
  70. $scope.filter.sex = 2;
  71. }
  72. break;
  73. default:
  74. }
  75. };
  76. $scope.filter = {
  77. hasMore: false,
  78. pageIndex: 1,
  79. pageSize: 20,
  80. sex: 0,//1男,2女,0:全部,
  81. age: 0,//0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>38,
  82. city:''
  83. };
  84. $scope.doFilter = function () {
  85. homeService.doFilter($scope.filter.sex,$scope.filter.age,$scope.filter.city).then(function(result){
  86. $scope.index.dreams = result.data.data.dreams.data;
  87. },function(error){
  88. msg.error(data.error.message);
  89. });
  90. //$ionicSideMenuDelegate.toggleRight();
  91. };
  92. $scope.index = {
  93. banner: [],
  94. users: [],
  95. dreams:[]
  96. };
  97. $scope.next = function (type) {
  98. //type:1 前一个,type:2 后一个
  99. if($scope.index.users.length>0){
  100. if(type==1)
  101. {
  102. var temp= $scope.index.users.splice(0,1);
  103. $scope.index.users.push(temp[0]);
  104. }
  105. if (type==2){
  106. var temp= $scope.index.users.splice($scope.index.users.length-1,1);
  107. $scope.index.users.unshift(temp[0]);
  108. }
  109. }
  110. };
  111. $scope.load = function (init) {
  112. if (init) {
  113. $scope.filter.pageIndex = 1;
  114. $scope.index.dreams = [];
  115. }
  116. msg.loading();
  117. homeService.index($scope.type, $scope.filter.pageIndex).then(function (result) {
  118. msg.hide();
  119. $scope.index.banners = result.data.data.banners;
  120. $scope.index.users = result.data.data.users;
  121. $scope.filter.pageIndex++;
  122. var more = (result.data.data.dreams.data.length >= $scope.filter.pageSize);
  123. $scope.filter.hasMore = more;
  124. $scope.index.dreams = $scope.index.dreams.concat(result.data.data.dreams.data);
  125. if (init) {
  126. $scope.$broadcast('scroll.refreshComplete');
  127. } else {
  128. $scope.$broadcast('scroll.infiniteScrollComplete');
  129. }
  130. }, function (error) {
  131. msg.hide();
  132. });
  133. };
  134. $scope.qrscan = function () {
  135. cordova.plugins.barcodeScanner.scan(
  136. function (result) {
  137. //扫码成功后执行的回调函数
  138. alert("收到一个二维码\n" +
  139. "扫码文字结果: " + result.text + "\n" +
  140. "格式: " + result.format + "\n" +
  141. "是否在扫码页面取消扫码: " + result.cancelled);
  142. },
  143. function (error) {
  144. //扫码失败执行的回调函数
  145. alert("Scanning failed: " + error);
  146. }, {
  147. preferFrontCamera: false, // iOS and Android 设置前置摄像头
  148. showFlipCameraButton: true, // iOS and Android 显示旋转摄像头按钮
  149. showTorchButton: true, // iOS and Android 显示打开闪光灯按钮
  150. torchOn: false, // Android, launch with the torch switched on (if available)打开手电筒
  151. prompt: "在扫描区域内放置二维码", // Android提示语
  152. resultDisplayDuration: 500, // Android, display scanned text for X ms.
  153. //0 suppresses it entirely, default 1500 设置扫码时间的参数
  154. formats: "QR_CODE", // 二维码格式可设置多种类型
  155. orientation: "portrait", // Android only (portrait|landscape),
  156. //default unset so it rotates with the device在安卓上 landscape 是横屏状态
  157. disableAnimations: true, // iOS 是否禁止动画
  158. disableSuccessBeep: false // iOS 禁止成功后提示声音 “滴”
  159. }
  160. );
  161. };
  162. $scope.data = {};
  163. //$scope.load(true);
  164. $scope.$on('$ionicView.beforeLeave', function () {
  165. $scope.popover.hide();
  166. $scope.load(true);
  167. });
  168. }]);
  169. app.controller('dreamDetailCtrl', ["$scope","$ionicHistory","$timeout", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
  170. , function ($scope, $ionicHistory,$timeout,$state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $ionicScrollDelegate, $interval) {
  171. var id = $stateParams.id;
  172. var top3user = '';
  173. $scope.chosedIndex = 0;
  174. $scope.clickAvatar = function (index) {
  175. $scope.chosedIndex = index;
  176. homeService.myInfo().then(function (result) {
  177. $scope.user = result.data.data;
  178. });
  179. };
  180. // id=5;
  181. $scope.$on('$ionicView.beforeEnter', function () {
  182. $ionicTabsDelegate.showBar(false);
  183. $scope.load(id);
  184. $scope.thisUser = storage.getObject('user');
  185. $scope.vm.payType = 2;
  186. homeService.myInfo().then(function(result){
  187. $scope.user = result.data.data;
  188. });
  189. homeService.messageInfo().then(function(result){
  190. $scope.infos = result.data.data;
  191. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  192. $scope.showMessage=0;
  193. }
  194. else {
  195. $scope.showMessage=1;
  196. }
  197. },function(error){
  198. });
  199. });
  200. $scope.$on('$ionicView.leave', function () {
  201. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  202. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  203. });
  204. $scope.toSort = function(){
  205. //$scope.type = 3;
  206. $scope.changeType(3)
  207. };
  208. $scope.load = function (id) {
  209. msg.loading();
  210. homeService.dreamDetail(id).then(function (result) {
  211. msg.hide();
  212. console.log(result);
  213. $scope.showCode = function(codeName){
  214. $scope.url = codeName;
  215. $scope.code = true;
  216. };
  217. $scope.hideCode = function(){
  218. $scope.code = false;
  219. };
  220. $scope.dream = result.data.data;
  221. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  222. $scope.codeBtn = true;
  223. }
  224. if($scope.dream.video){
  225. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  226. $scope.dream.video = config.imgServer+$scope.dream.video;
  227. }
  228. var reg = new RegExp("\n", "g");
  229. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  230. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  231. var date = new Date();
  232. var inter = (end_time.getTime() - date.getTime()) / 1000;
  233. leftTimer(inter);
  234. $scope.multi.a = $scope.dream.a;
  235. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  236. $scope.multi.c = $scope.dream.c;
  237. $scope.multi.promise = $scope.dream.a;
  238. var newtop3user = '' ;
  239. angular.forEach($scope.dream.top3user, function(user) {
  240. newtop3user= newtop3user +user.id+","
  241. });
  242. if(top3user!=''&&newtop3user!=top3user){
  243. //测试动画切换
  244. $timeout(function() {
  245. $scope.sort.slide1 = 'list-grow-animation';
  246. $scope.sort.slide2 = 'slide-in-both-ways';
  247. $scope.sort.slide3 = 'bounce-animation';
  248. }, 50);
  249. }
  250. top3user = newtop3user;
  251. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  252. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  253. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  254. $scope.calcmultiplier();
  255. }, function (error) {
  256. msg.hide();
  257. });
  258. };
  259. $scope.openSupport = function () {
  260. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  261. };
  262. $scope.multi = {
  263. a: '',
  264. b: '',
  265. c: '',
  266. result: 1,
  267. promise:null
  268. };
  269. $scope.type = 1;//tab切换
  270. $scope.tosupport = false;
  271. $scope.support = function ($event) {
  272. $event.stopPropagation();
  273. $scope.tosupport = true;
  274. $scope.vm.coin = 0;
  275. $scope.index = 0;
  276. };
  277. $scope.cancelSupport = function () {
  278. $scope.tosupport = false;
  279. $scope.toshare = false;
  280. $scope.input.show = false;
  281. };
  282. $scope.toshare = false;
  283. $scope.toRecharge = function(){
  284. $state.go("app.recharge")
  285. };
  286. $scope.share = function (type,$event) {
  287. $scope.toshare = true;
  288. if (type==0) {//分享给朋友
  289. /* Wechat.share({
  290. text: "分享的文字",
  291. scene: Wechat.Scene.SESSION // share to 好友
  292. }, function () {
  293. alert("Success");
  294. }, function (reason) {
  295. alert("Failed: " + reason);
  296. });*/
  297. Wechat.share({
  298. message: {
  299. title:"瞄瞄",
  300. description:"HELLO,这是我的梦想,快来围观吧!",
  301. thumb:"img/icon_cat_h.png",
  302. media: {
  303. type: Wechat.Type.WEBPAGE,
  304. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  305. }
  306. },
  307. scene: Wechat.Scene.SESSION
  308. }, function () {
  309. alert("Success");
  310. }, function (reason) {
  311. alert("Failed: " + reason);
  312. });
  313. }
  314. if(type==1){
  315. Wechat.share({
  316. message: {
  317. title:"瞄瞄",
  318. description:"HELLO,这是我的梦想,快来围观吧!",
  319. thumb:"img/icon_cat_h.png",
  320. media: {
  321. type: Wechat.Type.WEBPAGE,
  322. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  323. }
  324. },
  325. scene: Wechat.Scene.TIMELINE
  326. }, function () {
  327. alert("Success");
  328. }, function (reason) {
  329. alert("Failed: " + reason);
  330. });
  331. }
  332. // $state.go("app.shareDream",{item:$scope.dream});
  333. };
  334. //实时排行
  335. $scope.sort = {
  336. slide: ''
  337. };
  338. $scope.changeType = function (type) {
  339. $ionicScrollDelegate.scrollTop(true);
  340. $scope.type = type;
  341. };
  342. $scope.index = 0;
  343. $scope.vm = {
  344. coin:"",
  345. title:""
  346. };
  347. $scope.timer = '';
  348. var leftTimer = function (countDown) {
  349. if (isNaN(countDown)) {
  350. $scope.timer = '已结束';
  351. return;
  352. }
  353. var day=parseInt(countDown/(24*60*60));
  354. var h=parseInt(countDown/(60*60)%24);
  355. var m=parseInt(countDown/60%60);
  356. var s=parseInt(countDown%60);
  357. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  358. if(day>0) $scope.timer = day+'天';
  359. if(day<0 && h>0) $scope.timer = h+'小时';
  360. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  361. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  362. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  363. $scope.leftTimer = $interval(function () {
  364. if (countDown >= 1) leftTimer(countDown - 1);
  365. },1000);*/
  366. /*if(countDown<=0){
  367. $scope.timer='结束';
  368. }*/
  369. };
  370. $scope.changeIndex = function (index) {
  371. $scope.index = index;
  372. $scope.vm.coin = index*10;
  373. };
  374. $scope.vidEnded = function () {
  375. alert('播放完毕');
  376. };
  377. //实时计算支持乘数
  378. $scope.calcmultiplier = function () {
  379. $scope.multi.promise = $interval(function () {
  380. var date = new Date();
  381. var inter = date.getTime() - $scope.multi.b.getTime();
  382. var minutes = Math.floor(inter / (60 * 1000));
  383. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  384. if (number<=1) {
  385. number = 1;
  386. }
  387. //$scope.multi.result = Math.round(number * 100) / 100;
  388. $scope.multi.result = Math.round(number * 100 / 100);
  389. },1000);
  390. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  391. };
  392. $scope.supportDream = function (data) {
  393. if(!$scope.vm.coin){
  394. msg.error("请选择梦想币数量!");
  395. return ;
  396. }
  397. var data = {
  398. id:id,
  399. coin:$scope.vm.coin
  400. };
  401. homeService.supportDream(data).then(function(result){
  402. $scope.tosupport = false;
  403. $scope.load(id);
  404. homeService.myInfo().then(function(result){
  405. $scope.user = result.data.data;
  406. });
  407. $interval.cancel($scope.multi.promise);
  408. msg.text("发送成功");
  409. })
  410. };
  411. $scope.collectionDream = function(is_collection){
  412. homeService.collectionDream(id,is_collection).then(function(result){
  413. $scope.dream.is_collection=result.data.data;
  414. })
  415. };
  416. $scope.add = function(is_collection){
  417. var data = {
  418. id:id,
  419. title:$scope.vm.title,
  420. pics:$scope.imgs,
  421. video:$scope.video.server
  422. };
  423. homeService.add_interaction(data).then(function(){
  424. $scope.load(id);
  425. $scope.closeModal();
  426. })
  427. };
  428. $scope.showAbout = true;
  429. $scope.hideAbout = false;
  430. $scope.showText = function(){
  431. $scope.aboutStyle = {
  432. "white-space" : "normal"
  433. };
  434. $scope.showAbout = false;
  435. $scope.hideAbout = true;
  436. };
  437. $scope.hideText = function(){
  438. $scope.aboutStyle = {
  439. "white-space" : "nowrap"
  440. };
  441. $scope.showAbout = true;
  442. $scope.hideAbout = false;
  443. };
  444. $scope.input = {
  445. placeholder: '评论',
  446. focus: false,
  447. show:false
  448. };
  449. $scope.showmore = function (index) {
  450. if ($scope.dream.interactions[index].showmore) {
  451. $scope.dream.interactions[index].showmore = false;
  452. } else {
  453. $scope.dream.interactions[index].showmore = true;
  454. }
  455. }
  456. $scope.replay = function ($event, name, index) {
  457. $event.stopPropagation();
  458. $scope.input.focus = true;
  459. $scope.input.show = true;
  460. angular.forEach($scope.dream.interactions, function (item) {
  461. item.show = false;
  462. })
  463. $scope.dream.interactions[index].show = true;
  464. $scope.input.placeholder = "评论" + name+":";
  465. $scope.vm.title='';
  466. }
  467. $scope.replayOther = function ($event, name, index,currentindex) {
  468. $event.stopPropagation();
  469. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  470. $scope.input.focus = true;
  471. $scope.input.show = true;
  472. angular.forEach($scope.dream.interactions, function (item) {
  473. item.show = false;
  474. })
  475. $scope.dream.interactions[index].show = true;
  476. $scope.input.placeholder = "评论" + name+":";
  477. $scope.vm.title='';
  478. }
  479. else {
  480. msg.confirm("评论","是否删除评论").then(function(result){
  481. if(result==true)
  482. {
  483. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  484. msg.text("删除成功");
  485. $scope.load(id);
  486. },function(error){
  487. msg.error(error.data.message);
  488. })
  489. }
  490. });
  491. }
  492. };
  493. $scope.testcharge = function(number){
  494. if (!number) {
  495. msg.text('请输入充值金额');
  496. return;
  497. }
  498. homeService.testcharge(number,2).then(function (result) {
  499. msg.text("充值成功");
  500. $scope.vm.coin = parseInt($scope.vm.coin) + parseInt(number);
  501. $timeout(function () {
  502. $scope.closeRechargeModal();
  503. }, 500);
  504. homeService.myInfo().then(function (result) {
  505. $scope.user = result.data.data;
  506. });
  507. })
  508. }
  509. //充值
  510. $scope.charge = function(number){
  511. if (!number) {
  512. msg.text('请输入充值金额');
  513. return;
  514. }
  515. homeService.charge(number,2).then(function (result) {
  516. //todo:result需要返回支付宝或者微信的签名信息
  517. console.log("result: " + JSON.stringify(result));
  518. var payInfo = result.data;
  519. if ($scope.vm.payType == 1) { //支付宝
  520. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  521. //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
  522. //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
  523. //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
  524. //当e.resultStatus为9000时,请去服务端验证支付结果
  525. $scope.clicksub = false;
  526. if (e.resultStatus == '9000') {
  527. alert(orderID);
  528. //支付成功
  529. // $state.go('app.my');
  530. } else {
  531. msg.error("支付失败");
  532. // msg.error("支付失败:" + JSON.stringify(e));
  533. }
  534. }, function error(e) {
  535. $scope.clicksub = false;
  536. // msg.error("支付失败:" + JSON.stringify(e));
  537. msg.error("支付失败");
  538. });
  539. }
  540. if ($scope.vm.payType == 2) { //微信
  541. var obj = JSON.parse(payInfo);
  542. var params = {
  543. partnerid: obj.partnerid, // merchant id
  544. prepayid: obj.prepayid, // prepay id
  545. noncestr: obj.noncestr, // nonce
  546. timestamp: obj.timestamp, // timestamp
  547. sign: obj.sign, // signed string
  548. };
  549. Wechat.sendPaymentRequest(params, function (r) {
  550. $scope.clicksub = false;
  551. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  552. // alert(result);
  553. //支付成功
  554. // $state.go('app.my');
  555. }, function (erro) {
  556. msg.alert("支付反馈失败:" + JSON.stringify(erro));
  557. });
  558. }, function (reason) {
  559. $scope.clicksub = false;
  560. msg.alert("支付失败:" + JSON.stringify(reason));
  561. });
  562. }
  563. // msg.text("充值成功");
  564. // $state.go('app.my');
  565. });
  566. }
  567. $scope.submitComment = function (index) {
  568. var interaction = $scope.dream.interactions[index];
  569. var iid = interaction.id;
  570. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  571. $scope.input.focus = true;
  572. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  573. var data = {
  574. id:iid,
  575. content:$scope.vm.comment
  576. };
  577. console.log($scope.vm.comment+" "+iid);
  578. homeService.add_comment(data).then(function(){
  579. $scope.vm.comment = '' ;
  580. $scope.load(id);
  581. $scope.closeModal();
  582. })
  583. };
  584. $scope.bigImage = false;
  585. $scope.showBigImage = function ($event, imageName) {
  586. $event.stopPropagation();
  587. $scope.url = imageName;
  588. $scope.bigImage = true;
  589. };
  590. $scope.hideBigImage = function(){
  591. $scope.bigImage = false;
  592. };
  593. $ionicModal.fromTemplateUrl('qrCode.html', {
  594. scope: $scope,
  595. animation: 'slide-in-up'
  596. }).then(function(modal) {
  597. $scope.qrCodemodal = modal;
  598. });
  599. $scope.openCode = function() {
  600. $scope.qrCodemodal.show();
  601. $scope.vm.money = '';
  602. };
  603. $scope.closeCode = function() {
  604. $scope.qrCodemodal.hide();
  605. };
  606. $ionicModal.fromTemplateUrl('commentPic.html', {
  607. scope: $scope,
  608. animation: 'slide-in-up'
  609. }).then(function(modal) {
  610. $scope.CommentPicmodal = modal;
  611. });
  612. $scope.openCommentPic = function(pic) {
  613. $scope.CommentPicmodal.show();
  614. $scope.commentPicUrl = pic;
  615. };
  616. $scope.closeCommentPic = function() {
  617. $scope.CommentPicmodal.hide();
  618. };
  619. $scope.addpict = function () {
  620. common.chooseImage().then(function (img) {
  621. common.uploadFiles(img,1).then(function (result) {
  622. var response = JSON.parse(result.response);
  623. var file = response.data.file;
  624. $scope.imgs.push(config.imgServer+file);
  625. console.log(JSON.stringify(config.imgServer+file));
  626. }, function (error) {
  627. msg.error('图片上传失败');
  628. });
  629. }, function (error) {
  630. console.log('图片选择失败');
  631. });
  632. };
  633. $scope.deletefile = function (file) {
  634. var index = $scope.imgs.indexOf(file);
  635. $scope.imgs.splice(index, 1);
  636. common.deletefile(file).then(function () {
  637. })
  638. };
  639. $scope.addvideo = function () {
  640. common.chooseVideo().then(function (file) {
  641. common.uploadFiles(file, 2).then(function (result) {
  642. var response = JSON.parse(result.response);
  643. $scope.video.server = response.data.file;
  644. var file = config.imgServer+response.data.file;
  645. console.log("file:"+file);
  646. $scope.video.isOK = true;
  647. $scope.video.file = file;
  648. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  649. console.log("vpic:"+$scope.video.vpic);
  650. }, function (error) {
  651. msg.error('视频上传失败');
  652. });
  653. }, function (erro) {
  654. console.log('选择视频失败');
  655. });
  656. };
  657. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  658. scope: $scope,
  659. animation: 'slide-in-up'
  660. }).then(function(modal) {
  661. $scope.rechagemodal = modal;
  662. });
  663. $scope.openRechargeModal = function() {
  664. $scope.rechagemodal.show();
  665. $scope.vm.money = '';
  666. };
  667. $scope.closeRechargeModal = function() {
  668. $scope.rechagemodal.hide();
  669. };
  670. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  671. scope: $scope,
  672. animation: 'slide-in-up'
  673. }).then(function(modal) {
  674. $scope.modal = modal;
  675. });
  676. $scope.openModal = function() {
  677. $scope.modal.show();
  678. $scope.vm.title = '';
  679. $scope.imgs = [];
  680. $scope.video = {};
  681. };
  682. $scope.closeModal = function() {
  683. $scope.modal.hide();
  684. };
  685. //当我们用到模型时,清除它!
  686. $scope.$on('$destroy', function() {
  687. $scope.modal.remove();
  688. });
  689. $scope.toMessage = function(){
  690. $state.go("app.message");
  691. }
  692. }]);
  693. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  694. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  695. var id = $stateParams.id;
  696. var top3user = '';
  697. $scope.chosedIndex = 0;
  698. $scope.clickAvatar = function(index){
  699. $scope.chosedIndex = index;
  700. homeService.myInfo().then(function(result){
  701. $scope.user = result.data.data;
  702. });
  703. };
  704. // id=5;
  705. $scope.$on('$ionicView.beforeEnter', function () {
  706. $ionicTabsDelegate.showBar(false);
  707. $scope.load(id);
  708. $scope.thisUser = storage.getObject('user');
  709. homeService.myInfo().then(function(result){
  710. $scope.user = result.data.data;
  711. });
  712. homeService.messageInfo().then(function(result){
  713. $scope.infos = result.data.data;
  714. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  715. $scope.showMessage=0;
  716. }
  717. else {
  718. $scope.showMessage=1;
  719. }
  720. },function(error){
  721. });
  722. });
  723. $scope.$on('$ionicView.leave', function () {
  724. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  725. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  726. });
  727. $scope.toSort = function(){
  728. //$scope.type = 3;
  729. $scope.changeType(3)
  730. };
  731. $scope.load = function (id) {
  732. msg.loading();
  733. homeService.dreamDetail(id).then(function (result) {
  734. msg.hide();
  735. console.log(result);
  736. $scope.showCode = function(codeName){
  737. $scope.url = codeName;
  738. $scope.code = true;
  739. };
  740. $scope.hideCode = function(){
  741. $scope.code = false;
  742. };
  743. $scope.dream = result.data.data;
  744. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  745. $scope.codeBtn = true;
  746. }
  747. if($scope.dream.video){
  748. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  749. $scope.dream.video = config.imgServer+$scope.dream.video;
  750. }
  751. var reg = new RegExp("\n", "g");
  752. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  753. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  754. var date = new Date();
  755. var inter = (end_time.getTime() - date.getTime()) / 1000;
  756. leftTimer(inter);
  757. $scope.multi.a = $scope.dream.a;
  758. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  759. $scope.multi.c = $scope.dream.c;
  760. $scope.multi.promise = $scope.dream.a;
  761. var newtop3user = '' ;
  762. angular.forEach($scope.dream.top3user, function(user) {
  763. newtop3user= newtop3user +user.id+","
  764. });
  765. if(top3user!=''&&newtop3user!=top3user){
  766. //测试动画切换
  767. $timeout(function() {
  768. $scope.sort.slide1 = 'list-grow-animation';
  769. $scope.sort.slide2 = 'slide-in-both-ways';
  770. $scope.sort.slide3 = 'bounce-animation';
  771. }, 50);
  772. }
  773. top3user = newtop3user;
  774. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  775. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  776. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  777. $scope.calcmultiplier();
  778. }, function (error) {
  779. msg.hide();
  780. });
  781. };
  782. $scope.openSupport = function () {
  783. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  784. };
  785. $scope.multi = {
  786. a: '',
  787. b: '',
  788. c: '',
  789. result: 1,
  790. promise:null
  791. };
  792. $scope.type = 1;//tab切换
  793. $scope.tosupport = false;
  794. $scope.support = function ($event) {
  795. $event.stopPropagation();
  796. $scope.tosupport = true;
  797. $scope.vm.coin = 0;
  798. $scope.index = 0;
  799. };
  800. $scope.cancelSupport = function () {
  801. $scope.tosupport = false;
  802. $scope.toshare = false;
  803. $scope.input.show = false;
  804. };
  805. $scope.toshare = false;
  806. $scope.toRecharge = function(){
  807. $state.go("app.recharge")
  808. };
  809. $scope.share = function (type,$event) {
  810. $scope.toshare = true;
  811. if (type==0) {//分享给朋友
  812. /* Wechat.share({
  813. text: "分享的文字",
  814. scene: Wechat.Scene.SESSION // share to 好友
  815. }, function () {
  816. alert("Success");
  817. }, function (reason) {
  818. alert("Failed: " + reason);
  819. });*/
  820. Wechat.share({
  821. message: {
  822. title:"瞄瞄",
  823. description:"HELLO,这是我的梦想,快来围观吧!",
  824. thumb:"img/icon_cat_h.png",
  825. media: {
  826. type: Wechat.Type.WEBPAGE,
  827. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  828. }
  829. },
  830. scene: Wechat.Scene.SESSION
  831. }, function () {
  832. alert("Success");
  833. }, function (reason) {
  834. alert("Failed: " + reason);
  835. });
  836. }
  837. if(type==1){
  838. Wechat.share({
  839. message: {
  840. title:"瞄瞄",
  841. description:"HELLO,这是我的梦想,快来围观吧!",
  842. thumb:"img/icon_cat_h.png",
  843. media: {
  844. type: Wechat.Type.WEBPAGE,
  845. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  846. }
  847. },
  848. scene: Wechat.Scene.TIMELINE
  849. }, function () {
  850. alert("Success");
  851. }, function (reason) {
  852. alert("Failed: " + reason);
  853. });
  854. }
  855. // $state.go("app.shareDream",{item:$scope.dream});
  856. };
  857. //实时排行
  858. $scope.sort = {
  859. slide: ''
  860. };
  861. $scope.changeType = function (type) {
  862. $ionicScrollDelegate.scrollTop(true);
  863. $scope.type = type;
  864. };
  865. $scope.index = 0;
  866. $scope.vm = {
  867. coin:"",
  868. title:""
  869. };
  870. $scope.timer = '';
  871. var leftTimer = function (countDown) {
  872. if (isNaN(countDown)) {
  873. $scope.timer = '已结束';
  874. return;
  875. }
  876. var day=parseInt(countDown/(24*60*60));
  877. var h=parseInt(countDown/(60*60)%24);
  878. var m=parseInt(countDown/60%60);
  879. var s=parseInt(countDown%60);
  880. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  881. if(day>0) $scope.timer = day+'天';
  882. if(day<0 && h>0) $scope.timer = h+'小时';
  883. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  884. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  885. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  886. $scope.leftTimer = $interval(function () {
  887. if (countDown >= 1) leftTimer(countDown - 1);
  888. },1000);*/
  889. /*if(countDown<=0){
  890. $scope.timer='结束';
  891. }*/
  892. };
  893. $scope.changeIndex = function (index) {
  894. $scope.index = index;
  895. $scope.vm.coin = index*10;
  896. };
  897. $scope.vidEnded = function () {
  898. alert('播放完毕');
  899. };
  900. //实时计算支持乘数
  901. $scope.calcmultiplier = function () {
  902. $scope.multi.promise = $interval(function () {
  903. var date = new Date();
  904. var inter = date.getTime() - $scope.multi.b.getTime();
  905. var minutes = Math.floor(inter / (60 * 1000));
  906. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  907. if (number<=1) {
  908. number = 1;
  909. }
  910. //$scope.multi.result = Math.round(number * 100) / 100;
  911. $scope.multi.result = Math.round(number * 100 / 100);
  912. },1000);
  913. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  914. };
  915. $scope.supportDream = function (data) {
  916. if(!$scope.vm.coin){
  917. msg.error("请选择梦想币数量!");
  918. return ;
  919. }
  920. var data = {
  921. id:id,
  922. coin:$scope.vm.coin
  923. };
  924. homeService.supportDream(data).then(function(result){
  925. $scope.tosupport = false;
  926. $scope.load(id);
  927. homeService.myInfo().then(function(result){
  928. $scope.user = result.data.data;
  929. });
  930. $interval.cancel($scope.multi.promise);
  931. msg.text("发送成功");
  932. })
  933. };
  934. $scope.collectionDream = function(is_collection){
  935. homeService.collectionDream(id,is_collection).then(function(result){
  936. $scope.dream.is_collection=result.data.data;
  937. })
  938. };
  939. $scope.add = function(is_collection){
  940. var data = {
  941. id:id,
  942. title:$scope.vm.title,
  943. pics:$scope.imgs,
  944. video:$scope.video.server
  945. };
  946. homeService.add_interaction(data).then(function(){
  947. $scope.load(id);
  948. $scope.closeModal();
  949. })
  950. };
  951. $scope.showAbout = true;
  952. $scope.hideAbout = false;
  953. $scope.showText = function(){
  954. $scope.aboutStyle = {
  955. "white-space" : "normal"
  956. };
  957. $scope.showAbout = false;
  958. $scope.hideAbout = true;
  959. };
  960. $scope.hideText = function(){
  961. $scope.aboutStyle = {
  962. "white-space" : "nowrap"
  963. };
  964. $scope.showAbout = true;
  965. $scope.hideAbout = false;
  966. };
  967. $scope.input = {
  968. placeholder: '评论',
  969. focus: false,
  970. show:false
  971. };
  972. $scope.replay = function ($event, name) {
  973. $event.stopPropagation();
  974. $scope.input.focus = true;
  975. $scope.input.show = true;
  976. $scope.input.placeholder = "评论" + name+":";
  977. $scope.vm.title='';
  978. };
  979. $scope.submitComment = function (index) {
  980. var interaction = $scope.dream.interactions[index];
  981. var iid = interaction.id;
  982. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  983. $scope.input.focus = true;
  984. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  985. var data = {
  986. id:iid,
  987. content:$scope.vm.comment
  988. };
  989. console.log($scope.vm.comment+" "+iid);
  990. homeService.add_comment(data).then(function(){
  991. $scope.vm.comment = '' ;
  992. $scope.load(id);
  993. $scope.closeModal();
  994. })
  995. };
  996. $scope.bigImage = false;
  997. $scope.showBigImage = function ($event,imageName) {
  998. $event.stopPropagation();
  999. $scope.url = imageName;
  1000. $scope.bigImage = true;
  1001. };
  1002. $scope.hideBigImage = function(){
  1003. $scope.bigImage = false;
  1004. };
  1005. $ionicModal.fromTemplateUrl('qrCode.html', {
  1006. scope: $scope,
  1007. animation: 'slide-in-up'
  1008. }).then(function(modal) {
  1009. $scope.qrCodemodal = modal;
  1010. });
  1011. $ionicModal.fromTemplateUrl('commentPic.html', {
  1012. scope: $scope,
  1013. animation: 'slide-in-up'
  1014. }).then(function(modal) {
  1015. $scope.CommentPicmodal = modal;
  1016. });
  1017. $scope.openCode = function() {
  1018. $scope.qrCodemodal.show();
  1019. };
  1020. $scope.closeCode = function() {
  1021. $scope.qrCodemodal.hide();
  1022. };
  1023. $ionicModal.fromTemplateUrl('commentPic.html', {
  1024. scope: $scope,
  1025. animation: 'slide-in-up'
  1026. }).then(function(modal) {
  1027. $scope.CommentPicmodal = modal;
  1028. });
  1029. $scope.openCommentPic = function(pic) {
  1030. $scope.CommentPicmodal.show();
  1031. $scope.commentPicUrl = pic;
  1032. };
  1033. $scope.closeCommentPic = function() {
  1034. $scope.CommentPicmodal.hide();
  1035. };
  1036. $scope.addpict = function () {
  1037. common.chooseImage().then(function (img) {
  1038. common.uploadFiles(img,1).then(function (result) {
  1039. var response = JSON.parse(result.response);
  1040. var file = response.data.file;
  1041. $scope.imgs.push(config.imgServer+file);
  1042. console.log(JSON.stringify(config.imgServer+file));
  1043. }, function (error) {
  1044. msg.error('图片上传失败');
  1045. });
  1046. }, function (error) {
  1047. console.log('图片选择失败');
  1048. });
  1049. };
  1050. $scope.deletefile = function (file) {
  1051. var index = $scope.imgs.indexOf(file);
  1052. $scope.imgs.splice(index, 1);
  1053. common.deletefile(file).then(function () {
  1054. })
  1055. };
  1056. $scope.addvideo = function () {
  1057. common.chooseVideo().then(function (file) {
  1058. common.uploadFiles(file, 2).then(function (result) {
  1059. var response = JSON.parse(result.response);
  1060. $scope.video.server = response.data.file;
  1061. var file = config.imgServer+response.data.file;
  1062. console.log("file:"+file);
  1063. $scope.video.isOK = true;
  1064. $scope.video.file = file;
  1065. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  1066. console.log("vpic:"+$scope.video.vpic);
  1067. }, function (error) {
  1068. msg.error('视频上传失败');
  1069. });
  1070. }, function (erro) {
  1071. console.log('选择视频失败');
  1072. });
  1073. };
  1074. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  1075. scope: $scope,
  1076. animation: 'slide-in-up'
  1077. }).then(function(modal) {
  1078. $scope.rechagemodal = modal;
  1079. });
  1080. $scope.openRechargeModal = function() {
  1081. $scope.rechagemodal.show();
  1082. $scope.vm.money = '';
  1083. };
  1084. $scope.closeRechargeModal = function() {
  1085. $scope.rechagemodal.hide();
  1086. };
  1087. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  1088. scope: $scope,
  1089. animation: 'slide-in-up'
  1090. }).then(function(modal) {
  1091. $scope.modal = modal;
  1092. });
  1093. $scope.openModal = function() {
  1094. $scope.modal.show();
  1095. $scope.vm.title = '';
  1096. $scope.imgs = [];
  1097. $scope.video = {};
  1098. };
  1099. $scope.closeModal = function() {
  1100. $scope.modal.hide();
  1101. };
  1102. //当我们用到模型时,清除它!
  1103. $scope.$on('$destroy', function() {
  1104. $scope.modal.remove();
  1105. });
  1106. $scope.toMessage = function(){
  1107. $state.go("app.my_message");
  1108. }
  1109. }]);
  1110. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  1111. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  1112. var id = $stateParams.id;
  1113. $scope.items = $stateParams.items;
  1114. $scope.$on('$ionicView.beforeEnter', function () {
  1115. $ionicTabsDelegate.showBar(false);
  1116. });
  1117. $scope.attentionUser = function(is_care){
  1118. homeService.attentionUser(id,is_care).then(function(result){
  1119. $scope.items.is_care=result.data.data;
  1120. })
  1121. };
  1122. $scope.next = function (type) {
  1123. //type:1 前一个,type:2 后一个
  1124. if($scope.items.imgs.length>0){
  1125. if(type==1)
  1126. {
  1127. var temp= $scope.items.imgs.splice(0,1);
  1128. $scope.items.imgs.push(temp[0]);
  1129. }
  1130. if (type==2){
  1131. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  1132. $scope.items.imgs.unshift(temp[0]);
  1133. }
  1134. }
  1135. };
  1136. $scope.bigImage = false;
  1137. $scope.showBigImage = function(imageName){
  1138. $scope.url = imageName;
  1139. $scope.bigImage = true;
  1140. };
  1141. $scope.hideBigImage = function(){
  1142. $scope.bigImage = false;
  1143. };
  1144. $scope.cancelSupport = function () {
  1145. $scope.tosupport = false;
  1146. $scope.toshare = false;
  1147. };
  1148. $scope.toshare = false;
  1149. $scope.toshare = false;
  1150. $scope.toRecharge = function(){
  1151. $state.go("app.recharge")
  1152. };
  1153. $scope.share = function (type,$event) {
  1154. $scope.toshare = true;
  1155. if (type==0) {//分享给朋友
  1156. /* Wechat.share({
  1157. text: "分享的文字",
  1158. scene: Wechat.Scene.SESSION // share to 好友
  1159. }, function () {
  1160. alert("Success");
  1161. }, function (reason) {
  1162. alert("Failed: " + reason);
  1163. });*/
  1164. Wechat.share({
  1165. message: {
  1166. title:"瞄瞄",
  1167. description:"HELLO,这是我的个人资料,快来围观吧!",
  1168. thumb:"img/icon_cat_h.png",
  1169. media: {
  1170. type: Wechat.Type.WEBPAGE,
  1171. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  1172. }
  1173. },
  1174. scene: Wechat.Scene.SESSION
  1175. }, function () {
  1176. alert("Success");
  1177. }, function (reason) {
  1178. alert("Failed: " + reason);
  1179. });
  1180. }
  1181. if(type==1){
  1182. Wechat.share({
  1183. message: {
  1184. title:"瞄瞄",
  1185. description:"HELLO,这是我的个人资料,快来围观吧!",
  1186. thumb:"img/icon_cat_h.png",
  1187. media: {
  1188. type: Wechat.Type.WEBPAGE,
  1189. webpageUrl: "q8.9026.com//admin/share/view?id=" + id
  1190. }
  1191. },
  1192. scene: Wechat.Scene.TIMELINE
  1193. }, function () {
  1194. alert("Success");
  1195. }, function (reason) {
  1196. alert("Failed: " + reason);
  1197. });
  1198. }
  1199. // $state.go("app.shareDream",{item:$scope.dream});
  1200. };
  1201. $scope.toDetail = function (dream_id) {
  1202. if($scope.items.near_dream==null){
  1203. msg.alert("当前梦想","该用户没有当前梦想");
  1204. }
  1205. if($scope.items.near_dream!=null){
  1206. var dream_id = $scope.items.near_dream.id;
  1207. $state.go('app.home_dreamdetail',{id:dream_id});
  1208. }
  1209. };
  1210. $scope.toOldDream = function(){
  1211. if($scope.items.dreams.length<2){
  1212. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  1213. }
  1214. if($scope.items.dreams.length>1){
  1215. $state.go("app.oldDream",{user_id:$scope.items.user.id});
  1216. }
  1217. };
  1218. $scope.toSupportDream = function(){
  1219. if($scope.items.sup_dreams.length==0){
  1220. msg.alert("支持的梦想","该用户没有支持的梦想");
  1221. }
  1222. if($scope.items.sup_dreams.length!=0){
  1223. $state.go("app.supportDream",{user_id:$scope.items.user.id});
  1224. }
  1225. };
  1226. $scope.collectionDream = function(is_collection){
  1227. homeService.collectionDream(id,is_collection).then(function(result){
  1228. $scope.user.is_collection=result.data.data;
  1229. })
  1230. };
  1231. }]);
  1232. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  1233. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  1234. $scope.$on('$ionicView.beforeEnter', function () {
  1235. $ionicTabsDelegate.showBar(false);
  1236. myService.collect().then(function(result){
  1237. $scope.dreams = result.data.data.dreams;
  1238. });
  1239. });
  1240. $scope.toDetail = function (id) {
  1241. $state.go('app.home_dreamdetail',{id:id});
  1242. };
  1243. }]);
  1244. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1245. , function ($scope,homeService,$stateParams, $state, msg) {
  1246. $scope.dream = $stateParams.item;
  1247. $scope.showAbout = true;
  1248. $scope.hideAbout = false;
  1249. $scope.showText = function(){
  1250. $scope.aboutStyle = {
  1251. "white-space" : "normal"
  1252. };
  1253. $scope.showAbout = false;
  1254. $scope.hideAbout = true;
  1255. };
  1256. $scope.hideText = function(){
  1257. $scope.aboutStyle = {
  1258. "white-space" : "nowrap"
  1259. };
  1260. $scope.showAbout = true;
  1261. $scope.hideAbout = false;
  1262. };
  1263. }]);
  1264. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  1265. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  1266. $scope.$on('$ionicView.beforeEnter', function () {
  1267. $ionicTabsDelegate.showBar(false);
  1268. myService.messageInfo().then(function(result){
  1269. $scope.infos = result.data.data;
  1270. },function(error){
  1271. });
  1272. });
  1273. $scope.notRead = function(){
  1274. myService.notRead().then(function(result){
  1275. myService.messageInfo().then(function(result){
  1276. $scope.infos = result.data.data;
  1277. },function(error){
  1278. });
  1279. },function(error){
  1280. })
  1281. };
  1282. //系统消息
  1283. $scope.systemInfo = function(){
  1284. $state.go("app.message_sys");
  1285. myService.systemInfo().then(function(result){
  1286. },function(error){
  1287. });
  1288. };
  1289. //回复我的
  1290. $scope.replyMy = function(){
  1291. $state.go("app.message_reply");
  1292. myService.replyMy().then(function(result){
  1293. },function(error){
  1294. });
  1295. };
  1296. $scope.personalLetter = function(){
  1297. $state.go("app.letter");
  1298. }
  1299. }]);
  1300. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1301. , function ($scope,homeService,$stateParams, $state, msg) {
  1302. var user_id = $stateParams.user_id;
  1303. $scope.$on('$ionicView.beforeEnter',function(){
  1304. $scope.toUserDetail(user_id);
  1305. });
  1306. $scope.toUserDetail = function(user_id){
  1307. homeService.toUserDetail(user_id).then(function(result){
  1308. $scope.items = result.data.data;
  1309. $scope.user = result.data.data.user;
  1310. $scope.dreams = $scope.user.dreams;
  1311. },function(error){
  1312. })
  1313. };
  1314. $scope.toDetail = function(){
  1315. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1316. };
  1317. }]);
  1318. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  1319. , function ($scope,homeService,$stateParams, $state, msg) {
  1320. var user_id = $stateParams.user_id;
  1321. $scope.$on('$ionicView.beforeEnter',function(){
  1322. $scope.toUserDetail(user_id);
  1323. });
  1324. $scope.toUserDetail = function(user_id){
  1325. homeService.toUserDetail(user_id).then(function(result){
  1326. $scope.items = result.data.data;
  1327. $scope.user = result.data.data.user;
  1328. $scope.dreams = $scope.user.sup_dream;
  1329. },function(error){
  1330. })
  1331. };
  1332. $scope.toDetail = function(){
  1333. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  1334. }
  1335. }]);
  1336. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1337. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1338. $scope.showMore = function (keyword,index) {
  1339. if(!keyword)return;
  1340. $scope.index = index;
  1341. $scope.search(keyword);
  1342. };
  1343. $scope.search = function (keyword) {
  1344. $scope.vm.keyword = keyword;
  1345. homeService.search(keyword).then(function(result){
  1346. $scope.isResult = true;
  1347. $scope.dream_infos = result.data.data.dream_infos;
  1348. $scope.user_infos = result.data.data.user_infos;
  1349. });
  1350. };
  1351. $scope.toUserDetail = function (id) {
  1352. homeService.toUserDetail(id).then(function(result){
  1353. $scope.items = result.data.data;
  1354. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  1355. },function(error){
  1356. //msg.error(msg.data.error)
  1357. })
  1358. };
  1359. $scope.toDetail = function (id) {
  1360. $state.go('app.home_dreamdetail',{id:id});
  1361. };
  1362. $scope.$on('$ionicView.beforeEnter', function () {
  1363. $scope.isResult = false;
  1364. $scope.index = 0;
  1365. $scope.vm = {
  1366. keyword : ""
  1367. };
  1368. $ionicTabsDelegate.showBar(false);
  1369. // $ionicNavBarDelegate.showBackButton(false);
  1370. homeService.search('').then(function(result){
  1371. $scope.hot_searches = result.data.data.hot_searches;
  1372. $scope.history_searches = result.data.data.history_searches;
  1373. });
  1374. });
  1375. }]);
  1376. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  1377. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  1378. }]);
  1379. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  1380. , function ($scope, $state, myService, msg) {
  1381. $scope.$on('$ionicView.beforeEnter', function () {
  1382. myService.myDream().then(function(result){
  1383. console.log(result.data.data);
  1384. $scope.dreams = result.data.data;
  1385. });
  1386. });
  1387. $scope.toDetail = function (id) {
  1388. $state.go('app.home_dreamdetail',{id:id});
  1389. };
  1390. }]);
  1391. })(angular.module('app.controllers'));