12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166 |
- (function (app) {
- app.controller('homeCtrl', ["$scope", "$ionicTabsDelegate","storage", "$http", 'config', "$state", "$ionicSlideBoxDelegate", "msg", "$ionicPopover", "homeService", "$ionicPopup", "$timeout", "$ionicSideMenuDelegate", "$rootScope"
- , function ($scope, $ionicTabsDelegate,storage, $http, config, $state, $ionicSlideBoxDelegate, msg, $ionicPopover, homeService, $ionicPopup, $timeout, $ionicSideMenuDelegate, $rootScope) {
- $scope.$on('$ionicView.enter', function () {
- $ionicTabsDelegate.showBar(true);
- $scope.load(false);
- $ionicSlideBoxDelegate.start();
- $scope.step = storage.getObject('user').step;
- var width = window.screen.width;
- if(width>300&width<370){
- $scope.screenWidth = 0;
- }
- else if(width>=370&width<400){
- $scope.screenWidth = 1;
- }
- else{
- $scope.screenWidth = 2;
- }
- homeService.messageInfo().then(function(result){
- $scope.infos = result.data.data;
- if($scope.infos.dream_info.number==0 && $scope.infos.sup_info.number==0 && $scope.infos.system_info.number==0){
- $scope.showMessage=0;
- }
- else {
- $scope.showMessage=1;
- }
- },function(error){
- });
- });
- $rootScope.$on('msg-new', function (event, msg) {
- $scope.showMessage = 1;
- });
- $scope.type = 'hot';//tab切换
- $scope.changeStep = function(){
- $scope.step = $scope.step + 1;
- homeService.changeStep().then(function(result){
- if(result.data.status_code==0){
- storage.setObject('user', result.data.data);
- }
- },function(error){
-
- })
- }
- $ionicPopover.fromTemplateUrl('my-popover.html', {
- scope: $scope
- }).then(function (popover) {
- $scope.popover = popover;
- });
- $scope.toggleLeftSideMenu = function () {
- $ionicSideMenuDelegate.toggleLeft();
- };
- $scope.openPopover = function ($event) {
- $scope.popover.show($event);
- };
- $scope.closePopover = function () {
- $scope.popover.hide();
- };
- $scope.changetype = function (type) {
- $scope.type = type;
- $scope.load(true);
- };
- $scope.toDetail = function (id) {
- $state.go('app.home_dreamdetail',{id:id});
- };
- $scope.toUserDetail = function (id) {
- homeService.toUserDetail(id).then(function(result){
- $scope.items = result.data.data;
- $state.go('app.home_userDetail',{id:id,items:$scope.items});
- },function(error){
- //msg.error(msg.data.error)
- })
- };
- $scope.changeFilter = function (input) {
- switch (input) {
- case '1':
- if ($scope.filter.sex == 1) {
- $scope.filter.sex = 0;
- } else {
- $scope.filter.sex = 1;
- }
- break;
- case '2':
- if ($scope.filter.sex == 2) {
- $scope.filter.sex = 0;
- } else {
- $scope.filter.sex = 2;
- }
- break;
- default:
- }
- };
- $scope.filter = {
- hasMore: false,
- pageIndex: 1,
- pageSize: 20,
- sex: 0,//1男,2女,0:全部,
- age: '',//0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>38,7:>18
- city:''
- };
- $scope.ages = [
- {"value": 0, "age": "所有"},
- {"value": 7, "age": "<18"},
- {"value": 1, "age": "18-21"},
- {"value": 2, "age": "22-25"},
- {"value": 3, "age": "26-29"},
- {"value": 4, "age": "30-33"},
- {"value": 5, "age": "34-37"},
- {"value": 6, "age": ">37"}
- ];
- $scope.doFilter = function () {
- var obj=document.getElementsByName('age');
- for(var i=0; i<obj.length; i++){
- if(obj[i].checked){
- $scope.filter.age+=obj[i].value+',';
- obj[i].checked=false;
- }
- };
- homeService.doFilter($scope.filter.sex,$scope.filter.age,$scope.filter.city).then(function(result){
- $scope.index.dreams = result.data.data.dreams.data;
- },function(error){
- msg.error(data.error.message);
- });
- $scope.filter.age="";
- };
- $scope.index = {
- banner: [],
- users: [],
- dreams:[]
- };
-
- $scope.next = function (type) {
- //type:1 前一个,type:2 后一个
- if($scope.index.users.length>0){
- if(type==1)
- {
- var temp= $scope.index.users.splice(0,1);
- $scope.index.users.push(temp[0]);
- }
- if (type==2){
- var temp= $scope.index.users.splice($scope.index.users.length-1,1);
- $scope.index.users.unshift(temp[0]);
- }
- }
- };
- $scope.load = function (init) {
- if (init) {
- $scope.filter.pageIndex = 1;
- $scope.index.dreams = [];
- }
- msg.loading();
- homeService.index($scope.type, $scope.filter.pageIndex).then(function (result) {
- msg.hide();
- $scope.index.banners = result.data.data.banners;
- $ionicSlideBoxDelegate.update();
- $ionicSlideBoxDelegate.loop(true);
- $scope.index.users = result.data.data.users;
- $scope.filter.pageIndex++;
- var more = (result.data.data.dreams.data.length >= $scope.filter.pageSize);
- $scope.filter.hasMore = more;
- $scope.index.dreams = $scope.index.dreams.concat(result.data.data.dreams.data);
- if (init) {
- $scope.$broadcast('scroll.refreshComplete');
- } else {
- $scope.$broadcast('scroll.infiniteScrollComplete');
- }
- }, function (error) {
- msg.hide();
- });
- };
- $scope.clickAvatar = function(id,dream_id){
- $state.go('app.home_dreamdetail',{id:dream_id,dream_user_id:id,type:2});
- };
- $scope.qrscan = function () {
- cordova.plugins.barcodeScanner.scan(
- function (result) {
- //扫码成功后执行的回调函数
- //alert("收到一个二维码\n" +
- // "扫码文字结果: " + result.text + "\n" +
- // "格式: " + result.format + "\n" +
- // "是否在扫码页面取消扫码: " + result.cancelled);
- if (!result.cancelled) {
- $http({
- url: result.text,
- method: "get"
- }).then(function (res) {
- msg.success('扫码成功');
- }, function (erro) {
- //alert(JSON.stringify(erro));
- msg.error('扫码失败:'+erro.data.message);
- });
- }
-
- },
- function (error) {
- //扫码失败执行的回调函数
- // alert("Scanning failed: " + error);
- }, {
- preferFrontCamera: false, // iOS and Android 设置前置摄像头
- showFlipCameraButton: true, // iOS and Android 显示旋转摄像头按钮
- showTorchButton: true, // iOS and Android 显示打开闪光灯按钮
- torchOn: false, // Android, launch with the torch switched on (if available)打开手电筒
- prompt: "在扫描区域内放置二维码", // Android提示语
- resultDisplayDuration: 500, // Android, display scanned text for X ms.
- //0 suppresses it entirely, default 1500 设置扫码时间的参数
- formats: "QR_CODE", // 二维码格式可设置多种类型
- orientation: "portrait", // Android only (portrait|landscape),
- //default unset so it rotates with the device在安卓上 landscape 是横屏状态
- disableAnimations: true, // iOS 是否禁止动画
- disableSuccessBeep: false // iOS 禁止成功后提示声音 “滴”
- }
- );
- };
- $scope.$on('$ionicView.beforeLeave', function () {
- $scope.popover.hide();
- $scope.load(true);
- });
- }]);
- app.controller('dreamDetailCtrl', ["$scope","$location","$ionicHistory","$timeout","$ionicLoading", "$state", "WechatService","$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams","$ionicBackdrop", "$ionicScrollDelegate", "$interval"
- , function ($scope,$location, $ionicHistory,$timeout,$ionicLoading,$state,WechatService,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams,$ionicBackdrop, $ionicScrollDelegate, $interval) {
- var dream_user_id = $stateParams.dream_user_id;
- var id = $stateParams.id;
- var interaction_id = $stateParams.interaction_id;
- $scope.host = config.server;
- $scope.imghost = config.imgServer;
- var top3user = '';
- if($stateParams.type!=null){
- $scope.type = $stateParams.type;
- }
- else {
- $scope.type = 1;//tab切换
- }
- $scope.chosedIndex = 0;
- $scope.clickAvatar = function (index) {
- $scope.chosedIndex = index;
- homeService.myInfo().then(function (result) {
- $scope.user = result.data.data;
- });
- };
- // id=5;
- $scope.$on('$ionicView.afterEnter', function () {
- timerID = setInterval(function() {
- $scope.$apply(function(){
- $scope.load(id,dream_user_id,interaction_id);
- });
- }, 50000);
- });
- $scope.$on('$ionicView.afterLeave', function () {
- clearInterval(timerID);
- timerID = null;
- if($scope.multi.promise)$interval.cancel($scope.multi.promise);
- if($scope.leftTimer)$interval.cancel($scope.leftTimer);
- });
- $scope.$on('$ionicView.beforeEnter', function () {
- $scope.step = storage.getObject('user').step;
- var width = window.screen.width;
- if(width>300&width<370){
- $scope.screenWidth = 0;
- }
- else if(width>=370&width<400){
- $scope.screenWidth = 1;
- }
- else{
- $scope.screenWidth = 2;
- }
- $scope.video = {};
- msg.loading();
- $ionicTabsDelegate.showBar(false);
- $scope.load(id,dream_user_id,interaction_id);
- $scope.thisUser = storage.getObject('user');
- $scope.vm.payType = 2;
- homeService.myInfo().then(function(result){
- $scope.user = result.data.data;
- });
- homeService.messageInfo().then(function(result){
- $scope.infos = result.data.data;
- if($scope.infos.dream_info.number==0 && $scope.infos.sup_info.number==0 && $scope.infos.system_info.number==0){
- $scope.showMessage=0;
- }
- else {
- $scope.showMessage=1;
- }
- },function(error){
- });
- });
- $scope.changeStep = function(){
- $scope.step = $scope.step + 1;
- homeService.changeStep().then(function(result){
- if(result.data.status_code==0){
- storage.setObject('user', result.data.data);
- }
- },function(error){
-
- })
- }
- $scope.toUserDetail = function (id) {
- homeService.toUserDetail(id).then(function(result){
- $scope.items = result.data.data;
- $state.go('app.home_userDetail',{id:id,items:$scope.items});
- },function(error){
- //msg.error(msg.data.error)
- })
- };
-
- $scope.toSort = function(){
- //$scope.type = 3;
- $scope.changeType(3)
- };
- $scope.destroyInter = function(id,dream_id){
- msg.confirm("互动","是否删除该评论").then(function(result){
- if(result==true)
- {
- homeService.destroyInter(id).then(function(result){
- msg.text('删除成功');
- $scope.load(dream_id);
- },function(error){
- msg.error(error.data.message);
- });
- }
- });
- };
- $scope.load = function (id,dream_user_id,interaction_id) {
- homeService.dreamDetail(id,dream_user_id,interaction_id).then(function (result) {
- console.log(result);
- $scope.showCode = function(codeName){
- $scope.url = codeName;
- $scope.code = true;
- };
- $scope.hideCode = function(){
- $scope.code = false;
- };
- $scope.dream = result.data.data;
- //if($scope.timer=='已结束'|| 100*$scope.dream.get_coin/$scope.dream.coin>=100){
- // $scope.codeBtn = true;
- //}
- if($scope.timer=='已结束'){
- $scope.codeBtn = true;
- }
- if($scope.dream.video){
- if($scope.dream.video.indexOf('http')<0){
- $scope.dream.vpic = config.server+'upload/vpic/'+$scope.dream.video+'.jpg';
- $scope.dream.video = config.imgServer+$scope.dream.video;
- }
- else {
- //$scope.dream.vpic = $scope.dream.video+'upload/vpic/'+'.jpg';
- $scope.dream.vpic = $scope.dream.video.replace(/attachment/,'upload/vpic/')+'.jpg';
- $scope.dream.video = $scope.dream.video;
- }
- }
- var reg = new RegExp("\n", "g");
- $scope.dream.about = $scope.dream.about.replace(reg, "<br/>");
- var end_time = new Date($scope.dream.end_time.replace(/-/g, "/"));
- var date = new Date();
- var inter = (end_time.getTime() - date.getTime()) / 1000;
- leftTimer(inter);
- $scope.multi.a = $scope.dream.a;
- $scope.multi.b = new Date($scope.dream.created_at.replace(/-/g, "/"));
- $scope.multi.c = $scope.dream.c;
- $scope.multi.promise = $scope.dream.a;
- var newtop3user = '' ;
- angular.forEach($scope.dream.top3user, function(user) {
- newtop3user= newtop3user +user.id+","
- });
- if(top3user!=''&&newtop3user!=top3user){
- //测试动画切换
- $timeout(function() {
- $scope.sort.slide1 = 'list-grow-animation';
- $scope.sort.slide2 = 'slide-in-both-ways';
- $scope.sort.slide3 = 'bounce-animation';
- }, 50);
- }
- top3user = newtop3user;
- if($scope.dream.top3user[0])$scope.sort.first = $scope.dream.top3user[0].avatar;
- if($scope.dream.top3user[1])$scope.sort.second = $scope.dream.top3user[1].avatar;
- if($scope.dream.top3user[2])$scope.sort.third = $scope.dream.top3user[2].avatar;
- //$scope.calcmultiplier();
- msg.hide();
- }, function (error) {
- msg.hide();
- });
- };
- $scope.openSupport = function () {
- msg.alert("支持乘数","为了支持您的梦想者,乘数越高,得到的梦想分越高,抓紧机会哟~喵!(梦想币x支持乘数=梦想分)");
- };
- $scope.multi = {
- a: '',
- b: '',
- c: '',
- result: 1,
- promise:null
- };
- $scope.tosupport = false;
- $scope.support = function ($event) {
- $event.stopPropagation();
- $scope.tosupport = true;
- $scope.vm.coin = 0;
- $scope.index = 0;
- };
- $scope.cancelSupport = function () {
- $scope.tosupport = false;
- $scope.toshare = false;
- $scope.input.show = false;
- };
- $scope.toshare = false;
- $scope.toRecharge = function(){
- $state.go("app.recharge")
- };
- $scope.share = function (type,$event) {
- $scope.toshare = true;
- if (type==0) {
- //分享给朋友
- Wechat.share({
- message: {
- title: $scope.dream.name,
- description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '\n' + $scope.dream.about,
- thumb: $scope.dream.imgs[0].pic,
- media: {
- type: Wechat.Type.WEBPAGE,
- webpageUrl: config.server + "/admin/share/view?id=" + id + '&user_id = ' + $scope.user.id
- }
- },
- scene: Wechat.Scene.SESSION
- }, function () {
- //msg.alert('分享','分享成功');
- msg.success('分享成功');
- }, function (reason) {
- //msg.alert('分享','分享失败');
- msg.error('分享失败');
- });
- }
- if(type==1){
- Wechat.share({
- message: {
- title: $scope.dream.name,
- description: $scope.dream.user.nickname + '在瞄喵发布了一个新的梦想。' + '\n' + $scope.dream.about,
- thumb: $scope.dream.imgs[0].pic,
- media: {
- type: Wechat.Type.WEBPAGE,
- webpageUrl: config.server + "/admin/share/view?id=" + id
- }
- },
- scene: Wechat.Scene.TIMELINE
- }, function () {
- msg.success('分享成功');
- }, function (reason) {
- msg.error('分享失败');
- });
- }
- };
- //实时排行
- $scope.sort = {
- slide: ''
- };
- $scope.changeType = function (type) {
- $ionicScrollDelegate.scrollTop(true);
- $scope.type = type;
- };
- $scope.index = 0;
- $scope.vm = {
- coin:"",
- title:""
- };
- $scope.timer = '';
- var leftTimer = function (countDown) {
- if (isNaN(countDown)) {
- $scope.timer = '已结束';
- return;
- }
- if (countDown<=0) {
- $scope.timer = '已结束';
- return;
- }
- var day=parseInt(countDown/(24*60*60));
- var h=parseInt(countDown/(60*60)%24);
- var m=parseInt(countDown/60%60);
- var s=parseInt(countDown%60);
- //$scope.timer=(h<10?'0'+h:h)+'时'+(m<10?'0'+m:m)+'分'+(s<10?'0'+s:s)+'秒';
- if(day>0) $scope.timer = day+'天';
- if(day<0 && h>0) $scope.timer = h+'小时';
- if(day<0 && h<0 && m>0) $scope.timer = m+'分钟';
- if(day<0 && h<0 && m<0) $scope.timer = '已结束';
- /* if($scope.leftTimer)$interval.cancel($scope.leftTimer);
- $scope.leftTimer = $interval(function () {
- if (countDown >= 1) leftTimer(countDown - 1);
- },1000);*/
- /*if(countDown<=0){
- $scope.timer='结束';
- }*/
- };
- $scope.changeIndex = function (index) {
- $scope.index = index;
- $scope.vm.coin = index*10;
- };
- $scope.vidEnded = function () {
- alert('播放完毕');
- };
- //实时计算支持乘数
- //$scope.calcmultiplier = function () {
- // $scope.multi.promise = $interval(function () {
- //
- // var date = new Date();
- // var inter = date.getTime() - $scope.multi.b.getTime();
- // var minutes = Math.floor(inter / (60 * 1000));
- // var number = $scope.multi.a * minutes + $scope.multi.c;//js浮点运算会失真,根据muti.a的可能值范围,比如乘以100再除以100
- // if (number<=1) {
- // number = 1;
- // }
- // $scope.multi.result = Math.round(number * 100 / 100);
- // },1000);
- //};
- $scope.supportDream = function (data) {
- if(!$scope.vm.coin){
- msg.error("请选择梦想币数量!");
- return ;
- }
- var data = {
- id:id,
- coin:$scope.vm.coin
- };
- homeService.supportDream(data).then(function(result){
- $scope.tosupport = false;
- $scope.load(id);
- homeService.myInfo().then(function(result){
- $scope.user = result.data.data;
- });
- $interval.cancel($scope.multi.promise);
- msg.text("发送成功",1000);
- });
- };
- $scope.collectionDream = function(is_collection){
- homeService.collectionDream(id,is_collection).then(function(result){
- $scope.dream.is_collection=result.data.data;
- })
- };
- $scope.add = function(is_collection){
- var data = {
- id:id,
- title:$scope.vm.title,
- pics:$scope.imgs,
- video:$scope.video.server
- };
- homeService.add_interaction(data).then(function(){
- $scope.load(id);
- $scope.closeModal();
- })
- };
- $scope.showAbout = true;
- $scope.hideAbout = false;
- $scope.showText = function(){
- $scope.aboutStyle = {
- "white-space" : "normal"
- };
- $scope.showAbout = false;
- $scope.hideAbout = true;
- };
- $scope.hideText = function(){
- $scope.aboutStyle = {
- "white-space" : "nowrap"
- };
- $scope.showAbout = true;
- $scope.hideAbout = false;
- };
- $scope.input = {
- placeholder: '评论',
- focus: false,
- show:false
- };
- $scope.showmore = function (index) {
- if ($scope.dream.interactions[index].showmore) {
- $scope.dream.interactions[index].showmore = false;
- } else {
- $scope.dream.interactions[index].showmore = true;
- }
- };
- $scope.replay = function ($event, name, to_userid, index) {
- $event.stopPropagation();
- $scope.input.focus = true;
- $scope.input.show = true;
- angular.forEach($scope.dream.interactions, function (item) {
- item.show = false;
- });
- $scope.dream.interactions[index].show = true;
- $scope.dream.interactions[index].focus = true;
- $scope.input.placeholder = "评论" + name+":";
- $scope.to_userid = to_userid;
- $scope.vm.title='';
- $scope.vm.comment='';
- };
- $scope.replayOther = function ($event, name, to_userid, index,currentindex) {
- $event.stopPropagation();
- if($scope.dream.interactions[index].comments[currentindex].user_id!=$scope.user.id){
- $scope.input.focus = true;
- $scope.input.show = true;
- angular.forEach($scope.dream.interactions, function (item) {
- item.show = false;
- });
- $scope.dream.interactions[index].show = true;
- $scope.dream.interactions[index].focus = true;
- $scope.input.placeholder = "评论" + name;
- $scope.to_userid = to_userid;
- $scope.vm.title='';
- $scope.vm.comment='';
- }
- else if($scope.timer!='已结束') {
- msg.confirm("评论","是否删除评论").then(function(result){
- if(result==true)
- {
- homeService.deleteComment($scope.dream.interactions[index].comments[currentindex].id).then(function(result){
- msg.text("删除成功");
- $scope.load(id);
- },function(error){
- msg.error(error.data.message);
- })
- }
- });
- }
- };
- $scope.ios={
- isIOS:ionic.Platform.isIOS(),
- productid:''
- }
- //充值
- $scope.charge = function(number){
- if($scope.ios.isIOS){
- if ($scope.ios.productid.length<2){
- msg.text('请选择充值金额');
- return;
- }
- inAppPurchase
- .buy($scope.ios.productid)
- .then(function (data) {
- return inAppPurchase.consume(data.productType, data.receipt, data.signature);
- })
- .then(function () {
- msg.success('购买成功');
- })
- .catch(function (err) {
- alert('购买失败:'+err);
- });
- }else{
- if (!number) {
- msg.text('请输入充值金额');
- return;
- }
- homeService.charge(number,2).then(function (result) {
- //todo:result需要返回支付宝或者微信的签名信息
- console.log("result: " + JSON.stringify(result));
- var payInfo = result.data.data;
- if ($scope.vm.payType == 1) { //支付宝
- cordova.plugins.AliPay.pay(payInfo, function success(e) {
- $scope.clicksub = false;
- if (e.resultStatus == '9000') {
- alert(orderID);
- $timeout(function () {
- $scope.closeRechargeModal();
- }, 1000);
- homeService.myInfo().then(function (result) {
- $scope.user = result.data.data;
- });
- } else {
- msg.error("支付失败");
- // msg.error("支付失败:" + JSON.stringify(e));
- }
- }, function error(e) {
- $scope.clicksub = false;
- // msg.error("支付失败:" + JSON.stringify(e));
- msg.error("支付失败");
- });
- }
- if ($scope.vm.payType == 2) { //微信
- // var obj = JSON.parse(payInfo);
- var obj = payInfo.orderString;
- // console.log("obj: " + JSON.stringify(obj));
- var params = {
- partnerid: obj.partnerid, // merchant id
- prepayid: obj.prepayid, // prepay id
- noncestr: obj.noncestr, // nonce
- timestamp: obj.timestamp, // timestamp
- sign: obj.sign, // signed string
- };
- // console.log("result: " + JSON.stringify(params));
- Wechat.sendPaymentRequest(params, function (r) {
- // $scope.clicksub = false;
- $timeout(function () {
- $scope.closeRechargeModal();
- }, 1000);
- $scope.load(id,dream_user_id,interaction_id);
- // courseService.orderStatus(orderID, $scope.paytype).then(function (result) {
-
- // homeService.myInfo().then(function (result) {
- // $scope.user = result.data.data;
- // });
- // }, function (erro) {
- // // msg.alert("支付反馈失败:" + JSON.stringify(erro));
- // });
- }, function (reason) {
- $scope.clicksub = false;
- // msg.alert("支付失败:" + JSON.stringify(reason));
- });
- }
- });
- }
- };
- $scope.submitComment = function (index,to_userid) {
- var interaction = $scope.dream.interactions[index];
- var iid = interaction.id;
- // $scope.dream.interactions[index].comments.push($scope.vm.comment);
- $scope.input.focus = true;
- if ($scope.vm.comment && $scope.vm.comment == '' || !iid) return;
- var data = {
- id:iid,
- content:$scope.vm.comment,
- comment_user_id:to_userid,
- to_user_id: $scope.dream.user.id
- };
- if($scope.timer=='已结束'){
- msg.alert("评论","该梦想已结束,不支持评论");
- }
- else {
- homeService.add_comment(data).then(function(){
- msg.success('评论成功');
- $scope.vm.comment = '' ;
- $scope.load(id);
- $scope.closeModal();
- });
- }
- };
- $scope.bigImage = false;
- $scope.showBigImage = function ($event, imageName) {
- $event.stopPropagation();
- $scope.url = imageName;
- $scope.bigImage = true;
- };
- $scope.hideBigImage = function(){
- $scope.bigImage = false;
- };
- $ionicModal.fromTemplateUrl('qrCode.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function(modal) {
- $scope.qrCodemodal = modal;
- });
- $scope.openCode = function($event) {
- $event.stopPropagation();
- $scope.qrCodemodal.show();
- $scope.vm.money = '';
- };
- $scope.closeCode = function() {
- $scope.qrCodemodal.hide();
- };
- $ionicModal.fromTemplateUrl('commentPic.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function(modal) {
- $scope.CommentPicmodal = modal;
- });
- $scope.openCommentPic = function(pic,$event) {
- $event.stopPropagation();
- $scope.CommentPicmodal.show();
- $scope.commentPicUrl = pic;
- };
- $scope.closeCommentPic = function() {
- $scope.CommentPicmodal.hide();
- };
- $scope.addpict = function () {
- common.chooseImage().then(function (img) {
- common.uploadFiles(img,1).then(function (result) {
- var response = JSON.parse(result.response);
- var file = config.imgServer + response.data.file;
- $scope.imgs.push(file);
- }, function (error) {
- msg.error('图片上传失败');
- });
- }, function (error) {
- console.log('图片选择失败');
- });
- };
- $scope.deletefile = function (file) {
- var index = $scope.imgs.indexOf(file);
- $scope.imgs.splice(index, 1);
- common.deletefile(file).then(function () {
- })
- };
- $scope.addvideo = function () {
- common.chooseVideo().then(function (file) {
- msg.loading();
- common.uploadFiles(file, 2).then(function (result) {
- msg.hide();
- var response = JSON.parse(result.response);
- $scope.video.server = response.data.file;
- var file = config.imgServer+response.data.file;
- $scope.video.isOK = true;
- $scope.video.file = file;
- $scope.video.vpic = config.server+'upload/vpic/'+response.data.file+'.jpg';
- }, function (error) {
- //msg.error('视频上传失败');
- msg.hide();
- msg.error(JSON.stringify(error));
- });
- }, function (erro) {
- console.log('选择视频失败');
- });
- };
- $scope.deletevideo = function (file) {
- $scope.video = {};
- common.deletefile(file).then(function (res) {
- },function(erro){
- alert(JSON.stringify(erro));
- })
- };
- $ionicModal.fromTemplateUrl('recharge-modal.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function(modal) {
- $scope.rechagemodal = modal;
- });
- $scope.openRechargeModal = function() {
-
- $scope.rechagemodal.show();
- $scope.vm.money = '';
- };
- $scope.closeRechargeModal = function() {
- $scope.rechagemodal.hide();
- };
- $ionicModal.fromTemplateUrl('interaction-modal.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function(modal) {
- $scope.modal = modal;
- });
- $scope.openModal = function() {
- $scope.modal.show();
- $scope.vm.title = '';
- $scope.imgs = [];
- $scope.video = {};
- };
- $scope.closeModal = function() {
- $scope.modal.hide();
- };
- //当我们用到模型时,清除它!
- $scope.$on('$destroy', function() {
- $scope.modal.remove();
- });
- $scope.toMessage = function(){
- if($location.path()=="/app/home/dreamdetail"){
- $state.go("app.message");
- }
- else {
- $state.go("app.my_message");
- }
- }
- }]);
- app.controller('userDetailCtrl', ["$scope","$location", "$state", "$ionicModal","storage","msg", "common", "config", "homeService", "$ionicTabsDelegate", "$stateParams", "$ionicModal", "$timeout", "$ionicScrollDelegate", "$interval"
- , function ($scope,$location, $state,$ionicModal, storage , msg, common, config, homeService, $ionicTabsDelegate, $stateParams, $ionicModal, $timeout, $ionicScrollDelegate, $interval) {
- var id = $stateParams.id;
- $scope.items = $stateParams.items;
- $scope.$on('$ionicView.beforeEnter', function () {
- $ionicTabsDelegate.showBar(false);
- });
- $scope.attentionUser = function(is_care){
- homeService.attentionUser(id,is_care).then(function(result){
- $scope.items.is_care=result.data.data;
- })
- };
- $scope.next = function (type) {
- //type:1 前一个,type:2 后一个
- if($scope.items.imgs.length>0){
- if(type==1)
- {
- var temp= $scope.items.imgs.splice(0,1);
- $scope.items.imgs.push(temp[0]);
- }
- if (type==2){
- var temp= $scope.items.imgs.splice($scope.items.imgs.length-1,1);
- $scope.items.imgs.unshift(temp[0]);
- }
- }
- };
- $scope.bigImage = false;
- $scope.showBigImage = function(imageName,imageIndex){
- $scope.url = imageName;
- $scope.imageIndex = imageIndex;
- $scope.bigImage = true;
- };
- $scope.hideBigImage = function(){
- $scope.bigImage = false;
- };
- $scope.swipeLeft = function (imageIndex) {
- if ($scope.imageIndex < $scope.items.imgs.length - 1 && $scope.imageIndex >= 0)
- $scope.imageIndex = $scope.imageIndex + 1;
- else {
- //如果图片已经是最后一张图片了,则取index = 0
- $scope.imageIndex = 0;
- }
- //替换url,展示图片
- $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
- $scope.bigImage = true; //显示大图
- };
- $scope.swipeRight = function (imageIndex) {
- if ($scope.imageIndex <= $scope.items.imgs.length - 1 && $scope.imageIndex > 0)
- $scope.imageIndex = $scope.imageIndex - 1;
- else {
- //如果图片已经是第一张图片了,则取index = Images.length-1
- $scope.imageIndex = $scope.items.imgs.length - 1;
- }
- //替换url,展示图片
- $scope.url = $scope.items.imgs[$scope.imageIndex].pic; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
- $scope.bigImage = true; //显示大图
- };
- $scope.cancelSupport = function () {
- $scope.tosupport = false;
- $scope.toshare = false;
- };
- $scope.toshare = false;
- $scope.toshare = false;
- $scope.toRecharge = function(){
- $state.go("app.recharge")
- };
- $scope.toDetail = function (dream_id) {
- if($scope.items.near_dream==null){
- msg.alert("当前梦想","该用户没有当前梦想");
- }
- if($scope.items.near_dream!=null){
- var dream_id = $scope.items.near_dream.id;
- if($location.path()=="/app/home/userDetail"){
- $state.go('app.home_dreamdetail',{id:dream_id});
- }
- else {
- $state.go('app.my_dreamdetail',{id:dream_id});
- }
- }
- };
- $scope.toOldDream = function(){
- if($scope.items.dreams.length<2){
- msg.alert("曾经的梦想","该用户没有曾经的梦想");
- }
- if($scope.items.dreams.length>1){
- if($location.path()=="/app/home/userDetail"){
- $state.go('app.oldDream',{user_id:$scope.items.user.id});
- }
- else {
- $state.go('app.myOldDream',{user_id:$scope.items.user.id});
- }
- }
- };
- $scope.toSupportDream = function(){
- if($scope.items.sup_dreams.length==0){
- msg.alert("支持的梦想","该用户没有支持的梦想");
- }
- if($scope.items.sup_dreams.length!=0){
- if($scope.items.dreams.length>1){
- if($location.path()=="/app/home/userDetail"){
- $state.go('app.supportDream',{user_id:$scope.items.user.id});
- }
- else {
- $state.go('app.mySupportDream',{user_id:$scope.items.user.id});
- }
- }
- }
- };
- $scope.collectionDream = function(is_collection){
- homeService.collectionDream(id,is_collection).then(function(result){
- $scope.user.is_collection=result.data.data;
- })
- };
- }]);
- app.controller('homeCollectCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
- , function ($scope, $ionicTabsDelegate,$state, myService, msg) {
- $scope.$on('$ionicView.beforeEnter', function () {
- $ionicTabsDelegate.showBar(false);
- myService.collect().then(function(result){
- $scope.dreams = result.data.data.dreams;
- });
- });
- $scope.toDetail = function (id) {
- $state.go('app.home_dreamdetail',{id:id});
- };
- }]);
- app.controller('shareDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
- , function ($scope,homeService,$stateParams, $state, msg) {
- $scope.dream = $stateParams.item;
- $scope.showAbout = true;
- $scope.hideAbout = false;
- $scope.showText = function(){
- $scope.aboutStyle = {
- "white-space" : "normal"
- };
- $scope.showAbout = false;
- $scope.hideAbout = true;
- };
- $scope.hideText = function(){
- $scope.aboutStyle = {
- "white-space" : "nowrap"
- };
- $scope.showAbout = true;
- $scope.hideAbout = false;
- };
- }]);
- //app.controller('homeMessageCtrl', ["$scope", "$ionicTabsDelegate","$state", "myService", "msg"
- // , function ($scope,$ionicTabsDelegate, $state, myService, msg) {
- // $scope.$on('$ionicView.beforeEnter', function () {
- // $ionicTabsDelegate.showBar(false);
- // myService.messageInfo().then(function(result){
- // $scope.infos = result.data.data;
- // },function(error){
- //
- // });
- // });
- // $scope.notRead = function(){
- // myService.notRead().then(function(result){
- // myService.messageInfo().then(function(result){
- // $scope.infos = result.data.data;
- // },function(error){
- //
- // });
- // },function(error){
- //
- // })
- // };
- // //系统消息
- // $scope.systemInfo = function(){
- // $state.go("app.message_sys");
- // myService.systemInfo().then(function(result){
- // },function(error){
- //
- // });
- // };
- // //回复我的
- // $scope.replyMy = function(){
- // $state.go("app.message_reply");
- // myService.replyMy().then(function(result){
- //
- // },function(error){
- //
- // });
- // };
- // $scope.personalLetter = function(){
- // $state.go("app.letter");
- // }
- // }]);
- app.controller('oldDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
- , function ($scope,homeService,$stateParams, $state, msg) {
- var user_id = $stateParams.user_id;
- $scope.$on('$ionicView.beforeEnter',function(){
- $scope.toUserDetail(user_id);
- });
- $scope.toUserDetail = function(user_id){
- homeService.toUserDetail(user_id).then(function(result){
- $scope.items = result.data.data;
- $scope.user = result.data.data.user;
- $scope.dreams = $scope.user.dreams;
- },function(error){
- })
- };
- $scope.toDetail = function(){
- $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
- };
- }]);
- app.controller('supportDreamCtrl', ["$scope","homeService", "$stateParams","$state", "msg"
- , function ($scope,homeService,$stateParams, $state, msg) {
- var user_id = $stateParams.user_id;
- $scope.$on('$ionicView.beforeEnter',function(){
- $scope.toUserDetail(user_id);
- });
- $scope.toUserDetail = function(user_id){
- homeService.toUserDetail(user_id).then(function(result){
- $scope.items = result.data.data;
- $scope.user = result.data.data.user;
- $scope.dreams = $scope.user.sup_dream;
- },function(error){
- })
- };
- $scope.toDetail = function(){
- $state.go("app.home_userDetail",{user_id:user_id,items:$scope.items})
- }
- }]);
- app.controller('searchCtrl', ["$scope","homeService", "$state", "msg", "$ionicTabsDelegate", "$ionicNavBarDelegate"
- , function ($scope,homeService, $state, msg, $ionicTabsDelegate, $ionicNavBarDelegate) {
- $scope.showMore = function (keyword,index) {
- if(!keyword)return;
- $scope.index = index;
- $scope.search(keyword);
- };
- $scope.search = function (keyword) {
- $scope.vm.keyword = keyword;
- homeService.search(keyword).then(function(result){
- $scope.isResult = true;
- $scope.dream_infos = result.data.data.dream_infos;
- $scope.user_infos = result.data.data.user_infos;
- });
- };
- $scope.toUserDetail = function (id) {
- homeService.toUserDetail(id).then(function(result){
- $scope.items = result.data.data;
- $state.go('app.home_userDetail',{id:id,items:$scope.items});
- },function(error){
- //msg.error(msg.data.error)
- })
- };
- $scope.toDetail = function (id) {
- $state.go('app.home_dreamdetail',{id:id});
- };
-
- $scope.$on('$ionicView.beforeEnter', function () {
- $scope.isResult = false;
- $scope.index = 0;
- $scope.vm = {
- keyword : ""
- };
- $ionicTabsDelegate.showBar(false);
- // $ionicNavBarDelegate.showBackButton(false);
- homeService.search('').then(function(result){
- $scope.hot_searches = result.data.data.hot_searches;
- $scope.history_searches = result.data.data.history_searches;
- });
- });
- }]);
- app.controller('interactionAddCtrl', ["$scope","homeService", "$state", "msg","config","common", "$ionicTabsDelegate", "$ionicNavBarDelegate"
- , function ($scope,homeService, $state, msg,config,common, $ionicTabsDelegate, $ionicNavBarDelegate) {
- }]);
- app.controller('homeDreamsCtrl', ["$scope", "$state", "myService", "msg"
- , function ($scope, $state, myService, msg) {
- $scope.$on('$ionicView.beforeEnter', function () {
- myService.myDream().then(function(result){
- console.log(result.data.data);
- $scope.dreams = result.data.data;
- });
- });
- $scope.toDetail = function (id) {
- $state.go('app.home_dreamdetail',{id:id});
- };
- }]);
-
- })(angular.module('app.controllers'));
|