<template>
	<view class="">
		<u-popup v-model="show" mode="center" width="80%" :border-radius="10" negativeTop="200">
			<view style="padding:30rpx 0rpx;display: flex;flex-direction: column;justify-content: space-between;">
				<view class="center text-center padding-bottom-30">
					<text>注销账户</text>
				</view>
				<view class="flex-sub" style="margin: 50rpx 30rpx;">
					<text class=" text-red"
						style="font-size: 28rpx;line-height: 56rpx;">您的个人信息，账户信息，认证信息将被清空/删除，确定进行此操作？</text>
					<view class="margin-top " v-if="hasMember">
						<text class="cuIcon-title text-red"></text>
						<text class="text-sm ">业主角色请到【家人管理】处移除房间下的成员</text>
					</view>
				</view>

				<view class="text-sm" style="display: flex;padding: 5rpx 32rpx 38rpx">
					<u-checkbox v-model="checked" size="26" name="checked">
						<text style="font-size: 28rpx;">确定注销账户</text>
					</u-checkbox>
				</view>

				<view style="display: flex;justify-content: center">
					<u-button v-if="type==1" :customStyle="createStyle" @click="createRoom">创建新房间</u-button>
					<u-button v-else :customStyle="cancelStyle" @click="show=false">暂不注销</u-button>
					<u-button :disabled="time>0" type="primary" :customStyle="confirmStyle" @click="confirm">
						<text v-if="time>0">{{time}}s</text>
						<text v-else>确定注销</text>
					</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: '',
		data() {
			return {
				hasMember: false,
				time: 8,
				interval: null,
				checked: false,
				show: false,
				roomList: [],
				iconStyle: {
					'color': '#2f7ff5'
				},
				createStyle: {
					backgroundColor: '#ff9900',
					height: '70rpx',
					lineHeight: '70rpx',
					width: '210rpx',
					fontSize: '28rpx',
					color: '#FFFFFF',
					marginLeft: '15rpx',
					borderRadius: '0'
				},
				cancelStyle: {
					height: '70rpx',
					lineHeight: '70rpx',
					width: '210rpx',
					fontSize: '28rpx',
					border: '1rpx solid #afb0b3',
					marginRight: '15rpx',
					borderRadius: '0'
				},
				confirmStyle: {
					height: '70rpx',
					lineHeight: '70rpx',
					width: '210rpx',
					fontSize: '28rpx',
					marginLeft: '15rpx',
					borderRadius: '0'
				}
			};
		},
		created() {
			this.countdown()
		},
		beforeDestroy() {
			if (this.interval) {
				clearInterval(this.interval)
			}
		},
		methods: {
			async showModal() {
				let res = await this.$http.hasMember(this.vuex_member.id)
				this.hasMember = res.data.data
				this.show = true
			},
			confirm() {
				if (!this.checked) {
					this.$u.toast('请先勾选确定注销账户操作')
					this.show = true
					return
				}
				if (this.hasMember) {
					this.$u.toast('请先移除相关成员')
					return
				}
				this.$http.logout(this.vuex_member.id)
				this.show = false
				this.$dialog.showModal("注销成功,请退出小程序", false).then(res => {
					this.$store.commit('clear')
					getApp().globalData.anyHousePass = false
					getApp().globalData.member = null
					uni.clearStorage()
					uni.reLaunch({
						url: "/pages/index/index"
					})
				})
			},
			countdown() {
				this.interval = setInterval(() => {
					if (this.time > 0) {
						this.time -= 1
					}
				}, 1000)
			}
		}
	};
</script>

<style lang="scss" scoped>

</style>
