<template>
	<view class="main">
		<view class="one">
			<view class="one_1">
				<view v-if="user._id" class="top">
					<image class="image" :src="user.logo&&user.logo.length>0?user.logo[0].url:'../../static/my.png'"
						mode=""></image>
					<text>{{user.nick_name||'微信用户'}}</text>
				</view>
				<view v-else class="top" @tap="toLogin">
					<text class="iconfont icon-yonghu"></text>
					<text>登录/注册</text>
				</view>
			</view>
			<view class="one_2">
				<view class="bottom">
					<view class="list" v-for="(item,index) in list" :key="index" @tap="toLike(item)">
						<text>{{item.num}}</text>
						<text>{{item.title}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="two">
			<view class="two_1">
				<view class="left">我的订单</view>
				<view class="right" @tap="toCommon(`pagesMy/order/index`)">查看全部订单 <text
						class="iconfont icon-dayuhao"></text></view>
			</view>
			<view class="two_2">
				<view class="list" v-for="(item,index) in orderList" :key="index" @tap="toRoute(item)">
					<uni-badge :text="item.num" absolute="rightTop" size="normal">
						<view class="icon">
							<text class="iconfont" :class="[item.icon]"></text>
						</view>
						<text class="title">{{item.title}}</text>
					</uni-badge>
				</view>
			</view>
		</view>
		<view class="thr">
			<view class="list" v-for="(item, index) in menuList" :key="index" @click="toCommon(item.route)">
				<view class="left">
					<view class="icon">
						<text class="iconfont" :class="[item.icon]"></text>
					</view>
					<text class="title">{{item.title}}</text>
				</view>
				<view class="right">
					<text class="iconfont icon-dayuhao"></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				// 获赞数
				list: [],
				// 订单图标菜单
				orderList: [],
				// 菜单
				menuList: []
			}
		},
		onLoad: async function() {
			const that = this;
			await that.searchOther();
		},
		onShow: async function(e) {
			const that = this;
			that.searchToken();
			await that.search();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) that.$set(that, `user`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			// 查询
			async search() {
				const that = this;
				let res;
				res = await that.$api(`/user/statistics`, 'GET', {
					user: that.user._id
				})
				if (res.errcode == '0') {
					that.$set(that, `list`, res.data)
				} else {
					uni.showToast({
						title: res.errmsg,
					});
				}
			},
			// 登录或注册
			async toLogin() {
				uni.navigateTo({
					url: `/pagesIndex/login/index`
				})
			},
			// 点赞或收藏
			toLike(item) {
				const that = this;
				if (that.user && that.user._id) {
					if (item.type == '2') {
						uni.navigateTo({
							url: `/${item.route}`
						})
					} else {
						uni.navigateTo({
							url: `/${item.route}?type=${item.type}`
						})
					}
				} else {
					uni.navigateTo({
						url: `/pagesIndex/login/index`
					})
				}
			},
			// 订单或维修跳转
			toRoute(item) {
				const that = this;
				if (that.user && that.user._id) {
					uni.navigateTo({
						url: `/${item.route}?status=${item.status}`
					})
				} else {
					uni.navigateTo({
						url: `/pagesIndex/login/index`
					})
				}
			},
			// 公共跳转
			toCommon(e) {
				const that = this;
				if (that.user && that.user._id) {
					uni.navigateTo({
						url: `/${e}`
					})
				} else {
					uni.navigateTo({
						url: `/pagesIndex/login/index`
					})
				}
			},
			async searchOther() {
				const that = this;
				let config = that.$config;
				that.$set(that, `orderList`, config.orderList);
				that.$set(that, `menuList`, config.menuList);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;
		background-color: var(--footColor);

		.one {
			background-image: linear-gradient(181.2deg, #FEFEFE 10.5%, #87CEFA 86.8%);
			height: 45vw;

			.one_1 {
				padding: 4vw;

				.top {
					display: flex;
					align-items: center;
					font-size: var(--font18Szie);

					.image {
						width: 15vw;
						height: 15vw;
						border-radius: 15vw;
						margin: 0 2vw;
					}

					.iconfont {
						font-size: 40px;
						color: var(--f85Color);
						padding: 2vw;
					}
				}
			}

			.one_2 {
				padding: 5vw;

				.bottom {
					display: flex;
					justify-content: space-around;

					.list {
						display: flex;
						flex-direction: column;
						align-items: center;
					}
				}
			}
		}

		.two {
			display: flex;
			flex-direction: column;
			padding: 2vw;
			margin: 2vw;
			border-radius: 10px;
			background-color: var(--mainColor);

			.two_1 {
				display: flex;
				justify-content: space-between;
				padding: 2vw;
				border-bottom: 1px solid var(--f9Color);

				.left {
					font-weight: 600;
					font-size: var(--font14Size);
				}

				.right {
					display: flex;
					align-items: center;
					font-size: var(--font12Size);
					color: var(--f99Color);
				}
			}

			.two_2 {
				display: flex;
				justify-content: space-between;
				padding: 3vw 4vw;

				.list {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					text-align: center;

					.icon {
						.iconfont {
							font-size: 25px;
						}
					}

					.title {
						display: inline-block;
						margin: 1vw 0 0 0;
						font-size: var(--font12Size);
					}
				}
			}
		}

		.thr {
			display: flex;
			flex-direction: column;
			padding: 2vw;
			margin: 0 2vw;
			border-radius: 10px;
			background-color: var(--mainColor);

			.list {
				display: flex;
				justify-content: space-between;
				padding: 2vw;
				border-bottom: 1px solid var(--f9Color);

				.left {
					display: flex;
					align-items: center;
					font-size: var(--font12Size);

					.icon {
						padding: 0 1vw 0 0;

						.iconfont {
							color: var(--f3CColor);
							font-size: var(--font18Szie);
						}
					}

					.title {
						display: inline-block;
						font-size: var(--font12Size);
					}
				}

				.right {
					display: flex;
					align-items: center;
					font-size: var(--font12Size);
					color: var(--f99Color);
				}
			}
		}
	}
</style>