home.js 32 KB

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