home.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. (function (app) {
  2. app.controller('homeCtrl', ["$scope", "$ionicTabsDelegate", "$http", 'config', "$state", "$ionicSlideBoxDelegate", "msg", "$ionicPopover", "homeService", "$ionicPopup", "$timeout", "$ionicSideMenuDelegate", "$rootScope"
  3. , function ($scope, $ionicTabsDelegate, $http, config, $state, $ionicSlideBoxDelegate, msg, $ionicPopover, homeService, $ionicPopup, $timeout, $ionicSideMenuDelegate, $rootScope) {
  4. $scope.$on('$ionicView.enter', function () {
  5. $ionicTabsDelegate.showBar(true);
  6. $scope.load(false);
  7. $ionicSlideBoxDelegate.start();
  8. //$scope.options = {
  9. // loop: true,
  10. // effect: 'fade',
  11. // speed: 500
  12. //};
  13. homeService.messageInfo().then(function(result){
  14. $scope.infos = result.data.data;
  15. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  16. $scope.showMessage=0;
  17. }
  18. else {
  19. $scope.showMessage=1;
  20. }
  21. },function(error){
  22. });
  23. });
  24. $rootScope.$on('msg-new', function (event, msg) {
  25. //收到新消息
  26. // alert('收到新消息,改变样式');
  27. $scope.showMessage = 1;
  28. });
  29. $scope.type = 'hot';//tab切换
  30. $ionicPopover.fromTemplateUrl('my-popover.html', {
  31. scope: $scope
  32. }).then(function (popover) {
  33. $scope.popover = popover;
  34. });
  35. $scope.toggleLeftSideMenu = function () {
  36. $ionicSideMenuDelegate.toggleLeft();
  37. };
  38. $scope.openPopover = function ($event) {
  39. $scope.popover.show($event);
  40. };
  41. $scope.closePopover = function () {
  42. $scope.popover.hide();
  43. };
  44. $scope.changetype = function (type) {
  45. $scope.type = type;
  46. $scope.load(true);
  47. };
  48. $scope.toDetail = function (id) {
  49. $state.go('app.home_dreamdetail',{id:id});
  50. };
  51. $scope.toUserDetail = function (id) {
  52. homeService.toUserDetail(id).then(function(result){
  53. $scope.items = result.data.data;
  54. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  55. },function(error){
  56. //msg.error(msg.data.error)
  57. })
  58. };
  59. $scope.changeFilter = function (input) {
  60. switch (input) {
  61. case '1':
  62. if ($scope.filter.sex == 1) {
  63. $scope.filter.sex = 0;
  64. } else {
  65. $scope.filter.sex = 1;
  66. }
  67. break;
  68. case '2':
  69. if ($scope.filter.sex == 2) {
  70. $scope.filter.sex = 0;
  71. } else {
  72. $scope.filter.sex = 2;
  73. }
  74. break;
  75. default:
  76. }
  77. };
  78. $scope.filter = {
  79. hasMore: false,
  80. pageIndex: 1,
  81. pageSize: 20,
  82. sex: 0,//1男,2女,0:全部,
  83. age: '',//0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>38,7:>18
  84. city:''
  85. };
  86. $scope.ages = [
  87. {"value": 0, "age": "所有"},
  88. {"value": 7, "age": "<18"},
  89. {"value": 1, "age": "18-21"},
  90. {"value": 2, "age": "22-25"},
  91. {"value": 3, "age": "26-29"},
  92. {"value": 4, "age": "30-33"},
  93. {"value": 5, "age": "34-37"},
  94. {"value": 6, "age": ">37"}
  95. ];
  96. $scope.doFilter = function () {
  97. var obj=document.getElementsByName('age');
  98. for(var i=0; i<obj.length; i++){
  99. if(obj[i].checked){
  100. $scope.filter.age+=obj[i].value+',';
  101. obj[i].checked=false;
  102. }
  103. };
  104. homeService.doFilter($scope.filter.sex,$scope.filter.age,$scope.filter.city).then(function(result){
  105. $scope.index.dreams = result.data.data.dreams.data;
  106. },function(error){
  107. msg.error(data.error.message);
  108. });
  109. $scope.filter.age="";
  110. };
  111. $scope.index = {
  112. banner: [],
  113. users: [],
  114. dreams:[]
  115. };
  116. $scope.next = function (type) {
  117. //type:1 前一个,type:2 后一个
  118. if($scope.index.users.length>0){
  119. if(type==1)
  120. {
  121. var temp= $scope.index.users.splice(0,1);
  122. $scope.index.users.push(temp[0]);
  123. }
  124. if (type==2){
  125. var temp= $scope.index.users.splice($scope.index.users.length-1,1);
  126. $scope.index.users.unshift(temp[0]);
  127. }
  128. }
  129. };
  130. $scope.load = function (init) {
  131. if (init) {
  132. $scope.filter.pageIndex = 1;
  133. $scope.index.dreams = [];
  134. }
  135. msg.loading();
  136. homeService.index($scope.type, $scope.filter.pageIndex).then(function (result) {
  137. msg.hide();
  138. $scope.index.banners = result.data.data.banners;
  139. $ionicSlideBoxDelegate.update();
  140. $ionicSlideBoxDelegate.loop(true);
  141. $scope.index.users = result.data.data.users;
  142. $scope.filter.pageIndex++;
  143. var more = (result.data.data.dreams.data.length >= $scope.filter.pageSize);
  144. $scope.filter.hasMore = more;
  145. $scope.index.dreams = $scope.index.dreams.concat(result.data.data.dreams.data);
  146. if (init) {
  147. $scope.$broadcast('scroll.refreshComplete');
  148. } else {
  149. $scope.$broadcast('scroll.infiniteScrollComplete');
  150. }
  151. }, function (error) {
  152. msg.hide();
  153. });
  154. };
  155. $scope.clickAvatar = function(id,dream_id){
  156. if(dream_id!=0){
  157. $state.go('app.home_dreamdetail',{id:dream_id,type:2});
  158. }
  159. else {
  160. $scope.toUserDetail(id);
  161. }
  162. };
  163. $scope.qrscan = function () {
  164. cordova.plugins.barcodeScanner.scan(
  165. function (result) {
  166. //扫码成功后执行的回调函数
  167. //alert("收到一个二维码\n" +
  168. // "扫码文字结果: " + result.text + "\n" +
  169. // "格式: " + result.format + "\n" +
  170. // "是否在扫码页面取消扫码: " + result.cancelled);
  171. if (!result.cancelled) {
  172. $http({
  173. url: result.text,
  174. method: "get"
  175. }).then(function (res) {
  176. msg.success('扫码成功');
  177. }, function () {
  178. msg.error('扫码失败');
  179. });
  180. }
  181. },
  182. function (error) {
  183. //扫码失败执行的回调函数
  184. // alert("Scanning failed: " + error);
  185. }, {
  186. preferFrontCamera: false, // iOS and Android 设置前置摄像头
  187. showFlipCameraButton: true, // iOS and Android 显示旋转摄像头按钮
  188. showTorchButton: true, // iOS and Android 显示打开闪光灯按钮
  189. torchOn: false, // Android, launch with the torch switched on (if available)打开手电筒
  190. prompt: "在扫描区域内放置二维码", // Android提示语
  191. resultDisplayDuration: 500, // Android, display scanned text for X ms.
  192. //0 suppresses it entirely, default 1500 设置扫码时间的参数
  193. formats: "QR_CODE", // 二维码格式可设置多种类型
  194. orientation: "portrait", // Android only (portrait|landscape),
  195. //default unset so it rotates with the device在安卓上 landscape 是横屏状态
  196. disableAnimations: true, // iOS 是否禁止动画
  197. disableSuccessBeep: false // iOS 禁止成功后提示声音 “滴”
  198. }
  199. );
  200. };
  201. $scope.$on('$ionicView.beforeLeave', function () {
  202. $scope.popover.hide();
  203. $scope.load(true);
  204. });
  205. }]);
  206. app.controller('dreamDetailCtrl', ["$scope","$location","$ionicHistory","$timeout", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$timeout", "$ionicScrollDelegate", "$interval"
  207. , function ($scope,$location, $ionicHistory,$timeout,$state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $timeout, $ionicScrollDelegate, $interval) {
  208. var id = $stateParams.id;
  209. var top3user = '';
  210. if($stateParams.type!=null){
  211. $scope.type = $stateParams.type;
  212. }
  213. else {
  214. $scope.type = 1;//tab切换
  215. }
  216. $scope.chosedIndex = 0;
  217. $scope.clickAvatar = function (index) {
  218. $scope.chosedIndex = index;
  219. homeService.myInfo().then(function (result) {
  220. $scope.user = result.data.data;
  221. });
  222. };
  223. // id=5;
  224. $scope.$on('$ionicView.beforeEnter', function () {
  225. $ionicTabsDelegate.showBar(false);
  226. $scope.load(id);
  227. $scope.thisUser = storage.getObject('user');
  228. $scope.vm.payType = 2;
  229. homeService.myInfo().then(function(result){
  230. $scope.user = result.data.data;
  231. });
  232. homeService.messageInfo().then(function(result){
  233. $scope.infos = result.data.data;
  234. if($scope.infos.letter.is_read==0 && $scope.infos.reply.is_read==0 && $scope.infos.systemInfo.is_read==0){
  235. $scope.showMessage=0;
  236. }
  237. else {
  238. $scope.showMessage=1;
  239. }
  240. },function(error){
  241. });
  242. });
  243. $scope.toUserDetail = function (id) {
  244. homeService.toUserDetail(id).then(function(result){
  245. $scope.items = result.data.data;
  246. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  247. },function(error){
  248. //msg.error(msg.data.error)
  249. })
  250. };
  251. $scope.$on('$ionicView.leave', function () {
  252. if($scope.multi.promise)$interval.cancel($scope.multi.promise);
  253. if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  254. });
  255. $scope.toSort = function(){
  256. //$scope.type = 3;
  257. $scope.changeType(3)
  258. };
  259. $scope.load = function (id) {
  260. msg.loading();
  261. homeService.dreamDetail(id).then(function (result) {
  262. msg.hide();
  263. console.log(result);
  264. $scope.showCode = function(codeName){
  265. $scope.url = codeName;
  266. $scope.code = true;
  267. };
  268. $scope.hideCode = function(){
  269. $scope.code = false;
  270. };
  271. $scope.dream = result.data.data;
  272. if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
  273. $scope.codeBtn = true;
  274. }
  275. if($scope.dream.video){
  276. $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
  277. $scope.dream.video = config.imgServer+$scope.dream.video;
  278. }
  279. var reg = new RegExp("\n", "g");
  280. $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
  281. var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
  282. var date = new Date();
  283. var inter = (end_time.getTime() - date.getTime()) / 1000;
  284. leftTimer(inter);
  285. $scope.multi.a = $scope.dream.a;
  286. $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
  287. $scope.multi.c = $scope.dream.c;
  288. $scope.multi.promise = $scope.dream.a;
  289. var newtop3user = '' ;
  290. angular.forEach($scope.dream.top3user, function(user) {
  291. newtop3user= newtop3user +user.id+","
  292. });
  293. if(top3user!=''&&newtop3user!=top3user){
  294. //测试动画切换
  295. $timeout(function() {
  296. $scope.sort.slide1 = 'list-grow-animation';
  297. $scope.sort.slide2 = 'slide-in-both-ways';
  298. $scope.sort.slide3 = 'bounce-animation';
  299. }, 50);
  300. }
  301. top3user = newtop3user;
  302. if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
  303. if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
  304. if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
  305. $scope.calcmultiplier();
  306. }, function (error) {
  307. msg.hide();
  308. });
  309. };
  310. $scope.openSupport = function () {
  311. msg.alert("支持乘数说明","支持乘数支持乘数支持乘数支持乘数");
  312. };
  313. $scope.multi = {
  314. a: '',
  315. b: '',
  316. c: '',
  317. result: 1,
  318. promise:null
  319. };
  320. $scope.tosupport = false;
  321. $scope.support = function ($event) {
  322. $event.stopPropagation();
  323. $scope.tosupport = true;
  324. $scope.vm.coin = 0;
  325. $scope.index = 0;
  326. };
  327. $scope.cancelSupport = function () {
  328. $scope.tosupport = false;
  329. $scope.toshare = false;
  330. $scope.input.show = false;
  331. };
  332. $scope.toshare = false;
  333. $scope.toRecharge = function(){
  334. $state.go("app.recharge")
  335. };
  336. $scope.share = function (type,$event) {
  337. $scope.toshare = true;
  338. if (type==0) {
  339. //分享给朋友
  340. Wechat.share({
  341. message: {
  342. title: $scope.dream.name,
  343. description: $scope.dream.about,
  344. thumb: "q8.9026.com/base/img/share/icon_cat_h.png",
  345. media: {
  346. type: Wechat.Type.WEBPAGE,
  347. webpageUrl: config.server + "/admin/share/view?id=" + id
  348. }
  349. },
  350. scene: Wechat.Scene.SESSION
  351. }, function () {
  352. alert("分享成功");
  353. }, function (reason) {
  354. alert("分享失败");
  355. });
  356. }
  357. if(type==1){
  358. Wechat.share({
  359. message: {
  360. title: $scope.dream.name,
  361. description: $scope.dream.about,
  362. thumb: "q8.9026.com/base/img/share/icon_cat_h.png",
  363. media: {
  364. type: Wechat.Type.WEBPAGE,
  365. webpageUrl: config.server + "/admin/share/view?id=" + id
  366. }
  367. },
  368. scene: Wechat.Scene.TIMELINE
  369. }, function () {
  370. alert("分享","分享成功");
  371. }, function (reason) {
  372. alert("分享","分享失败");
  373. });
  374. }
  375. };
  376. //实时排行
  377. $scope.sort = {
  378. slide: ''
  379. };
  380. $scope.changeType = function (type) {
  381. $ionicScrollDelegate.scrollTop(true);
  382. $scope.type = type;
  383. };
  384. $scope.index = 0;
  385. $scope.vm = {
  386. coin:"",
  387. title:""
  388. };
  389. $scope.timer = '';
  390. var leftTimer = function (countDown) {
  391. if (isNaN(countDown)) {
  392. $scope.timer = '已结束';
  393. return;
  394. }
  395. var day=parseInt(countDown/(24*60*60));
  396. var h=parseInt(countDown/(60*60)%24);
  397. var m=parseInt(countDown/60%60);
  398. var s=parseInt(countDown%60);
  399. //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
  400. if(day>0) $scope.timer = day+'天';
  401. if(day<0 && h>0) $scope.timer = h+'小时';
  402. if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
  403. if(day<0 && h<0 && m<0) $scope.timer = '已结束';
  404. /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
  405. $scope.leftTimer = $interval(function () {
  406. if (countDown >= 1) leftTimer(countDown - 1);
  407. },1000);*/
  408. /*if(countDown<=0){
  409. $scope.timer='结束';
  410. }*/
  411. };
  412. $scope.changeIndex = function (index) {
  413. $scope.index = index;
  414. $scope.vm.coin = index*10;
  415. };
  416. $scope.vidEnded = function () {
  417. alert('播放完毕');
  418. };
  419. //实时计算支持乘数
  420. $scope.calcmultiplier = function () {
  421. $scope.multi.promise = $interval(function () {
  422. var date = new Date();
  423. var inter = date.getTime() - $scope.multi.b.getTime();
  424. var minutes = Math.floor(inter / (60 * 1000));
  425. var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
  426. if (number<=1) {
  427. number = 1;
  428. }
  429. //$scope.multi.result = Math.round(number * 100) / 100;
  430. $scope.multi.result = Math.round(number * 100 / 100);
  431. },1000);
  432. // 点击支持取消 $interval.cancel($scope.multi.promise); 获取数据后重新开始执行
  433. };
  434. $scope.supportDream = function (data) {
  435. if(!$scope.vm.coin){
  436. msg.error("请选择梦想币数量!");
  437. return ;
  438. }
  439. var data = {
  440. id:id,
  441. coin:$scope.vm.coin
  442. };
  443. homeService.supportDream(data).then(function(result){
  444. $scope.tosupport = false;
  445. $scope.load(id);
  446. homeService.myInfo().then(function(result){
  447. $scope.user = result.data.data;
  448. });
  449. $interval.cancel($scope.multi.promise);
  450. msg.text("发送成功");
  451. });
  452. };
  453. $scope.collectionDream = function(is_collection){
  454. homeService.collectionDream(id,is_collection).then(function(result){
  455. $scope.dream.is_collection=result.data.data;
  456. })
  457. };
  458. $scope.add = function(is_collection){
  459. var data = {
  460. id:id,
  461. title:$scope.vm.title,
  462. pics:$scope.imgs,
  463. video:$scope.video.file
  464. };
  465. homeService.add_interaction(data).then(function(){
  466. $scope.load(id);
  467. $scope.closeModal();
  468. })
  469. };
  470. $scope.showAbout = true;
  471. $scope.hideAbout = false;
  472. $scope.showText = function(){
  473. $scope.aboutStyle = {
  474. "white-space" : "normal"
  475. };
  476. $scope.showAbout = false;
  477. $scope.hideAbout = true;
  478. };
  479. $scope.hideText = function(){
  480. $scope.aboutStyle = {
  481. "white-space" : "nowrap"
  482. };
  483. $scope.showAbout = true;
  484. $scope.hideAbout = false;
  485. };
  486. $scope.input = {
  487. placeholder: '评论',
  488. focus: false,
  489. show:false
  490. };
  491. $scope.showmore = function (index) {
  492. if ($scope.dream.interactions[index].showmore) {
  493. $scope.dream.interactions[index].showmore = false;
  494. } else {
  495. $scope.dream.interactions[index].showmore = true;
  496. }
  497. };
  498. $scope.replay = function ($event, name, to_suerid, index) {
  499. $event.stopPropagation();
  500. $scope.input.focus = true;
  501. $scope.input.show = true;
  502. angular.forEach($scope.dream.interactions, function (item) {
  503. item.show = false;
  504. });
  505. $scope.dream.interactions[index].show = true;
  506. $scope.dream.interactions[index].focus = true;
  507. $scope.input.placeholder = "评论" + name+":";
  508. $scope.vm.title='';
  509. $scope.vm.comment='';
  510. };
  511. $scope.replayOther = function ($event, name, to_userid, index,currentindex) {
  512. $event.stopPropagation();
  513. if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
  514. $scope.input.focus = true;
  515. $scope.input.show = true;
  516. angular.forEach($scope.dream.interactions, function (item) {
  517. item.show = false;
  518. });
  519. $scope.dream.interactions[index].show = true;
  520. $scope.dream.interactions[index].focus = true;
  521. $scope.input.placeholder = "评论" + name+":" + to_userid;
  522. $scope.to_userid = to_userid;
  523. $scope.vm.title='';
  524. $scope.vm.comment='';
  525. }
  526. else {
  527. msg.confirm("评论","是否删除评论").then(function(result){
  528. if(result==true)
  529. {
  530. homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
  531. msg.text("删除成功");
  532. $scope.load(id);
  533. },function(error){
  534. msg.error(error.data.message);
  535. })
  536. }
  537. });
  538. }
  539. };
  540. //充值
  541. $scope.charge = function(number){
  542. if (!number) {
  543. msg.text('请输入充值金额');
  544. return;
  545. }
  546. homeService.charge(number,2).then(function (result) {
  547. //todo:result需要返回支付宝或者微信的签名信息
  548. console.log("result: " + JSON.stringify(result));
  549. var payInfo = result.data.data;
  550. if ($scope.vm.payType == 1) { //支付宝
  551. cordova.plugins.AliPay.pay(payInfo, function success(e) {
  552. $scope.clicksub = false;
  553. if (e.resultStatus == '9000') {
  554. alert(orderID);
  555. $timeout(function () {
  556. $scope.closeRechargeModal();
  557. }, 500);
  558. homeService.myInfo().then(function (result) {
  559. $scope.user = result.data.data;
  560. });
  561. } else {
  562. msg.error("支付失败");
  563. // msg.error("支付失败:" + JSON.stringify(e));
  564. }
  565. }, function error(e) {
  566. $scope.clicksub = false;
  567. // msg.error("支付失败:" + JSON.stringify(e));
  568. msg.error("支付失败");
  569. });
  570. }
  571. if ($scope.vm.payType == 2) { //微信
  572. // var obj = JSON.parse(payInfo);
  573. var obj = payInfo.orderString;
  574. // console.log("obj: " + JSON.stringify(obj));
  575. var params = {
  576. partnerid: obj.partnerid, // merchant id
  577. prepayid: obj.prepayid, // prepay id
  578. noncestr: obj.noncestr, // nonce
  579. timestamp: obj.timestamp, // timestamp
  580. sign: obj.sign, // signed string
  581. };
  582. // console.log("result: " + JSON.stringify(params));
  583. Wechat.sendPaymentRequest(params, function (r) {
  584. $scope.clicksub = false;
  585. courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
  586. $timeout(function () {
  587. $scope.closeRechargeModal();
  588. }, 500);
  589. homeService.myInfo().then(function (result) {
  590. $scope.user = result.data.data;
  591. });
  592. }, function (erro) {
  593. // msg.alert("支付反馈失败:" + JSON.stringify(erro));
  594. });
  595. }, function (reason) {
  596. $scope.clicksub = false;
  597. // msg.alert("支付失败:" + JSON.stringify(reason));
  598. });
  599. }
  600. });
  601. };
  602. $scope.submitComment = function (index,to_userid) {
  603. var interaction = $scope.dream.interactions[index];
  604. var iid = interaction.id;
  605. // $scope.dream.interactions[index].comments.push($scope.vm.comment);
  606. $scope.input.focus = true;
  607. if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
  608. var data = {
  609. id:iid,
  610. content:$scope.vm.comment,
  611. comment_user_id:to_userid
  612. };
  613. console.log($scope.vm.comment+" "+iid);
  614. homeService.add_comment(data).then(function(){
  615. $scope.vm.comment = '' ;
  616. $scope.load(id);
  617. $scope.closeModal();
  618. });
  619. };
  620. $scope.bigImage = false;
  621. $scope.showBigImage = function ($event, imageName) {
  622. $event.stopPropagation();
  623. $scope.url = imageName;
  624. $scope.bigImage = true;
  625. };
  626. $scope.hideBigImage = function(){
  627. $scope.bigImage = false;
  628. };
  629. $ionicModal.fromTemplateUrl('qrCode.html', {
  630. scope: $scope,
  631. animation: 'slide-in-up'
  632. }).then(function(modal) {
  633. $scope.qrCodemodal = modal;
  634. });
  635. $scope.openCode = function($event) {
  636. $event.stopPropagation();
  637. $scope.qrCodemodal.show();
  638. $scope.vm.money = '';
  639. };
  640. $scope.closeCode = function() {
  641. $scope.qrCodemodal.hide();
  642. };
  643. $ionicModal.fromTemplateUrl('commentPic.html', {
  644. scope: $scope,
  645. animation: 'slide-in-up'
  646. }).then(function(modal) {
  647. $scope.CommentPicmodal = modal;
  648. });
  649. $scope.openCommentPic = function(pic,$event) {
  650. $event.stopPropagation();
  651. $scope.CommentPicmodal.show();
  652. $scope.commentPicUrl = pic;
  653. };
  654. $scope.closeCommentPic = function() {
  655. $scope.CommentPicmodal.hide();
  656. };
  657. $scope.addpict = function () {
  658. common.chooseImage().then(function (img) {
  659. common.uploadFiles(img,1).then(function (result) {
  660. var response = JSON.parse(result.response);
  661. var file = config.imgServer + response.data.file;
  662. $scope.imgs.push(file);
  663. }, function (error) {
  664. msg.error('图片上传失败');
  665. });
  666. }, function (error) {
  667. console.log('图片选择失败');
  668. });
  669. };
  670. $scope.deletefile = function (file) {
  671. var index = $scope.imgs.indexOf(file);
  672. $scope.imgs.splice(index, 1);
  673. common.deletefile(file).then(function () {
  674. })
  675. };
  676. $scope.addvideo = function () {
  677. common.chooseVideo().then(function (file) {
  678. common.uploadFiles(file, 2).then(function (result) {
  679. var response = JSON.parse(result.response);
  680. var file = config.imgServer+response.data.file;
  681. console.log("file:"+file);
  682. $scope.video.isOK = true;
  683. $scope.video.file = file;
  684. $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
  685. console.log("vpic:"+$scope.video.vpic);
  686. }, function (error) {
  687. msg.error('视频上传失败');
  688. });
  689. }, function (erro) {
  690. console.log('选择视频失败');
  691. });
  692. };
  693. $ionicModal.fromTemplateUrl('recharge-modal.html', {
  694. scope: $scope,
  695. animation: 'slide-in-up'
  696. }).then(function(modal) {
  697. $scope.rechagemodal = modal;
  698. });
  699. $scope.openRechargeModal = function() {
  700. $scope.rechagemodal.show();
  701. $scope.vm.money = '';
  702. };
  703. $scope.closeRechargeModal = function() {
  704. $scope.rechagemodal.hide();
  705. };
  706. $ionicModal.fromTemplateUrl('interaction-modal.html', {
  707. scope: $scope,
  708. animation: 'slide-in-up'
  709. }).then(function(modal) {
  710. $scope.modal = modal;
  711. });
  712. $scope.openModal = function() {
  713. $scope.modal.show();
  714. $scope.vm.title = '';
  715. $scope.imgs = [];
  716. $scope.video = {};
  717. };
  718. $scope.closeModal = function() {
  719. $scope.modal.hide();
  720. };
  721. //当我们用到模型时,清除它!
  722. $scope.$on('$destroy', function() {
  723. $scope.modal.remove();
  724. });
  725. $scope.toMessage = function(){
  726. //var dreamdetailUrl = $location.path();
  727. if($location.path()=="/app/home/dreamdetail"){
  728. $state.go("app.message");
  729. }
  730. else {
  731. $state.go("app.my_message");
  732. }
  733. }
  734. }]);
  735. app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
  736. , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
  737. var id = $stateParams.id;
  738. $scope.items = $stateParams.items;
  739. $scope.$on('$ionicView.beforeEnter', function () {
  740. $ionicTabsDelegate.showBar(false);
  741. });
  742. $scope.attentionUser = function(is_care){
  743. homeService.attentionUser(id,is_care).then(function(result){
  744. $scope.items.is_care=result.data.data;
  745. })
  746. };
  747. $scope.next = function (type) {
  748. //type:1 前一个,type:2 后一个
  749. if($scope.items.imgs.length>0){
  750. if(type==1)
  751. {
  752. var temp= $scope.items.imgs.splice(0,1);
  753. $scope.items.imgs.push(temp[0]);
  754. }
  755. if (type==2){
  756. var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
  757. $scope.items.imgs.unshift(temp[0]);
  758. }
  759. }
  760. };
  761. $scope.bigImage = false;
  762. $scope.showBigImage = function(imageName,imageIndex){
  763. $scope.url = imageName;
  764. $scope.imageIndex = imageIndex;
  765. $scope.bigImage = true;
  766. };
  767. $scope.hideBigImage = function(){
  768. $scope.bigImage = false;
  769. };
  770. $scope.swipeLeft = function (imageIndex) {
  771. if ($scope.imageIndex < $scope.items.imgs.length - 1 && $scope.imageIndex >= 0)
  772. $scope.imageIndex = $scope.imageIndex + 1;
  773. else {
  774. //如果图片已经是最后一张图片了,则取index = 0
  775. $scope.imageIndex = 0;
  776. }
  777. //替换url,展示图片
  778. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  779. $scope.bigImage = true; //显示大图
  780. };
  781. $scope.swipeRight = function (imageIndex) {
  782. if ($scope.imageIndex <= $scope.items.imgs.length - 1 && $scope.imageIndex > 0)
  783. $scope.imageIndex = $scope.imageIndex - 1;
  784. else {
  785. //如果图片已经是第一张图片了,则取index = Images.length-1
  786. $scope.imageIndex = $scope.items.imgs.length - 1;
  787. }
  788. //替换url,展示图片
  789. $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  790. $scope.bigImage = true; //显示大图
  791. };
  792. $scope.cancelSupport = function () {
  793. $scope.tosupport = false;
  794. $scope.toshare = false;
  795. };
  796. $scope.toshare = false;
  797. $scope.toshare = false;
  798. $scope.toRecharge = function(){
  799. $state.go("app.recharge")
  800. };
  801. $scope.toDetail = function (dream_id) {
  802. if($scope.items.near_dream==null){
  803. msg.alert("当前梦想","该用户没有当前梦想");
  804. }
  805. if($scope.items.near_dream!=null){
  806. var dream_id = $scope.items.near_dream.id;
  807. if($location.path()=="/app/home/userDetail"){
  808. $state.go('app.home_dreamdetail',{id:dream_id});
  809. }
  810. else {
  811. $state.go('app.my_dreamdetail',{id:dream_id});
  812. }
  813. }
  814. };
  815. $scope.toOldDream = function(){
  816. if($scope.items.dreams.length<2){
  817. msg.alert("曾经的梦想","该用户没有曾经的梦想");
  818. }
  819. if($scope.items.dreams.length>1){
  820. if($location.path()=="/app/home/userDetail"){
  821. $state.go('app.oldDream',{user_id:$scope.items.user.id});
  822. }
  823. else {
  824. $state.go('app.myOldDream',{user_id:$scope.items.user.id});
  825. }
  826. }
  827. };
  828. $scope.toSupportDream = function(){
  829. if($scope.items.sup_dreams.length==0){
  830. msg.alert("支持的梦想","该用户没有支持的梦想");
  831. }
  832. if($scope.items.sup_dreams.length!=0){
  833. if($scope.items.dreams.length>1){
  834. if($location.path()=="/app/home/userDetail"){
  835. $state.go('app.supportDream',{user_id:$scope.items.user.id});
  836. }
  837. else {
  838. $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
  839. }
  840. }
  841. }
  842. };
  843. $scope.collectionDream = function(is_collection){
  844. homeService.collectionDream(id,is_collection).then(function(result){
  845. $scope.user.is_collection=result.data.data;
  846. })
  847. };
  848. }]);
  849. app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
  850. , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
  851. $scope.$on('$ionicView.beforeEnter', function () {
  852. $ionicTabsDelegate.showBar(false);
  853. myService.collect().then(function(result){
  854. $scope.dreams = result.data.data.dreams;
  855. });
  856. });
  857. $scope.toDetail = function (id) {
  858. $state.go('app.home_dreamdetail',{id:id});
  859. };
  860. }]);
  861. app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  862. , function ($scope,homeService,$stateParams, $state, msg) {
  863. $scope.dream = $stateParams.item;
  864. $scope.showAbout = true;
  865. $scope.hideAbout = false;
  866. $scope.showText = function(){
  867. $scope.aboutStyle = {
  868. "white-space" : "normal"
  869. };
  870. $scope.showAbout = false;
  871. $scope.hideAbout = true;
  872. };
  873. $scope.hideText = function(){
  874. $scope.aboutStyle = {
  875. "white-space" : "nowrap"
  876. };
  877. $scope.showAbout = true;
  878. $scope.hideAbout = false;
  879. };
  880. }]);
  881. app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
  882. , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
  883. $scope.$on('$ionicView.beforeEnter', function () {
  884. $ionicTabsDelegate.showBar(false);
  885. myService.messageInfo().then(function(result){
  886. $scope.infos = result.data.data;
  887. },function(error){
  888. });
  889. });
  890. $scope.notRead = function(){
  891. myService.notRead().then(function(result){
  892. myService.messageInfo().then(function(result){
  893. $scope.infos = result.data.data;
  894. },function(error){
  895. });
  896. },function(error){
  897. })
  898. };
  899. //系统消息
  900. $scope.systemInfo = function(){
  901. $state.go("app.message_sys");
  902. myService.systemInfo().then(function(result){
  903. },function(error){
  904. });
  905. };
  906. //回复我的
  907. $scope.replyMy = function(){
  908. $state.go("app.message_reply");
  909. myService.replyMy().then(function(result){
  910. },function(error){
  911. });
  912. };
  913. $scope.personalLetter = function(){
  914. $state.go("app.letter");
  915. }
  916. }]);
  917. app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  918. , function ($scope,homeService,$stateParams, $state, msg) {
  919. var user_id = $stateParams.user_id;
  920. $scope.$on('$ionicView.beforeEnter',function(){
  921. $scope.toUserDetail(user_id);
  922. });
  923. $scope.toUserDetail = function(user_id){
  924. homeService.toUserDetail(user_id).then(function(result){
  925. $scope.items = result.data.data;
  926. $scope.user = result.data.data.user;
  927. $scope.dreams = $scope.user.dreams;
  928. },function(error){
  929. })
  930. };
  931. $scope.toDetail = function(){
  932. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  933. };
  934. }]);
  935. app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
  936. , function ($scope,homeService,$stateParams, $state, msg) {
  937. var user_id = $stateParams.user_id;
  938. $scope.$on('$ionicView.beforeEnter',function(){
  939. $scope.toUserDetail(user_id);
  940. });
  941. $scope.toUserDetail = function(user_id){
  942. homeService.toUserDetail(user_id).then(function(result){
  943. $scope.items = result.data.data;
  944. $scope.user = result.data.data.user;
  945. $scope.dreams = $scope.user.sup_dream;
  946. },function(error){
  947. })
  948. };
  949. $scope.toDetail = function(){
  950. $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
  951. }
  952. }]);
  953. app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  954. , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
  955. $scope.showMore = function (keyword,index) {
  956. if(!keyword)return;
  957. $scope.index = index;
  958. $scope.search(keyword);
  959. };
  960. $scope.search = function (keyword) {
  961. $scope.vm.keyword = keyword;
  962. homeService.search(keyword).then(function(result){
  963. $scope.isResult = true;
  964. $scope.dream_infos = result.data.data.dream_infos;
  965. $scope.user_infos = result.data.data.user_infos;
  966. });
  967. };
  968. $scope.toUserDetail = function (id) {
  969. homeService.toUserDetail(id).then(function(result){
  970. $scope.items = result.data.data;
  971. $state.go('app.home_userDetail',{id:id,items:$scope.items});
  972. },function(error){
  973. //msg.error(msg.data.error)
  974. })
  975. };
  976. $scope.toDetail = function (id) {
  977. $state.go('app.home_dreamdetail',{id:id});
  978. };
  979. $scope.$on('$ionicView.beforeEnter', function () {
  980. $scope.isResult = false;
  981. $scope.index = 0;
  982. $scope.vm = {
  983. keyword : ""
  984. };
  985. $ionicTabsDelegate.showBar(false);
  986. // $ionicNavBarDelegate.showBackButton(false);
  987. homeService.search('').then(function(result){
  988. $scope.hot_searches = result.data.data.hot_searches;
  989. $scope.history_searches = result.data.data.history_searches;
  990. });
  991. });
  992. }]);
  993. app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
  994. , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
  995. }]);
  996. app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
  997. , function ($scope, $state, myService, msg) {
  998. $scope.$on('$ionicView.beforeEnter', function () {
  999. myService.myDream().then(function(result){
  1000. console.log(result.data.data);
  1001. $scope.dreams = result.data.data;
  1002. });
  1003. });
  1004. $scope.toDetail = function (id) {
  1005. $state.go('app.home_dreamdetail',{id:id});
  1006. };
  1007. }]);
  1008. })(angular.module('app.controllers'));