home.js 42 KB

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