home.js 32 KB

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