home.js 35 KB

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