<template>
	<div class="website-home">
		<div class="banner">
			<el-carousel :interval="5000" arrow="always" height="100%">
				<el-carousel-item>
					<img class="banner-img"
						src="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/1eeba102483945589db9fa134581c19c"
						alt="" />
				</el-carousel-item>
				<el-carousel-item>
					<img class="banner-img"
						src="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/e5a861ad85284564ad3fca7783dfbdfd"
						alt="" />
				</el-carousel-item>
				<el-carousel-item>
					<img class="banner-img"
						src="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/fbcd3f73ece94cde94f768428d164a9f"
						alt="" />
				</el-carousel-item>
				<el-carousel-item>
					<img class="banner-img"
						src="https://file-node.oss-cn-shanghai.aliyuncs.com/youji/29a9a76dd14942198a28851cfe920061"
						alt="" />
				</el-carousel-item>
			</el-carousel>
		</div>
		<!-- <div class="website-home-bg"></div> -->
		<div class="container">
			<!-- <div class="main-container">
				<div class="main-title">WORKARK-寻找合适的服务</div>
				<div class="main-sub-title">方便、快捷、精准</div>
			</div> -->
			<div class="product-box">
				<div class="product-iview" v-for="item in list" :key="item.id" :id="`list${item.id}`">
					<div class="title">{{item.name}}</div>
					<div class="product-list">
						<product-item v-for="(node,index) in item.children" :key="index" :item="node" :parent="item">
						</product-item>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	const productItem = () => import('@/components/website/productItem');
	import {
		getServeProductList
	} from '@/api/system'
	export default {
		name: 'index',
		data() {
			return {
				list: [],
				scrollPosition: 0 // 保存滚动条位置
			}
		},
		mounted() {
			this.init();
		},
		activated() {
			// 组件被激活时调用
			if (document.getElementsByClassName('website-layout')) {
				document.getElementsByClassName('website-layout')[0].scrollTo(0, this.scrollPosition);
			}
		},
		beforeRouteLeave(to, from, next) {
			if (document.getElementsByClassName('website-layout')) {
				this.scrollPosition = document.getElementsByClassName('website-layout')[0].scrollTop;
			}
			next();
		},
		deactivated() {
			// 组件被停用时调用

		},
		methods: {
			init() {
				getServeProductList(-1).then(res => {
					if (res.state) {
						this.list = res.data;
						let navList = JSON.parse(JSON.stringify(res.data));
						// navList.push({
						// 	name: '产品介绍',
						// 	id: -1
						// })
						this.$emit('navFunc', navList);
					}
				})
			},
			screenTo(item) {
				if (!document.getElementById('list' + item.id)) return;
				let top = document.getElementById('list' + item.id).offsetTop;
				if (document.getElementsByClassName('website-layout')) {
					document.getElementsByClassName('website-layout')[0].scrollTo({
						top: top - 40, // 纵坐标位置
						left: 0, // 横坐标位置
						behavior: 'smooth' // 平滑滚动效果
					});
				}
			}
		},
		components: {
			productItem
		}
	}
</script>

<style lang="scss">
	.website-home {
		position: relative;

		.container {
			width: 1200px;
			margin: 0 auto;
		}

		.website-home-bg {
			width: 100%;
			min-width: 1200px;
			height: 600px;
			background: url(https://file-node.oss-cn-shanghai.aliyuncs.com/youji/5ea8dc9317c643d0b0254d8d13a154f3);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.el-carousel {
			height: 100%;
		}

		.banner {
			width: 100%;
			height: 600px;
			background: #eee;
		}

		.banner-img {
			object-fit: cover;
			width: 100%;
			height: 100%;
		}

		.main-container {
			height: 600px;
			color: #fff;
			padding-top: 80px;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			justify-content: center;
			position: relative;
			z-index: 8;

			.main-title {
				font-weight: 500;
				font-size: 30px;
				line-height: 50px;
				margin-bottom: 12px;
			}

			.main-sub-title {
				font-weight: 300;
				font-size: 20px;
				line-height: 28px;
				opacity: .7;
				margin-bottom: 50px;
			}
		}

		.product-box {
			margin-top: 80px;
			padding-bottom: 200px;

			.title {
				font-size: 36px;
				line-height: 50px;
				font-weight: 600;
				margin-bottom: 30px;
			}
		}

		.product-list {
			display: flex;
			flex-wrap: wrap;
		}

		.product-iview {
			margin-bottom: 30px;
		}
	}
</style>