home.js 33 KB

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