home.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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.showAbout = true;
  332. $scope.hideAbout = false;
  333. $scope.showText = function(){
  334. $scope.aboutStyle = {
  335. "white-space" : "normal"
  336. };
  337. $scope.showAbout = false;
  338. $scope.hideAbout = true;
  339. };
  340. $scope.hideText = function(){
  341. $scope.aboutStyle = {
  342. "white-space" : "nowrap"
  343. };
  344. $scope.showAbout = true;
  345. $scope.hideAbout = false;
  346. };
  347. $scope.input = {
  348. placeholder: '评论',
  349. focus:false
  350. };
  351. $scope.replay = function ($event, name) {
  352. $event.stopPropagation();
  353. $scope.input.focus = true;
  354. $scope.input.placeholder = "回复" + name;
  355. $scope.vm.title='';
  356. };
  357. $scope.comment = function(){
  358. // $event.stopPropagation();
  359. //$scope.input.placeholder = "评论";
  360. $scope.input.focus = true;
  361. $scope.vm.title='';
  362. };
  363. $scope.submitComment = function(iid){
  364. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  365. var data = {
  366. id:iid,
  367. content:$scope.vm.comment
  368. };
  369. console.log($scope.vm.comment+" "+iid);
  370. homeService.add_comment(data).then(function(){
  371. $scope.vm.comment = '' ;
  372. $scope.load(id);
  373. $scope.closeModal();
  374. })
  375. };
  376. $scope.addpict = function () {
  377. common.chooseImage().then(function (img) {
  378. common.uploadFiles(img,1).then(function (result) {
  379. var response = JSON.parse(result.response);
  380. var file = response.data.file;
  381. $scope.imgs.push(config.imgServer+file);
  382. console.log(JSON.stringify(config.imgServer+file));
  383. }, function (error) {
  384. msg.error('图片上传失败');
  385. });
  386. }, function (error) {
  387. console.log('图片选择失败');
  388. });
  389. };
  390. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  391. scope: $scope,
  392. animation: 'slide-in-up'
  393. }).then(function(modal) {
  394. $scope.rechagemodal = modal;
  395. });
  396. $scope.openRechargeModal = function() {
  397. $scope.rechagemodal.show();
  398. $scope.vm.money = '';
  399. };
  400. $scope.closeRechargeModal = function() {
  401. $scope.rechagemodal.hide();
  402. };
  403. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  404. scope: $scope,
  405. animation: 'slide-in-up'
  406. }).then(function(modal) {
  407. $scope.modal = modal;
  408. });
  409. $scope.openModal = function() {
  410. $scope.modal.show();
  411. $scope.vm.title = '';
  412. $scope.imgs = [];
  413. };
  414. $scope.closeModal = function() {
  415. $scope.modal.hide();
  416. };
  417. //当我们用到模型时,清除它!
  418. $scope.$on('$destroy', function() {
  419. $scope.modal.remove();
  420. });
  421. $scope.toMessage = function(){
  422. $state.go("app.message");
  423. }
  424. }]);
  425. app.controller('myDreamDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  426. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  427. var id = $stateParams.id;
  428. var top3user = '';
  429. $scope.toMessage = function(){
  430. $state.go("app.dream_message");
  431. }
  432. $scope.chosedIndex = 0;
  433. $scope.clickAvatar = function(index){
  434. $scope.chosedIndex = index;
  435. };
  436. // id=5;
  437. $scope.$on('$ionicView.beforeEnter', function () {
  438. $ionicTabsDelegate.showBar(false);
  439. $scope.load(id);
  440. $scope.thisUser = storage.getObject('user');
  441. homeService.myInfo().then(function(result){
  442. $scope.user = result.data.data;
  443. });
  444. console.log($scope.user);
  445. });
  446. $scope.$on('$ionicView.leave', function () {
  447. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  448. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  449. });
  450. $scope.load = function (id) {
  451. msg.loading();
  452. homeService.dreamDetail(id).then(function (result) {
  453. msg.hide();
  454. console.log(result);
  455. $scope.dream = result.data.data;
  456. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  457. var date = new Date();
  458. var inter = (end_time.getTime() - date.getTime()) / 1000;
  459. leftTimer(inter);
  460. $scope.multi.a = $scope.dream.a;
  461. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  462. $scope.multi.c = $scope.dream.c;
  463. $scope.multi.promise = $scope.dream.a;
  464. var newtop3user = '' ;
  465. angular.forEach($scope.dream.top3user, function(user) {
  466. newtop3user= newtop3user +user.id+","
  467. });
  468. if(top3user!=''&&newtop3user!=top3user){
  469. //测试动画切换
  470. $timeout(function() {
  471. $scope.sort.slide1 = 'list-grow-animation';
  472. $scope.sort.slide2 = 'slide-in-both-ways';
  473. $scope.sort.slide3 = 'bounce-animation';
  474. }, 50);
  475. }
  476. top3user = newtop3user;
  477. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  478. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  479. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  480. $scope.calcmultiplier();
  481. }, function (error) {
  482. msg.hide();
  483. });
  484. };
  485. // $ionicModal.fromTemplateUrl('supportExplain.html', {
  486. // scope: $scope
  487. // }).then(function(modal) {
  488. // $scope.supportmodal = modal;
  489. // });
  490. // $scope.openSupportmodal = function() {
  491. // $scope.supportmodal.show();
  492. // };
  493. // $scope.closeSupportmodal = function() {
  494. // $scope.supportmodal.hide();
  495. // };
  496. $scope.openSupport = function () {
  497. msg.alert("支持乘数","支持乘数支持乘数支持乘数支持乘数");
  498. };
  499. $scope.multi = {
  500. a: '',
  501. b: '',
  502. c: '',
  503. result: 1,
  504. promise:null
  505. };
  506. $scope.type = 1;//tab切换
  507. $scope.tosupport = false;
  508. $scope.support = function ($event) {
  509. $event.stopPropagation();
  510. $scope.tosupport = true;
  511. $scope.vm.coin = 0;
  512. $scope.index = 0;
  513. };
  514. $scope.cancelSupport = function () {
  515. $scope.tosupport = false;
  516. $scope.toshare = false;
  517. };
  518. $scope.toshare = false;
  519. $scope.share = function ($event) {
  520. $event.stopPropagation();
  521. $scope.toshare = true;
  522. };
  523. $scope.toRecharge = function(){
  524. $state.go("app.recharge")
  525. };
  526. $scope.shareDream = function(){
  527. $state.go("app.shareDream",{item:$scope.dream});
  528. };
  529. //实时排行
  530. $scope.sort = {
  531. slide: ''
  532. };
  533. $scope.changeType = function (type) {
  534. $ionicScrollDelegate.scrollTop(true);
  535. $scope.type = type;
  536. };
  537. $scope.index = 0;
  538. $scope.vm = {
  539. coin:"",
  540. title:""
  541. };
  542. $scope.timer = '';
  543. var leftTimer = function (countDown) {
  544. if (isNaN(countDown)) {
  545. $scope.timer = '结束';
  546. return;
  547. }
  548. var day=parseInt(countDown/(24*60*60));
  549. var h=parseInt(countDown/(60*60)%24);
  550. var m=parseInt(countDown/60%60);
  551. var s=parseInt(countDown%60);
  552. $scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  553. if(day>0) $scope.timer = day+'天'+ $scope.timer;
  554. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  555. $scope.leftTimer = $interval(function () {
  556. if (countDown >= 1) leftTimer(countDown - 1);
  557. },1000);
  558. if(countDown<=0){
  559. $scope.timer='结束';
  560. }
  561. };
  562. $scope.changeIndex = function (index) {
  563. $scope.index = index;
  564. $scope.vm.coin = index*5;
  565. };
  566. $scope.vidEnded = function () {
  567. alert('播放完毕');
  568. };
  569. //实时计算支持乘数
  570. $scope.calcmultiplier = function () {
  571. $scope.multi.promise = $interval(function () {
  572. var date = new Date();
  573. var inter = date.getTime() - $scope.multi.b.getTime();
  574. var minutes = Math.floor(inter / (60 * 1000));
  575. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  576. if (number<=1) {
  577. number = 1;
  578. }
  579. //$scope.multi.result = Math.round(number * 100) / 100;
  580. $scope.multi.result = Math.round(number * 100 / 100);
  581. },1000);
  582. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  583. };
  584. $scope.supportDream = function (data) {
  585. if(!$scope.vm.coin){
  586. msg.error("请选择梦想币数量!");
  587. return ;
  588. }
  589. var data = {
  590. id:id,
  591. coin:$scope.vm.coin
  592. };
  593. homeService.supportDream(data).then(function(result){
  594. $scope.tosupport = false;
  595. $scope.load(id);
  596. $interval.cancel($scope.multi.promise);
  597. })
  598. };
  599. $scope.collectionDream = function(is_collection){
  600. homeService.collectionDream(id,is_collection).then(function(result){
  601. $scope.dream.is_collection=result.data.data;
  602. })
  603. };
  604. $scope.add = function(is_collection){
  605. var data = {
  606. id:id,
  607. title:$scope.vm.title,
  608. pics:$scope.imgs
  609. };
  610. homeService.add_interaction(data).then(function(){
  611. $scope.load(id);
  612. $scope.closeModal();
  613. })
  614. };
  615. $scope.showText = function(){
  616. $scope.aboutStyle = {
  617. "white-space" : "normal"
  618. };
  619. $scope.ionDownStyle = {
  620. "display" : "none"
  621. }
  622. };
  623. $scope.input = {
  624. placeholder: '评论',
  625. focus:false
  626. };
  627. $scope.replay = function ($event, name) {
  628. $event.stopPropagation();
  629. $scope.input.focus = true;
  630. $scope.input.placeholder = "回复" + name;
  631. $scope.vm.title='';
  632. };
  633. $scope.comment = function(){
  634. // $event.stopPropagation();
  635. //$scope.input.placeholder = "评论";
  636. $scope.input.focus = true;
  637. $scope.vm.title='';
  638. };
  639. $scope.submitComment = function(iid){
  640. if($scope.vm.comment&&$scope.vm.comment==''||!iid)return;
  641. var data = {
  642. id:iid,
  643. content:$scope.vm.comment
  644. };
  645. console.log($scope.vm.comment+" "+iid);
  646. homeService.add_comment(data).then(function(){
  647. $scope.vm.comment = '' ;
  648. $scope.load(id);
  649. $scope.closeModal();
  650. })
  651. };
  652. $scope.addpict = function () {
  653. common.chooseImage().then(function (img) {
  654. common.uploadFiles(img,1).then(function (result) {
  655. var response = JSON.parse(result.response);
  656. var file = response.data.file;
  657. $scope.imgs.push(config.imgServer+file);
  658. console.log(JSON.stringify(config.imgServer+file));
  659. }, function (error) {
  660. msg.error('图片上传失败');
  661. });
  662. }, function (error) {
  663. console.log('图片选择失败');
  664. });
  665. };
  666. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  667. scope: $scope,
  668. animation: 'slide-in-up'
  669. }).then(function(modal) {
  670. $scope.rechagemodal = modal;
  671. });
  672. $scope.openRechargeModal = function() {
  673. $scope.rechagemodal.show();
  674. $scope.vm.money = '';
  675. };
  676. $scope.closeRechargeModal = function() {
  677. $scope.rechagemodal.hide();
  678. };
  679. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  680. scope: $scope,
  681. animation: 'slide-in-up'
  682. }).then(function(modal) {
  683. $scope.modal = modal;
  684. });
  685. $scope.openModal = function() {
  686. $scope.modal.show();
  687. $scope.vm.title = '';
  688. $scope.imgs = [];
  689. };
  690. $scope.closeModal = function() {
  691. $scope.modal.hide();
  692. };
  693. //当我们用到模型时,清除它!
  694. $scope.$on('$destroy', function() {
  695. $scope.modal.remove();
  696. });
  697. }]);
  698. app.controller('userDetailCtrl', ["$scope", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  699. , function ($scope, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  700. var id = $stateParams.id;
  701. $scope.$on('$ionicView.beforeEnter', function () {
  702. $ionicTabsDelegate.showBar(false);
  703. });
  704. $scope.load = function (id) {
  705. msg.loading();
  706. homeService.dreamDetail(id).then(function (result) {
  707. msg.hide();
  708. $scope.user = result.data.data;
  709. }, function (error) {
  710. msg.hide();
  711. });
  712. };
  713. $scope.load(id);
  714. $scope.cancelSupport = function () {
  715. $scope.tosupport = false;
  716. $scope.toshare = false;
  717. };
  718. $scope.toshare = false;
  719. $scope.share = function ($event) {
  720. $event.stopPropagation();
  721. $scope.toshare = true;
  722. };
  723. $scope.shareDream = function(){
  724. $state.go("app.shareDream",{item:$scope.user});
  725. };
  726. $scope.toDetail = function (id) {
  727. $state.go('app.home_dreamdetail',{id:id});
  728. };
  729. $scope.toOldDream = function(){
  730. $state.go("app.oldDream");
  731. };
  732. $scope.toSupportDream = function(){
  733. $state.go("app.supportDream");
  734. };
  735. $scope.collectionDream = function(is_collection){
  736. homeService.collectionDream(id,is_collection).then(function(result){
  737. $scope.user.is_collection=result.data.data;
  738. })
  739. };
  740. }]);
  741. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  742. , function ($scope,homeService,$stateParams, $state, msg) {
  743. $scope.dream = $stateParams.item
  744. }]);
  745. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  746. , function ($scope,homeService,$stateParams, $state, msg) {
  747. }]);
  748. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  749. , function ($scope,homeService,$stateParams, $state, msg) {
  750. }]);
  751. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  752. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  753. $scope.showMore = function (keyword,index) {
  754. if(!keyword)return;
  755. $scope.index = index;
  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.search = function (keyword) {
  764. $scope.vm.keyword = keyword;
  765. homeService.search(keyword).then(function(result){
  766. $scope.isResult = true;
  767. $scope.dream_infos = result.data.data.dream_infos;
  768. $scope.user_infos = result.data.data.user_infos;
  769. });
  770. };
  771. $scope.toDetail = function (id) {
  772. $state.go('app.home_dreamdetail',{id:id});
  773. };
  774. $scope.toUser = function (id) {
  775. $state.go('app.home_dreamdetail',{id:id});
  776. };
  777. $scope.$on('$ionicView.beforeEnter', function () {
  778. $scope.isResult = false;
  779. $scope.index = 0;
  780. $scope.vm = {
  781. keyword : ""
  782. }
  783. $ionicTabsDelegate.showBar(false);
  784. // $ionicNavBarDelegate.showBackButton(false);
  785. homeService.search('').then(function(result){
  786. $scope.hot_searches = result.data.data.hot_searches;
  787. $scope.history_searches = result.data.data.history_searches;
  788. });
  789. });
  790. }]);
  791. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  792. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  793. }]);
  794. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  795. , function ($scope, $state, myService, msg) {
  796. $scope.$on('$ionicView.beforeEnter', function () {
  797. myService.myDream().then(function(result){
  798. console.log(result.data.data);
  799. $scope.dreams = result.data.data;
  800. });
  801. });
  802. $scope.toDetail = function (id) {
  803. $state.go('app.home_dreamdetail',{id:id});
  804. };
  805. }]);
  806. })(angular.module('app.controllers'));