<template>
	<view class="page">
		
		<view class="listcell">
			<view class="cells" @tap="gotoaddr()">
				<view class="title">
					<image class="timg" src="../../static/image/dz.png"></image>收货地址
				</view>
				<uni-icons type="right" size="18" color="#777777"></uni-icons>
			</view>
			<view class="cells" @tap="gotopj()">
				<view class="title">
					<image class="timg" src="../../static/image/wpj.png"></image>我的评价
				</view>
				<uni-icons type="right" size="18" color="#777777"></uni-icons>
			</view>
			<!-- <view class="cells" @tap="gotomsg()">
				<view class="title">
					<image class="timg" src="../../static/image/tz.png"></image>开启通知
				</view>
				<view style="color:#00a89b">已开启</view>
				<uni-icons type="right" size="18" color="#777777"></uni-icons>
			</view> -->
			<view class="cells" @tap="gotopwd()">
				<view class="title">
					<image class="timg" src="../../static/image/mm.png"></image>修改密码
				</view>
				<uni-icons type="right" size="18" color="#777777"></uni-icons>
			</view>
			<view class="cells" @tap="gotout()">
				<view class="title">
					<image class="timg" src="../../static/image/zx.png"></image>账号注销
				</view>
				<uni-icons type="right" size="18" color="#777777"></uni-icons>
			</view>
			<view class="cells">
				<view class="title"><image class="timg" src="../../static/image/bb.png"></image>关于我们</view>
				<view class="version">版本号 {{versionIn}}</view>
				<uni-icons type="right" size="18" color="#777777"></uni-icons>
			</view>
		</view>
		
		<view class="loginout" @click="loginout">
			退出登录
		</view>
		
	</view>
</template>

<script>
	import { myCache } from '../../utils/utils.js';
	export default {
		data() {
			return {
				openId:"",
				phone:"",
				userid:"",
				versionIn: '1.0.0',
			};
		},
		onLoad() {
			let that = this;
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				that.versionIn = widgetInfo.version;
			});
			// #endif
		},
		onShow(){
			this.openId = myCache('openId');
			var user = myCache('user');
			this.userid = user.userid? user.userid:'';
			this.phone = user.userphone;
			if(this.userid==""||this.userid=="0"){
				uni.navigateTo({
					url: `/pages/login/login`
				});
			}
		},
		methods: {
			gotomsg() {
				var _this=this
				// 开启通知
				uni.showModal({
					title: '提示',
					content: '通知已经开启，确定要关闭通知吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: ress => {
						if (ress.confirm) {
							// 开启通知
							_this.msgDo();
						}
					}
				});
			},
			async msgDo() {
				uni.showLoading({
					title: '关闭通知中...'
				});
				const {data: res} = await uni.$http.post('/Appiso/delBuyerById', {id:this.userid});
				if(res=='1'){
					console.log('通知已关闭！')
					uni.showToast({
						title: '通知已关闭！',
						icon: 'success',
						duration: 2000
					});
				}
				else{
					uni.showToast({
						title: '通知关闭失败！请联系客服后再重试！',
						icon: 'error',
						duration: 2000
					}) 
				}
			},
			gotoaddr() {
				// 收货地址
				uni.navigateTo({
					url: `/pages/address/alist`
				});
			},
			gotopj() {
				// 我的评价
				uni.navigateTo({
					url: `/pages/user/myevaluat`
				});
			},
			gotopwd() {
				// 修改密码
				uni.navigateTo({
					url: `/pages/user/pwdset`
				});
			},
			async gotout(){
				var _this=this;
				// 账号注销
				uni.showModal({
					title: '提示',
					content: '确定要注销账号吗？账号注销后，所有登录信息将删除不可恢复！',
					cancelText: '取消',
					confirmText: '确定',
					success: ress => {
						if (ress.confirm) {
							// 账号注销
							_this.logOutDo();
						}
					}
				});
			},
			async logOutDo() {
				uni.showLoading({
					title: '账号注销中...'
				});
				const {data: res} = await uni.$http.post('/Appiso/delBuyerById', {id:this.userid});
				if(res=='1'){
					console.log('账号已注销！')
					uni.showToast({
						title: '账号已注销！',
						icon: 'success',
						duration: 2000
					});
					// 清除登录缓存
					myCache('phone','');
					myCache('openId','');
					myCache('userid','');
					myCache('userInfo','');
					myCache('alipayuserInfo','');
					myCache("signtype",'11');
					setTimeout(() => {
						// 跳转 我的
						uni.switchTab({
							url: '/pages/user/user'
						});
					}, 2000);
				}
				else if(res=='2'){
					console.log('账号不可注销！')
					uni.showModal({
						title: '提示',
						content: '当前账号还有订单未完成，账号不可注销！请处理后操作！',
						confirmText: '确定',
						success: ress => {
							if (ress.confirm) {
							}
						}
					});
				}
				else{
					uni.showToast({
						title: '账号注销失败！请联系客服后再重试！',
						icon: 'error',
						duration: 2000
					}) 
				}
			},
			loginout(){
				// 退出登录
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: ress => {
						if (ress.confirm) {
							// 清除登录缓存
							myCache('phone','');
							myCache('openId','');
							myCache('userid','');
							myCache('userInfo','');
							myCache('alipayuserInfo','');
							myCache("signtype",'11');
							// 跳转 我的
							uni.switchTab({
								url: '/pages/user/user'
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 0;
		position: relative;
		background-image: url('@/static/image/bg.jpg');
		background-attachment: fixed;
		background-size: cover;
		background-position: center center;
		min-height: calc(100vh - var(--window-top) - var(--window-bottom));
	}
	.loginout {
		height: 80rpx;
		line-height: 80rpx;
		position: relative;
		display: block;
		overflow: hidden;
		background-color: #fff;
		border-radius: 5rpx;
		text-align: center;
		font-size: 28rpx;
		color: #00a89b;
		margin: 50rpx 20rpx 30rpx;
	}
	.listcell {
		position: relative;
		display: block;
		overflow-y: auto;
		margin: 50rpx 20rpx 30rpx;
		box-sizing: content-box;
		.cells {
			background: #FFFFFF;
			display: flex;
			padding: 15rpx 20rpx 5rpx;
			height: 110rpx;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			border-bottom: 1rpx solid #f5f5f5;
			.img {
				width: 48rpx;
				height: 48rpx;
				margin-left: 10rpx;
			}

			.title {
				height: 44rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #0E1521;
				margin-left: 10rpx;
				flex: 1;
				display: flex;
				flex-direction: row;
				justify-items: center;
				.timg{
					width: 40rpx;
					height: 40rpx;
					margin-right: 16rpx;
				}
			}
		}
	}
</style>