<template>
	<view class="setting_wrap">
		<u-navbar title="我的设置" :autoBack="true" :placeholder="true" v-hideNav></u-navbar>
		<view class="option_list">
			<view class="option_item" @click="toPersonal">
				<view class="item_left">
					<image src="@/static/parson/icon-gezl.png" mode=""></image>
					<text class="label">个人资料</text>
				</view>
				<view class="item-right">
					<u-icon name="arrow-right" color="#aaa"></u-icon>
				</view>
			</view>
			<view class="option_item" @click="handleEditPassword">
				<view class="item_left">
					<image src="@/static/parson/updatePass.png" mode=""></image>
					<text class="label">修改密码</text>
				</view>
				<view class="item-right">
					<u-icon name="arrow-right" color="#aaa"></u-icon>
				</view>
			</view>

			<option-list></option-list>

		</view>
		<view class="logout_btn">
			<u-button type="warning" :plain="true" text="退出账号" size="large" @click="handleShowModal"></u-button>
		</view>
		<u-modal :show="showModal" 
			@confirm="confirm" 
			ref="uModal" 
			:asyncClose="true" 
			showCancelButton
			@cancel="showModal = false"
			cancelColor="#409eff"
			:confirmText="'退出登录'" confirmColor="#f8836c">
			<view class="modal_box">
				确定要退出当前账号
			</view>
		</u-modal>
	</view>
</template>
<script>
	import OptionList from '@/pages/person/option/index.vue'
	export default {
		components: {
			OptionList
		},
		data() {
			return {
				showModal: false
			}
		},
		onLoad: function(opt) {

		},
		methods: {
			handleEditPassword(){
				uni.navigateTo({
					url : "/pages/changePw/index"
				});
			},
			toPersonal(){
				uni.navigateTo({
					url : "/pages/profile/index"
				})
			},
			handleShowModal() {
				this.showModal = true;
			},
			confirm() {
				// 停止电话监听
				this.$store.dispatch("call/stopPhoneListener").catch(error => {
					console.error('退出登录时停止电话监听失败:', error);
				});
				
				this.$store.dispatch("user/logout").then(()=>{
					uni.$u.toast("退出成功");
					setTimeout(()=>{
						this.showModal = false;
						uni.reLaunch({
							url: "/pages/login/index"
						})
					},1000)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.modal_box{
		line-height: 100rpx;
		color: #aaa;
	}
	.logout_btn {
		width: 100%;
		position: absolute;
		left: 50%;
		transform: translate(-50%, 0%);
		bottom: 10%;

		::v-deep .u-button {
			border: none;
		}
	}

	.option_list {

		.option_item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 100rpx;
			border-bottom: 2rpx solid #dfdfdf;
			background-color: #fff;
			padding: 0 30rpx;

			&:last-child {
				border: none;
			}

			.item_left {
				display: flex;
				align-items: center;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 20rpx;
				}

				.label {
					font-size: 28rpx;
					color: #202020;
				}
			}

			.item-right {
				display: flex;
				justify-content: space-between;
				align-items: center;

				::v-deep .u-icon__icon {
					font-size: 30rpx !important;
				}

				text {
					font-size: 24rpx;
					color: #999999;
					margin-right: 20rpx;
				}

				.copy_btn {
					display: flex;
					font-size: 24rpx;
					color: #108CFF;
					margin-right: 30rpx;
				}
			}
		}
	}
</style>
