<template>
	<view class="page__view">

		<image class="bg" src="@/pages_order/static/center/bg.png" mode="widthFix"></image>

		<view class="main">

			<navbar bgColor="transparent" >
				<image class="nav-icon" src="@/pages_order/static/center/icon-nav.png" mode="widthFix"></image>
			</navbar>

			<view class="content">
				<view class="flex user">
					<view class="user-avatar">
						<image class="user-avatar-img" src="@/pages_order/static/report/avatar.png" mode="scaleToFill"></image>
					</view>
					<view class="user-info">
						<view class="user-info-name">战斗世界</view>
						<view class="user-info-desc">世界这么美，身体要健康～</view>
					</view>
				</view>

				<report-card></report-card>
				<order-card></order-card>
				<account-card></account-card>

				<view class="card">
					<view v-for="item in list1" :key="item.id">
						<template v-if="item.key === 'service'">
							<button plain class="flex btn-service" open-type="contact">
								<view class="flex row">
									<view class="flex label">
										<image class="icon" :src="item.icon" mode="scaleToFill"></image>
										<view>{{ item.label }}</view>
									</view>
									<uv-icon name="arrow-right" color="#C6C6C6" size="24rpx"></uv-icon>
								</view>			
							</button>
						</template>
						<view v-else class="flex row" @click="onClick(item)">
							<view class="flex label">
								<image class="icon" :src="item.icon" mode="scaleToFill"></image>
								<view>{{ item.label }}</view>
							</view>
				      <uv-icon name="arrow-right" color="#C6C6C6" size="24rpx"></uv-icon>
						</view>						
					</view>
				</view>
				
				<view class="card">
					<view v-for="item in list2" :key="item.id">
						<view class="flex row" @click="onClick(item)">
							<view class="flex label">
								<image class="icon" :src="item.icon" mode="scaleToFill"></image>
								<view>{{ item.label }}</view>
							</view>
				      <uv-icon name="arrow-right" color="#C6C6C6" size="24rpx"></uv-icon>
						</view>						
					</view>
				</view>

			</view>

			<tabber select="center" />

		</view>

	</view>
</template>

<script>
	import { mapState } from 'vuex'

	import tabber from '@/components/base/tabbar.vue'
	import reportCard from '@/pages_order/center/reportCard.vue'
	import orderCard from '@/pages_order/center/orderCard.vue'
	import accountCard from '@/pages_order/center/accountCard.vue'

	export default {
		components: {
			reportCard,
			orderCard,
			accountCard,
			tabber,
		},
		data() {
			return {
				list1: [
					{ id: '001', label: '检测预约', icon: '/pages_order/static/center/icon-detectBook.png', path: '/pages_order/checkup/checkupRecords' },
					{ id: '002', label: '联系客服', icon: '/pages_order/static/center/icon-service.png', key: 'service' },
					// todo: check key
					{ id: '003', label: '服用说明', icon: '/pages_order/static/center/icon-instruc.png', path: `/pages_order/common?key=instruc&title=服用说明` },
					// todo: check key
					{ id: '004', label: '用户须知', icon: '/pages_order/static/center/icon-userAgreement.png', path: `/pages_order/common?key=userAgreement&title=用户须知` },
				],
				list2: [
					{ id: '005', label: '我的评价', icon: '/pages_order/static/center/icon-comment.png', key: 'comment' },
					// todo: check key
					{ id: '006', label: '关于我们', icon: '/pages_order/static/center/icon-aboutUs.png', path: `/pages_order/common?key=aboutUs&title=关于我们` },
					{ id: '007', label: '修改信息', icon: '/pages_order/static/center/icon-modifyInfo.png', path: `/pages_order/auth/wxUserInfo?mode=edit` },
					{ id: '008', label: '退出登录', icon: '/pages_order/static/center/icon-logout.png', key: 'logout' },
				],
			}
		},
		computed: {
			...mapState(['userInfo']),
		},
		methods: {
			onClick(target) {
				const { key, path } = target

				switch(key) {
					case 'comment':
          	this.$utils.navigateTo(`/pages_order/comment/commentRecords?creator=${this.userInfo.id}`)
						break
					case 'logout':
						this.$store.commit('logout')
						break
					default:
						path && this.$utils.navigateTo(path)
						break
				}
			},
		},
	}
</script>

<style scoped lang="scss">

	.page__view {
		width: 100vw;
		min-height: 100vh;
		background-color: $uni-bg-color;
		position: relative;

    /deep/ .nav-bar__view {
      position: fixed;
      top: 0;
      left: 0;
    }

		.nav-icon {
			width: 200rpx;
			height: auto;
			vertical-align: top;
		}

	}

	.bg {
		width: 100vw;
		height: auto;
	}

	.main {
		position: absolute;
		top: 176rpx;
		left: 0;
		width: 100%;
	}

	.content {
		width: 100%;
		padding: 16rpx 32rpx 80rpx 32rpx;
		box-sizing: border-box;
	}

	.user {
		column-gap: 24rpx;

		&-avatar {
			flex: none;
			width: 100rpx;
			height: 100rpx;
			border: 4rpx solid #FFFFFF;
			border-radius: 50%;
			overflow: hidden;

			&-img {
				width: 100%;
				height: 100%;
			}
		}

		&-info {
			flex: 1;

			&-name {
				font-family: PingFang SC;
				font-weight: 600;
				font-size: 36rpx;
				line-height: 1.2;
				color: #FFFFFF;
			}

			&-desc {
				margin-top: 8rpx;
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				line-height: 1.5;
				color: #F4F4F4;
			}
		}
	}
	
	.card {
		margin-top: 32rpx;
		width: 100%;
		background: #FAFAFF;
		border: 2rpx solid #FFFFFF;
		border-radius: 32rpx;
    box-sizing: border-box;

		.row {
			justify-content: space-between;
			width: 100%;
			padding: 40rpx;
			box-sizing: border-box;

			.label {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				line-height: 1;
				color: #252545;

				.icon {
					margin-right: 16rpx;
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}

	.btn-service {
		border: none;
		padding: 0;
	}
</style>