home.js 37 KB

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