home.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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. };
  211. $scope.toshare = false;
  212. $scope.share = function ($event) {
  213. $event.stopPropagation();
  214. $scope.toshare = true;
  215. };
  216. $scope.toRecharge = function(){
  217. $state.go("app.recharge")
  218. };
  219. $scope.shareDream = function(){
  220. $state.go("app.shareDream",{item:$scope.dream});
  221. };
  222. //实时排行
  223. $scope.sort = {
  224. slide: ''
  225. };
  226. $scope.changeType = function (type) {
  227. $ionicScrollDelegate.scrollTop(true);
  228. $scope.type = type;
  229. };
  230. $scope.index = 0;
  231. $scope.vm = {
  232. coin:"",
  233. title:""
  234. };
  235. $scope.timer = '';
  236. var leftTimer = function (countDown) {
  237. if (isNaN(countDown)) {
  238. $scope.timer = '结束';
  239. return;
  240. }
  241. var day=parseInt(countDown/(24*60*60));
  242. var h=parseInt(countDown/(60*60)%24);
  243. var m=parseInt(countDown/60%60);
  244. var s=parseInt(countDown%60);
  245. $scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  246. if(day>0) $scope.timer = day+'天'+ $scope.timer;
  247. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  248. $scope.leftTimer = $interval(function () {
  249. if (countDown >= 1) leftTimer(countDown - 1);
  250. },1000);
  251. if(countDown<=0){
  252. $scope.timer='结束';
  253. }
  254. };
  255. $scope.changeIndex = function (index) {
  256. $scope.index = index;
  257. $scope.vm.coin = index*5;
  258. };
  259. $scope.vidEnded = function () {
  260. alert('播放完毕');
  261. };
  262. //实时计算支持乘数
  263. $scope.calcmultiplier = function () {
  264. $scope.multi.promise = $interval(function () {
  265. var date = new Date();
  266. var inter = date.getTime() - $scope.multi.b.getTime();
  267. var minutes = Math.floor(inter / (60 * 1000));
  268. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  269. if (number<=1) {
  270. number = 1;
  271. }
  272. //$scope.multi.result = Math.round(number * 100) / 100;
  273. $scope.multi.result = Math.round(number * 100 / 100);
  274. },1000);
  275. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  276. };
  277. $scope.supportDream = function (data) {
  278. if(!$scope.vm.coin){
  279. msg.error("请选择梦想币数量!");
  280. return ;
  281. }
  282. var data = {
  283. id:id,
  284. coin:$scope.vm.coin
  285. };
  286. homeService.supportDream(data).then(function(result){
  287. $scope.tosupport = false;
  288. $scope.load(id);
  289. $interval.cancel($scope.multi.promise);
  290. })
  291. };
  292. $scope.collectionDream = function(is_collection){
  293. homeService.collectionDream(id,is_collection).then(function(result){
  294. $scope.dream.is_collection=result.data.data;
  295. })
  296. };
  297. $scope.add = function(is_collection){
  298. var data = {
  299. id:id,
  300. title:$scope.vm.title,
  301. pics:$scope.imgs
  302. };
  303. homeService.add_interaction(data).then(function(){
  304. $scope.load(id);
  305. $scope.closeModal();
  306. })
  307. };
  308. $scope.showAbout = true;
  309. $scope.hideAbout = false;
  310. $scope.showText = function(){
  311. $scope.aboutStyle = {
  312. "white-space" : "normal"
  313. };
  314. $scope.showAbout = false;
  315. $scope.hideAbout = true;
  316. };
  317. $scope.hideText = function(){
  318. $scope.aboutStyle = {
  319. "white-space" : "nowrap"
  320. };
  321. $scope.showAbout = true;
  322. $scope.hideAbout = false;
  323. };
  324. $scope.input = {
  325. placeholder: '评论',
  326. focus:false
  327. };
  328. $scope.replay = function ($event, name) {
  329. $event.stopPropagation();
  330. $scope.input.focus = true;
  331. $scope.input.placeholder = "回复" + name;
  332. $scope.vm.title='';
  333. };
  334. $scope.comment = function(){
  335. // $event.stopPropagation();
  336. //$scope.input.placeholder = "评论";
  337. $scope.input.focus = true;
  338. $scope.vm.title='';
  339. };
  340. $scope.submitComment = function(iid){
  341. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  342. var data = {
  343. id:iid,
  344. content:$scope.vm.comment
  345. };
  346. console.log($scope.vm.comment+" "+iid);
  347. homeService.add_comment(data).then(function(){
  348. $scope.vm.comment = '' ;
  349. $scope.load(id);
  350. $scope.closeModal();
  351. })
  352. };
  353. $scope.addpict = function () {
  354. common.chooseImage().then(function (img) {
  355. common.uploadFiles(img,1).then(function (result) {
  356. var response = JSON.parse(result.response);
  357. var file = response.data.file;
  358. $scope.imgs.push(config.imgServer+file);
  359. console.log(JSON.stringify(config.imgServer+file));
  360. }, function (error) {
  361. msg.error('图片上传失败');
  362. });
  363. }, function (error) {
  364. console.log('图片选择失败');
  365. });
  366. };
  367. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  368. scope: $scope,
  369. animation: 'slide-in-up'
  370. }).then(function(modal) {
  371. $scope.rechagemodal = modal;
  372. });
  373. $scope.openRechargeModal = function() {
  374. $scope.rechagemodal.show();
  375. $scope.vm.money = '';
  376. };
  377. $scope.closeRechargeModal = function() {
  378. $scope.rechagemodal.hide();
  379. };
  380. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  381. scope: $scope,
  382. animation: 'slide-in-up'
  383. }).then(function(modal) {
  384. $scope.modal = modal;
  385. });
  386. $scope.openModal = function() {
  387. $scope.modal.show();
  388. $scope.vm.title = '';
  389. $scope.imgs = [];
  390. };
  391. $scope.closeModal = function() {
  392. $scope.modal.hide();
  393. };
  394. //当我们用到模型时,清除它!
  395. $scope.$on('$destroy', function() {
  396. $scope.modal.remove();
  397. });
  398. $scope.toMessage = function(){
  399. $state.go("app.message");
  400. }
  401. }]);
  402. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  403. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  404. var id = $stateParams.id;
  405. var top3user = '';
  406. $scope.chosedIndex = 0;
  407. $scope.clickAvatar = function(index){
  408. $scope.chosedIndex = index;
  409. };
  410. // id=5;
  411. $scope.$on('$ionicView.beforeEnter', function () {
  412. $ionicTabsDelegate.showBar(false);
  413. $scope.load(id);
  414. $scope.thisUser = storage.getObject('user');
  415. homeService.myInfo().then(function(result){
  416. $scope.user = result.data.data;
  417. });
  418. console.log($scope.user);
  419. });
  420. $scope.$on('$ionicView.leave', function () {
  421. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  422. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  423. });
  424. $scope.load = function (id) {
  425. msg.loading();
  426. homeService.dreamDetail(id).then(function (result) {
  427. msg.hide();
  428. console.log(result);
  429. $scope.dream = result.data.data;
  430. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  431. var date = new Date();
  432. var inter = (end_time.getTime() - date.getTime()) / 1000;
  433. leftTimer(inter);
  434. $scope.multi.a = $scope.dream.a;
  435. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  436. $scope.multi.c = $scope.dream.c;
  437. $scope.multi.promise = $scope.dream.a;
  438. var newtop3user = '' ;
  439. angular.forEach($scope.dream.top3user, function(user) {
  440. newtop3user= newtop3user +user.id+","
  441. });
  442. if(top3user!=''&&newtop3user!=top3user){
  443. //测试动画切换
  444. $timeout(function() {
  445. $scope.sort.slide1 = 'list-grow-animation';
  446. $scope.sort.slide2 = 'slide-in-both-ways';
  447. $scope.sort.slide3 = 'bounce-animation';
  448. }, 50);
  449. }
  450. top3user = newtop3user;
  451. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  452. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  453. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  454. $scope.calcmultiplier();
  455. }, function (error) {
  456. msg.hide();
  457. });
  458. };
  459. $scope.openSupport = function () {
  460. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  461. };
  462. // $ionicModal.fromTemplateUrl('supportExplain.html', {
  463. // scope: $scope
  464. // }).then(function(modal) {
  465. // $scope.supportmodal = modal;
  466. // });
  467. // $scope.openSupportmodal = function() {
  468. // $scope.supportmodal.show();
  469. // };
  470. // $scope.closeSupportmodal = function() {
  471. // $scope.supportmodal.hide();
  472. // };
  473. $scope.multi = {
  474. a: '',
  475. b: '',
  476. c: '',
  477. result: 1,
  478. promise:null
  479. };
  480. $scope.type = 1;//tab切换
  481. $scope.tosupport = false;
  482. $scope.support = function ($event) {
  483. $event.stopPropagation();
  484. $scope.tosupport = true;
  485. $scope.vm.coin = 0;
  486. $scope.index = 0;
  487. };
  488. $scope.cancelSupport = function () {
  489. $scope.tosupport = false;
  490. $scope.toshare = false;
  491. };
  492. $scope.toshare = false;
  493. $scope.share = function ($event) {
  494. $event.stopPropagation();
  495. $scope.toshare = true;
  496. };
  497. $scope.toRecharge = function(){
  498. $state.go("app.recharge")
  499. };
  500. $scope.shareDream = function(){
  501. $state.go("app.my_shareDream",{item:$scope.dream});
  502. };
  503. //实时排行
  504. $scope.sort = {
  505. slide: ''
  506. };
  507. $scope.changeType = function (type) {
  508. $ionicScrollDelegate.scrollTop(true);
  509. $scope.type = type;
  510. };
  511. $scope.index = 0;
  512. $scope.vm = {
  513. coin:"",
  514. title:""
  515. };
  516. $scope.timer = '';
  517. var leftTimer = function (countDown) {
  518. if (isNaN(countDown)) {
  519. $scope.timer = '结束';
  520. return;
  521. }
  522. var day=parseInt(countDown/(24*60*60));
  523. var h=parseInt(countDown/(60*60)%24);
  524. var m=parseInt(countDown/60%60);
  525. var s=parseInt(countDown%60);
  526. $scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  527. if(day>0) $scope.timer = day+'天'+ $scope.timer;
  528. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  529. $scope.leftTimer = $interval(function () {
  530. if (countDown >= 1) leftTimer(countDown - 1);
  531. },1000);
  532. if(countDown<=0){
  533. $scope.timer='结束';
  534. }
  535. };
  536. $scope.changeIndex = function (index) {
  537. $scope.index = index;
  538. $scope.vm.coin = index*5;
  539. };
  540. $scope.vidEnded = function () {
  541. alert('播放完毕');
  542. };
  543. //实时计算支持乘数
  544. $scope.calcmultiplier = function () {
  545. $scope.multi.promise = $interval(function () {
  546. var date = new Date();
  547. var inter = date.getTime() - $scope.multi.b.getTime();
  548. var minutes = Math.floor(inter / (60 * 1000));
  549. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  550. if (number<=1) {
  551. number = 1;
  552. }
  553. //$scope.multi.result = Math.round(number * 100) / 100;
  554. $scope.multi.result = Math.round(number * 100 / 100);
  555. },1000);
  556. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  557. };
  558. $scope.supportDream = function (data) {
  559. if(!$scope.vm.coin){
  560. msg.error("请选择梦想币数量!");
  561. return ;
  562. }
  563. var data = {
  564. id:id,
  565. coin:$scope.vm.coin
  566. };
  567. homeService.supportDream(data).then(function(result){
  568. $scope.tosupport = false;
  569. $scope.load(id);
  570. $interval.cancel($scope.multi.promise);
  571. })
  572. };
  573. $scope.collectionDream = function(is_collection){
  574. homeService.collectionDream(id,is_collection).then(function(result){
  575. $scope.dream.is_collection=result.data.data;
  576. })
  577. };
  578. $scope.add = function(is_collection){
  579. var data = {
  580. id:id,
  581. title:$scope.vm.title,
  582. pics:$scope.imgs
  583. };
  584. homeService.add_interaction(data).then(function(){
  585. $scope.load(id);
  586. $scope.closeModal();
  587. })
  588. };
  589. $scope.showAbout = true;
  590. $scope.hideAbout = false;
  591. $scope.showText = function(){
  592. $scope.aboutStyle = {
  593. "white-space" : "normal"
  594. };
  595. $scope.showAbout = false;
  596. $scope.hideAbout = true;
  597. };
  598. $scope.hideText = function(){
  599. $scope.aboutStyle = {
  600. "white-space" : "nowrap"
  601. };
  602. $scope.showAbout = true;
  603. $scope.hideAbout = false;
  604. };
  605. $scope.input = {
  606. placeholder: '评论',
  607. focus:false
  608. };
  609. $scope.replay = function ($event, name) {
  610. $event.stopPropagation();
  611. $scope.input.focus = true;
  612. $scope.input.placeholder = "回复" + name;
  613. $scope.vm.title='';
  614. };
  615. $scope.comment = function(){
  616. // $event.stopPropagation();
  617. //$scope.input.placeholder = "评论";
  618. $scope.input.focus = true;
  619. $scope.vm.title='';
  620. };
  621. $scope.submitComment = function(iid){
  622. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  623. var data = {
  624. id:iid,
  625. content:$scope.vm.comment
  626. };
  627. console.log($scope.vm.comment+" "+iid);
  628. homeService.add_comment(data).then(function(){
  629. $scope.vm.comment = '' ;
  630. $scope.load(id);
  631. $scope.closeModal();
  632. })
  633. };
  634. $scope.addpict = function () {
  635. common.chooseImage().then(function (img) {
  636. common.uploadFiles(img,1).then(function (result) {
  637. var response = JSON.parse(result.response);
  638. var file = response.data.file;
  639. $scope.imgs.push(config.imgServer+file);
  640. console.log(JSON.stringify(config.imgServer+file));
  641. }, function (error) {
  642. msg.error('图片上传失败');
  643. });
  644. }, function (error) {
  645. console.log('图片选择失败');
  646. });
  647. };
  648. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  649. scope: $scope,
  650. animation: 'slide-in-up'
  651. }).then(function(modal) {
  652. $scope.rechagemodal = modal;
  653. });
  654. $scope.openRechargeModal = function() {
  655. $scope.rechagemodal.show();
  656. $scope.vm.money = '';
  657. };
  658. $scope.closeRechargeModal = function() {
  659. $scope.rechagemodal.hide();
  660. };
  661. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  662. scope: $scope,
  663. animation: 'slide-in-up'
  664. }).then(function(modal) {
  665. $scope.modal = modal;
  666. });
  667. $scope.openModal = function() {
  668. $scope.modal.show();
  669. $scope.vm.title = '';
  670. $scope.imgs = [];
  671. };
  672. $scope.closeModal = function() {
  673. $scope.modal.hide();
  674. };
  675. //当我们用到模型时,清除它!
  676. $scope.$on('$destroy', function() {
  677. $scope.modal.remove();
  678. });
  679. $scope.toMessage = function(){
  680. $state.go("app.my_message");
  681. }
  682. }]);
  683. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  684. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  685. var id = $stateParams.id;
  686. $scope.$on('$ionicView.beforeEnter', function () {
  687. $ionicTabsDelegate.showBar(false);
  688. });
  689. $scope.load = function (id) {
  690. msg.loading();
  691. homeService.dreamDetail(id).then(function (result) {
  692. msg.hide();
  693. $scope.user = result.data.data;
  694. }, function (error) {
  695. msg.hide();
  696. });
  697. };
  698. $scope.load(id);
  699. $scope.cancelSupport = function () {
  700. $scope.tosupport = false;
  701. $scope.toshare = false;
  702. };
  703. $scope.toshare = false;
  704. $scope.share = function ($event) {
  705. $event.stopPropagation();
  706. $scope.toshare = true;
  707. };
  708. $scope.shareDream = function(){
  709. $state.go("app.shareDream",{item:$scope.user});
  710. };
  711. $scope.toDetail = function (id) {
  712. $state.go('app.home_dreamdetail',{id:id});
  713. };
  714. $scope.toOldDream = function(){
  715. $state.go("app.oldDream");
  716. };
  717. $scope.toSupportDream = function(){
  718. $state.go("app.supportDream");
  719. };
  720. $scope.collectionDream = function(is_collection){
  721. homeService.collectionDream(id,is_collection).then(function(result){
  722. $scope.user.is_collection=result.data.data;
  723. })
  724. };
  725. }]);
  726. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  727. , function ($scope,homeService,$stateParams, $state, msg) {
  728. $scope.dream = $stateParams.item;
  729. $scope.showAbout = true;
  730. $scope.hideAbout = false;
  731. $scope.showText = function(){
  732. $scope.aboutStyle = {
  733. "white-space" : "normal"
  734. };
  735. $scope.showAbout = false;
  736. $scope.hideAbout = true;
  737. };
  738. $scope.hideText = function(){
  739. $scope.aboutStyle = {
  740. "white-space" : "nowrap"
  741. };
  742. $scope.showAbout = true;
  743. $scope.hideAbout = false;
  744. };
  745. }]);
  746. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  747. , function ($scope,homeService,$stateParams, $state, msg) {
  748. }]);
  749. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  750. , function ($scope,homeService,$stateParams, $state, msg) {
  751. }]);
  752. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  753. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  754. $scope.showMore = function (keyword,index) {
  755. if(!keyword)return;
  756. $scope.index = index;
  757. // $scope.vm.keyword = keyword;
  758. homeService.search(keyword).then(function(result){
  759. $scope.isResult = true;
  760. $scope.dream_infos = result.data.data.dream_infos;
  761. $scope.user_infos = result.data.data.user_infos;
  762. });
  763. };
  764. $scope.search = function (keyword) {
  765. $scope.vm.keyword = keyword;
  766. homeService.search(keyword).then(function(result){
  767. $scope.isResult = true;
  768. $scope.dream_infos = result.data.data.dream_infos;
  769. $scope.user_infos = result.data.data.user_infos;
  770. });
  771. };
  772. $scope.toDetail = function (id) {
  773. $state.go('app.home_dreamdetail',{id:id});
  774. };
  775. $scope.toUser = function (id) {
  776. $state.go('app.home_userDetail',{id:id});
  777. };
  778. $scope.$on('$ionicView.beforeEnter', function () {
  779. $scope.isResult = false;
  780. $scope.index = 0;
  781. $scope.vm = {
  782. keyword : ""
  783. }
  784. $ionicTabsDelegate.showBar(false);
  785. // $ionicNavBarDelegate.showBackButton(false);
  786. homeService.search('').then(function(result){
  787. $scope.hot_searches = result.data.data.hot_searches;
  788. $scope.history_searches = result.data.data.history_searches;
  789. });
  790. });
  791. }]);
  792. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  793. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  794. }]);
  795. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  796. , function ($scope, $state, myService, msg) {
  797. $scope.$on('$ionicView.beforeEnter', function () {
  798. myService.myDream().then(function(result){
  799. console.log(result.data.data);
  800. $scope.dreams = result.data.data;
  801. });
  802. });
  803. $scope.toDetail = function (id) {
  804. $state.go('app.home_dreamdetail',{id:id});
  805. };
  806. }]);
  807. })(angular.module('app.controllers'));