home.js 51 KB

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