<template>
	<view class="content">
		<view v-if="token" style="width: 100%;">
			<view class="head" v-if="info.aud_id" @tap="navTo('/pageTwo/setting/setting')">
				<view class="left">
					<image :src="info.head_pic"></image>
					<text>{{info.nickname}}</text>
				</view>
				<view class="right">
					<uni-icons type="forward" size="20" color="#666"></uni-icons>
				</view>
			</view>
			<view class="head " v-else @click="handleUserEdit">
				<text class="size22">完善资料后，记录更准确哦！</text>
			</view>
		</view>

		<view class="list">
			<view class="item" @tap="navTo('/pageTwo/me/userEdit')">
				<view>
					<image src="/static/11.png" mode=""></image>个人资料
				</view>
				<uni-icons type="forward" size="20" color="#666"></uni-icons>
			</view>
			<view class="item" @tap="navTo('/pageTwo/me/mymenu?pageName=我的菜谱')">
				<view>
					<image src="/static/12.png" mode=""></image>我的菜谱
				</view>
				<uni-icons type="forward" size="20" color="#666"></uni-icons>
			</view>
			<view class="item" @tap="navTo('/pageTwo/me/mymenu?pageName=我的收藏')">
				<view>
					<image src="/static/27.png" mode=""></image>我的收藏
				</view>
				<uni-icons type="forward" size="20" color="#666"></uni-icons>
			</view>

			<view class="item" @tap="navTo('/pageTwo/me/record')">
				<view>
					<image src="/static/13.png" mode=""></image>饮食记录
				</view>
				<uni-icons type="forward" size="20" color="#666"></uni-icons>
			</view>
			<view class="item" @click="navTo('/pageTwo/webview/webview?url=' + configInfo.business_cooperation)">
				<view>
					<image src="/static/14.png" mode=""></image>商务合作
				</view>
				<uni-icons type="forward" size="20" color="#666"></uni-icons>
			</view>
			<!-- <view class="item" @tap="navTo('/pageTwo/me/feedBack')">
				<text>联系客服</text>
				<uni-icons type="forward" size="20" color="#666"></uni-icons>
			</view> -->
		</view>
		<view class="btn" v-if="!token" @click="handleLogin">登录后查看更多</view>
		<view class="btn " v-if="token" @click="handleOutLogin">退出登录</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				token: null
			}
		},
		computed: {
			...mapState(["user",'configInfo']),
			info() {
				return this.user
			},
		},
		onLoad() {
			let that = this
			that.token = uni.getStorageSync('token')
		},
		methods: {
			handleOutLogin() {
				let that = this
				uni.showModal({
					title: '友情提示',
					content: '是否退出登录？',
					success: function(res) {
						if (res.confirm) {
							that.$model.getloginOut({}).then((res) => {
								that.$tools.msg(res.message)
								if (res.code != 0) return
								that.token = null
								uni.setStorageSync('token', null)
								uni.clearStorageSync()
								uni.reLaunch({
									url: "/pageTwo/login/login"
								})
							})
						} else if (res.cancel) {
							that.$tools.msg("您已取消操作！");
						}
					},
				})
			},
			handleLogin() {
				uni.reLaunch({
					url: "/pageTwo/login/login"
				})
			},
			//个人资料
			handleUserEdit() {
				uni.navigateTo({
					url: '/pageTwo/me/userEdit'
				})
			},
			navTo(url) {
				if (!uni.getStorageSync('token')) {
					this.$tools.msg("登录后查看等多！")
					return
				}
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		min-height: calc(100vh - 20px);
		background-color: #fff;
		padding-top: 20px;
	}

	.size22 {
		width: 100%;
		text-align: center;
		color: #fff;
	}

	.head {
		width: 100%;
		height: 5rem;
		background: $maincolor;
		display: flex;
		align-items: center;
		font-size: 16px;
		font-weight: bold;
		padding-bottom: 20px;
		margin-top: -20px;

		.left {
			width: calc(100% - 30px);
			display: flex;
			align-items: center;
		}

		image {
			width: 50px;
			height: 50px;
			margin: 0 15px;
		}
	}

	.btnlogin {
		color: #fff;
		margin: auto;
		padding: 8px 15px;
		background: $btncolor;
		border-radius: 5px;
		font-weight: 500 !important;
	}

	.list {
		width: 100%;
		background: #fff;
		margin: 15px;
		border-radius: 10px;
		line-height: 50px;
		margin-top: -20px;

		.item {
			display: flex;
			justify-content: space-between;
			margin: 0 15px;
			border-radius: 20px;
			background: #FEF9F4;
			margin-top: 15px;
			padding: 0 10px;

			view {
				width: 80%;
				display: flex;
				align-items: center;
			}

			image {
				width: 25px;
				height: 25px;
				margin-right: 10px;
			}
		}

		:nth-child(2).item {
			background-color: #F2FDEE;
		}

		:nth-child(3).item {
			background-color: #FFEEFF;
		}

		:nth-child(4).item {
			background-color: #DBF2F9;
		}

		:nth-child(5).item {
			background-color: #FFEEFF;
		}
	}

	.btn {
		width: calc(100% - 60rpx);
		margin-left: 30rpx;
		color: #fff;
		margin-bottom: 20px;
	}
</style>