<template>
	<view>
		<view class="list" v-for="(item,index) in displacementList" :key="index">
			<view class="list__item" @click="choice(item,index)">
				<text class="list__item__user-name">{{item.modelYear}}</text>
			</view>
			<u-line></u-line>
		</view>
		<u-popup :show="annualStyle" @close="annualStyle = false" mode="right" :closeable="true">
			<view style="padding-top: 10rpx;width: 650rpx;">
				<swiper class="box-c" style="height: 100vh;">
					<swiper-item class="child">
						<scroll-view :scroll-y="true">
							<view class="list" v-for="(item,index) in annualStyleList" :key="index">
								<view class="list__item" @click="vehicleSeriesClick(item)">
									<text class="list__item__user-name">{{item.modelName}}</text>
								</view>
								<u-line></u-line>
							</view>
						</scroll-view>
					</swiper-item>
				</swiper>
			</view>
		</u-popup>
		<view style="position: absolute;top: 45%;left: 50%;transform:translate(-50%,-50%)">
			<u-empty v-if="displacementList.length == 0" mode="list">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import {
		seriesList,
		brandList
	} from '@/api/views/vehicle/brand.js'
	export default {
		data() {
			return {
				displacementList: [],
				annualStyle: false,
				annualStyleList: [],
				params:{}
			}
		},
		onLoad(params) {
			this.params = {
				...params
			}
			uni.showLoading({
				title: '查询年款中',
				mask: true
			});
			seriesList(this.params).then(res => {
				this.displacementList = res.data
				uni.hideLoading();
				// this.annualStyle = true
			})
			// seriesList(this.params).then(res => {
			// 	this.displacementList = res.data
			// })
		},
		methods: {
			choice(item, index) {
				this.form = item
				uni.showLoading({
					title: '查询车型中',
					mask: true
				});
				seriesList({
					brandId: item.brandId,
					seriesId: item.seriesId,
					modelYear:item.modelYear
				}).then(res => {
					console.log(res)
					this.annualStyleList = res.data
					uni.hideLoading();
					this.annualStyle = true
				})
			},
			vehicleSeriesClick(item) {
				uni.$u.route('/pages/views/vehicle/autoParts', {
					brand:item.brandName,
					seriesName:item.seriesName,
					brandId:item.brandId,
					seriesId:item.seriesId,
					engine:item.engine,
					modelYear:item.modelYear,
					modelName:item.modelName,
					id:item.id
				});
			}
		}
	}
</script>

<style lang="scss">
	.box-c,
	.child {
		display: flex;
		flex: 1;
	}

	.list {

		&__item {
			@include flex;
			padding: 6px 12px;
			align-items: center;
			justify-content: space-between;

			&__user-name {
				font-size: 32rpx;
				color: $u-main-color;
			}

			&__user-tel {
				font-size: 32rpx;
				margin-right: 20rpx;
				color: $u-main-color;
			}
		}

		&__footer {
			color: $u-tips-color;
			font-size: 14px;
			text-align: center;
			margin: 15px 0;
		}
	}
</style>
