home.js 32 KB

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