home.js 33 KB

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