<template>
	<view class="main">

		<view class="backTop"></view>
		<!-- 头部开始 -->
		<view class="header box">
			<view class="header-zuo">
				<u-avatar
					:src="photo?photo:'https://qufang.oss-cn-beijing.aliyuncs.com/upload/icon/xcx/zkgj/headPicture.png'"
					size="148"></u-avatar>
			</view>
			<view class="header-you">
				<view class="userName">{{name}}</view>
				<view class="mobile">{{mobile}}</view>
			</view>
		</view>
		<view class="settingGroup box">
			<navigator class="line" url="/pages/mine/Myprofile">
				<view class="title">
					<image src="/static/images/setting.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					编辑资料
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</navigator>
			<view class="line" @click="phone">
				<view class="title">
					<image src="/static/images/Customer.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					客服电话
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>
			<view class="line" @click="Changehepassword">
				<view class="title">
					<image src="/static/images/password.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					修改密码
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>
			<view class="line" @click="logout" style="border: none;">
				<view class="title">
					<image src="/static/images/exit.png" style="width: 36rpx;height: 36rpx;" mode=""></image>
					退出登录
				</view>
				<view class="right">
					<image src="/static/images/arrow.png" style="width: 18rpx;height: 32rpx;" mode=""></image>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	var app = getApp();
	var util = require("../../utils/util.js");
	var config = require("../../config");

	export default {
		data() {
			return {
				name: "",
				photo: "",
				mobile: "",
			};
		},
		onShow: function() {
			var userInfos = uni.getStorageSync('weapp_session_userInfo_data');
			this.name = userInfos.name,
			this.photo = userInfos.avatar,
			this.mobile = userInfos.username
		},
		methods: {
			//拨打电话
			phone() {
				wx.makePhoneCall({
					phoneNumber: '4008191707,8888' //仅为示例，并非真实的电话号码
				})
			},
			//修改密码
			Changehepassword() {
				uni.navigateTo({
					url: '/pages/mine/Changehepassword'
				});
			},
			//退出
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出？',
					cancelColor: "#999999",
					showCancel: true,
					success(res) {
						if (res.confirm) {
							uni.request({
								url: config.service.logout,
								header: {
									'Authorization': 'Basic dGVzdDp0ZXN0',
									'content-type': 'application/x-www-form-urlencoded'
								},
								method: "DELETE",
								success: function(result) {
									var data = result.data; //console.log("登陆信息", data);
									if(data.data==true){
										app.Closewebsocke()
										uni.clearStorageSync(); //清除缓存
										uni.showToast({
											icon: "none",
											title: "退出成功"
										})
										uni.reLaunch({
											url: '/pages/login/index'
										});
									}
								},
								// 响应错误
								fail: function(loginResponseError) {
									util.showNone("网络异常，请重试");
									return false;
								}
							});	
						}
					}
				});
			}

		}
	};
</script>
<style lang="scss" scoped>
	.main {
		padding: 0 30rpx;
		background: #F8F8F8;
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		padding-bottom: 40rpx;

		.backTop {
			background: #2671E2;
			position: absolute;
			left: 0;
			top: 0;
			width: 750rpx;
			height: 171rpx;
		}

		.box {
			background: #ffffff;
		}
	}

	.header {
		z-index: 2;
		width: 100%;
		height: 212rpx;
		border-radius: 12rpx;
		margin-top: 42rpx;
		display: flex;

		.header-zuo {
			width: 148rpx;
			height: 148rpx;
			margin-top: 32rpx;
			margin-left: 30rpx;
		}

		.header-you {
			margin-left: 20rpx;

			.userName {
				font-size: 36rpx;
				font-weight: 500;
				color: #303030;
				margin-top: 56rpx;
			}

			.mobile {
				font-size: 30rpx;
				color: #BDBDBD;
				margin-top: 20rpx;
			}
		}
	}

	.settingGroup {
		box-shadow: 0px 0px 12px 0px rgba(224, 224, 224, 0.3);
		border-radius: 12rpx;
		margin-top: 30rpx;
		color: #333333;
		font-size: 30rpx;
		display: flex;
		flex-direction: column;

		.line {
			height: 118rpx;
			border-bottom: 1rpx solid #EEEEEE;
			margin: 0 38rpx 0 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.title {
				display: flex;
				align-items: center;
				width: 190rpx;
				justify-content: space-between;
			}
		}
	}
</style>
