<template>
	<view class="content">
		<view class="set-box" >
			<view class="item" @tap="showAlert()">
				<view class="left">
					<view class="title">账号注销及删除应用数据</view>
				</view>
			</view>
		</view>
		
		<view class="checkbox">
			<view class="checkbox-icon" @tap="handleAgree">
				<image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
				<image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
			</view>
			<view>我已阅读并同意<text @tap="goToWeb()">《用户注销协议》</text> </view>
		</view>
		
		<u-modal 
			  :show="showCustomModal" 
			  title="您正在申请注销账户"
			  content="1.账户一旦注销，不可恢复\n 2.用户权益等视为自行放弃，无法继续使用\n"
			  :show-cancel-button="true"
			  cancel-text="我再想想"
			  confirm-text="仍然注销"
			  @confirm="deleteUser"
			  @cancel="showCustomModal = false">
		</u-modal>
		
	</view>
</template>

<script>
 import { removeUser } from '@/api/user'
 export default {
 	data() {
 		return {
			showCustomModal:false,
			userInfo:null,
			agree: false
 		}
 	},
	onLoad() {
		this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
	},

 	methods: {
		// 同意
		handleAgree() {
			this.agree = !this.agree
		},
	    showAlert(){
			if(!this.agree){
				uni.showToast({icon:'none',title: "请先同意用户注销协议"});
				return;
			}
	    	let that=this;
			this.showCustomModal=true;
			
	    	// uni.showModal({
	    	// 	title:"您正在申请注销账户",
	    	// 	content:"账户一旦注销，不可恢复\n 2.会员权益等视为自行放弃，无法继续使用\n 3.医疗行业受法律监管用户问诊订单/病历数据等必须保持15年以上。",
	    	// 	showCancel:true,
	    	// 	cancelText:'我再想想',
	    	// 	confirmText:'仍然注销',
	    	// 	success:res=>{
	    	// 		if(res.confirm){
	    	// 			this.deleteUser();
	    	// 		}else{
	    	// 			// 否则点击了取消  
	    	// 		}
	    	// 	}
	    	// });
	    				
	    },
	    deleteUser(){
	    	let that=this;
			uni.showLoading({title:""});
	    	removeUser().then(res => {
				    uni.hideLoading();
	    			if(res.code==200){
	    				uni.showToast({icon:'none',title: "账号已注销"});
						setTimeout(()=>{
							uni.$emit("loginOut");
						},2000);
	    			}
					else{
						uni.showToast({
							icon:'none',
							title: res.msg
						});
					}
	    		},
	    		rej => {}
	    	);
	    },
		goToWeb(index){
			uni.setStorageSync('url',"http://app.fbylive.com/web/userRemoveService");
			uni.navigateTo({
				url:"/pages/index/h5"
			})
		},
 	}
 }
 
 
</script>


<style scoped lang="scss">
	
@mixin u-flex($flexD, $alignI, $justifyC) {
	display: flex;
	flex-direction: $flexD;
	align-items: $alignI;
	justify-content: $justifyC;
}	
	
page{
	height: 100%;
}

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

.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{
			 
		}
	}
}

.checkbox {
		margin-left: 24rpx;
		margin-top: 24rpx;
		@include u-flex(row, flex-start, flex-start);
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #999999;
		line-height: 38rpx;
		text-align: left;

		text {
			color:#2583EB;
		}

		&-icon {
			flex-shrink: 0;
			margin-right: 12rpx;

			image {
				height: 24rpx;
				width: 24rpx;
			}
		}
		
	}


</style>
