<template>
	<view class="content">
		<view class="es-pt-20 es-pb-20 es-pl-20 es-fs-26 es-c-99 es-bc-f7">你希望收到</view>
		<view class="set-box" >
			<view class="item">
				<view class="left">
					<view class="title">消息通知</view>
					<view class="text">关闭后，可能会错过点赞、评论、关注等消息通知</view>
				</view>
				<switch :checked="user.isPush?true:false" color="#FF233C" @change="switch1Change"  style="transform:scale(0.7)"/>
			</view>
			<!-- <view class="line"></view> -->
			<view class="item">
				<view class="left">
					<view class="title">个性化推送</view>
					<view class="text">依据您的喜好和习惯向您推荐相关信息</view>
				</view>
				<switch :checked="user.isIndividuationPush?true:false" color="#FF233C" @change="switch2Change"  style="transform:scale(0.7)"/>
			</view>
		</view>
		
	</view>
</template>

<script>
 import { editUserPushSetting,getUserPushSetting} from '@/api/user'
 export default {
 	data() {
 		return {
			user:{ 
				   "isPush": 0,
                   "isIndividuationPush": 0
                 }
 		}
 	},
	onLoad() {
		this.getUserPushSetting();
	},
	onNavigationBarButtonTap(e) {
		this.editUserPushSetting();
	},
 	methods: {
	    getUserPushSetting(){
	    	let that=this;
	    	getUserPushSetting().then(res => {
	    			if(res.code==200){
	    				if(res.data!=null){
	    					this.user = res.data;
	    				}
	    				else{
	    					uni.showToast({
	    						icon:'none',
	    						title: res.msg,
	    					});
	    				}
	    			}
	    		},
	    		rej => {}
	    	);
	    },
	    editUserPushSetting(){
	    	let that=this;
			uni.showLoading({title:""});
			let data={"isPush":this.user.isPush?1:0,"isIndividuationPush":this.user.isIndividuationPush?1:0};
	    	editUserPushSetting(data).then(res => {
				    uni.hideLoading();
	    			if(res.code==200){
	    				uni.showToast({icon:'none',title: "操作成功"});
	    			}
					else{
						uni.showToast({
							icon:'none',
							title: res.msg
						});
					}
	    		},
	    		rej => {}
	    	);
	    },
	
		loginNavTo(url){
			if(!this.$isLogin()){
				this.$showLoginPage();
				return;
			}
			uni.navigateTo({
				url: url
			});
		},
		switch1Change(e){
			this.user.isPush=e.detail.value;
			this.editUserPushSetting();
		},
		switch2Change(e){
			this.user.isIndividuationPush=e.detail.value;
			this.editUserPushSetting();
		},
 		
 	}
 }
 
 
</script>


<style scoped lang="scss">
page{
	height: 100%;
}

.content{
	height: 100%;
	background-color: #ffffff;
}

.line{
	height: 1px;background-color: #F7F7F7;
}

.logo{
	padding-top: 15%;
	text-align: center;
	image{
		width: 120rpx;
		height: 120rpx;
		border-radius: 10rpx;
		box-shadow:0px 0px 20rpx rgba(0,0,0,0.2);
	}
	p{
		margin: 10px 0px;
		font-size: 14px;
	}
}
.set-box{
	margin-top: 20upx;
	background: #fff;
	padding: 0 30upx;
	.item{
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25upx 0;
		.left{
			display: flex;
			flex-direction: column;
			.title{
				font-size: 32upx;
				font-weight: bold;
				color: #333;
				margin-bottom: 10rpx;
			}
			.text{
				font-size: 22upx;
				color: #999;
			}
			
		}
		.right{
			width: 10upx;
			height: 20upx;
		 
		}
		.right-text{
			 
		}
	}
}
.contact-btn {
	position: absolute;
	width: 100%;
	display: flex;
	opacity: 0;
}



</style>
