<template>
	<view class="page">
		<view class="top">
			<view class="wd">
				<view class="qw"><image :src="user == '' ? '../../static/ls.jpg' : user.avatarUrl" class="head"></image></view>
				<view class="xs" @click="navigate('/pages/user/info')">
					<view v-if="user == ''">登录 / 注册</view>
					<view class="nickName" v-else>{{ user.nickName }}</view>
					<view class="nh">{{ user == '' ? '你还未登陆' : ' 你好，欢迎来到智慧旅游' }}</view>
				</view>
			</view>
			<image src="../../static/bj.jpg" mode="aspectFill"></image>
		</view>
		<view class="main">
			<view class="list">
				<view class="item hr" @click="navigate('/pages/order/my')">
					<text class="icon ic" style="background-color: #2979FF;">&#xe705;</text>
					<text>我的预约</text>
					<text class="icon arrow">&#xe62d;</text>
				</view>
				<view class="item hr" @click="navigate('/pages/shop/list')">
					<text class="icon ic" style="background-color:red">&#xe616;</text>
					<text>商家中心</text>
					<text class="icon arrow">&#xe62d;</text>
				</view>
			</view>
			<view class="list" style="margin-top: 13px;">
				<view class="item hr" @click="navigate('/pages/user/info')">
					<text class="icon ic" style="background-color:#606266">&#xe626;</text>
					<text>我的信息</text>
					<text class="icon arrow">&#xe62d;</text>
				</view>
				<view class="item hr" @click="call()">
					<text class="icon ic" style="background-color:#366092">&#xe634;</text>
					<text>求助电话</text>
					<text class="icon arrow">&#xe62d;</text>
				</view>
				<view class="item hr" @click="navigate('/pages/other/feedback')">
					<text class="icon ic" style="background-color:#FF554B">&#xe610;</text>
					<text>投诉建议</text>
					<text class="icon arrow">&#xe62d;</text>
				</view>
				<view class="item hr">
					<button open-type="share">
						<text class="icon ic" style="background-color:#18B566">&#xe607;</text>
						<text>分享朋友</text>
						<text class="icon arrow">&#xe62d;</text>
					</button>
				</view>
				<view class="item" @click="navigate('/pages/other/about')">
					<text class="icon ic" style="background-color:#606266">&#xe65f;</text>
					<text>关于我们</text>
					<text class="icon arrow">&#xe62d;</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			ip: this.$http.urls.ip,
			user: this.$getUser(),
			aboutUs: { showPictures: [] }
		};
	},
	onLoad() {
		this.aboutUs = uni.getStorageSync('aboutUs');
	},
	onShow() {
		this.user = this.$getUser();
	},
	methods: {
		navigate(url) {
			if (this.$hasLogin()) {
				uni.navigateTo({ url: url });
			} else {
				uni.navigateTo({ url: '/pages/user/login' });
			}
		},
		//拨打求助电话
		call() {
			if (!this.$hasLogin()) {
				uni.showModal({ content: '登陆才能使用该功能', showCancel: false });
				return;
			}
			//获取拨打人位置
			uni.authorize({
				scope: 'scope.userLocation',
				success: s => {
					uni.getLocation({
						type: 'wgs84',
						success: res => {
							uni.showModal({
								title: '提示',
								content: '是否拨打' + this.aboutUs.helpPhone + '求援电话?',
								success: c => {
									if (c.confirm) {
										//上传拨打救援记录
										this.$http.request({
											method: 'POST',
											url: this.$http.urls.pushHelp,
											data: {
												memberId: this.$getUser().memberId,
												lat: res.latitude,
												lng: res.longitude,
												phone: this.aboutUs.helpPhone,
												memberPhone: this.$getUser().mobile
											},
											success: r => {
												uni.makePhoneCall({
													phoneNumber: this.aboutUs.helpPhone
												});
											}
										});
									}
								}
							});
						}
					});
				},
				fail(res) {
					//1.2 拒绝授权
					console.log(JSON.stringify(res));
				}
			});
		}
	}
};
</script>

<style lang="scss">
.top {
	position: relative;
	height: 300px;
	color: white;
	.wd {
		position: absolute;
		top: 70px;
		left: 20px;
		z-index: 11;
		.head {
			width: 75px;
			height: 75px;
			border-radius: 50%;
		}
		.xs {
			margin-left: 90px;
			width: 100%;
			font-weight: bold;
			margin-top: 10px;
			.nickName {
				margin-top: 20px;
			}
			.nh {
				font-size: 12px;
				font-weight: normal;
				margin-top: 5px;
			}
		}
	}
	image {
		width: 100%;
		height: 300px;
		position: absolute;
	}
}
.main {
	padding: 15px 15px 50px 15px;
	width: 100%;
	overflow: hidden;
	position: absolute;
	margin-top: -100px;
	.list {
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		width: 100%;
		background-color: white;
		border-radius: 5px;
		overflow: hidden;
		.item {
			padding: 16px;
			background-color: white;
			font-size: 16px;
			.ic {
				font-size: 20px;
				background-color: red;
				text-align: center;
				padding: 5px;
				border-radius: 5px;
				margin-right: 9px;
				color: white;
			}
			.arrow {
				font-size: 20px;
			}
		}
	}
}
button {
	text-align: left;
	background-color: white;
	color: #2e2e2e !important;
	font-size: 16px;
	padding-left: 0px;
	padding-right: 2px;
	line-height: 20px;
	overflow: initial;
}
</style>
