home.js 34 KB

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