<template>
	<view>
		<div class="title">
			<p>当前操作为注销账号，注销后信息将无法恢复。</p>
			<p>请输入登录密码确认！</p>
		</div>
		<div class="btnBox">
			<div class="btn" style="background: #fa3534;color: #fff;" @click="logoffUser">注销用户</div>
		</div>

		<u-modal title="当前操作为注销账号，注销后信息将无法恢复。请输入登录密码确认！！" :show="showLogout" closeOnClickOverlay showCancelButton
			cancelColor="#fa3534" confirmColor="#606266" @cancel="() => showLogout = false" @confirm="logoutBtn()">
			<u--input placeholder="请输入密码" border="surround" v-model="password"></u--input>
		</u-modal>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				showLogout: false,
			};
		},
		methods: {
			logoutBtn() {
				if (!this.password) {
					this.$util.showToast({
						title: '请输入密码'
					});
					return;
				}
				this.$api.sendRequest({
					url: '/api/member/logout',
					data: {
						password: this.password,
					},
					success: res => {
						this.$util.showToast({
							title: res.message
						});
						this.signOut()
					}
				});

			},
			signOut() {
				uni.removeStorage({
					key: 'token',
					success: res => {
						uni.setStorageSync('loginLock', 1);
						//购物车数量
						uni.removeStorageSync('DIY_VIEW_INDEX_popwindow_count')
						uni.removeStorageSync('userInfo')
						this.$store.dispatch('clearCartNumber');
						uni.reLaunch({
							url: "/pages_tool/login/login"
						})
					},
				});
			},
			logoffUser() {
				this.showLogout = true;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		font-size: 34rpx;
		font-weight: 600;
		width: calc(100% - 60rpx);
		position: fixed;
		top: 300rpx;
		left: 30rpx;
		// height: 92rpx;
		width: calc(100% - 60rpx);
		text-align: center;
	}

	.btnBox {
		position: fixed;
		bottom: 76rpx;
		left: 30rpx;
		// height: 92rpx;
		width: calc(100% - 60rpx);

		.btn+.btn {
			margin-top: 40rpx;
		}

		.btn {
			width: 100%;
			height: 92rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;

		}
	}
</style>