home.js 34 KB

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