home.js 32 KB

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