<template>
	<view class="box">
		<!-- 自定义导航 -->
		<view class="zdyNavBox">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view class="zdyNav">
				<div @click="goback" class="uni-page-head-btn"><i class="uni-btn-icon"
						style="color: rgb(0, 0, 0); font-size: 27px;"></i></div>

				<view class="zdyNavTitle">车型</view>
				<view class="zdyNavRight" @click="goOemSearch">OEM搜索</view>

			</view>
		</view>

		<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
		<view style="height: 44px;"></view>

		<view class="top">{{title}}</view>

		<!-- 车型 -->
		<view v-if="carModelShow" class="cangBox">
			<view v-for="(item,index) in xingList" :key="index">
				<view class="cangTitle">{{item.fct_name}}</view>
				<view @click="goNext(item2)" class="xingBox" v-for="(item2,index) in item.models" :key="index">
					<view class="xing">{{item2.model_name}}</view>
					<image src="../../static/img/rightArrow.png" mode="" style="width: 12rpx; height: 20rpx"></image>
				</view>
			</view>
		</view>

		<!-- 年份 -->
		<view v-if="yearShow" class="cangBox">
			<view @click="goNext2(item)" class="xingBox" v-for="(item,index) in yearList">
				<view class="xing">{{item.year}}</view>
				<image src="../../static/img/rightArrow.png" mode="" style="width: 12rpx; height: 20rpx"></image>
			</view>
		</view>

		<!-- 型号 -->
		<view v-if="xinghaoShow" class="cangBox">
			<view @click="gogroup(item)" class="workBox2" v-for="(item,index) in xinghaoList" :key="index">
				<view class="leftBox">
					<view class="oneBox">
						<view class="comtent2">
							<view class="left2" style="width: 28%;">变速器：</view>
							<view class="right2">{{item.trans}}</view>
						</view>
						<view class="comtent2">
							<view class="left2">车型：</view>
							<view class="right2">{{item.model}}</view>
						</view>
					</view>

					<view class="oneBox">
						<view class="comtent2">
							<view class="left2">级别：</view>
							<view class="right2">{{item.grade}}</view>
						</view>
						<view class="comtent2">
							<view class="left2" style="width: 35%;">发动机号：</view>
							<view class="right2">{{item.engine}}</view>
						</view>
					</view>

					<view class="oneBox">
						<view class="comtent2">
							<view class="left2">装配：</view>
							<view class="right2">{{item.equip}}</view>
						</view>

					</view>


					<view class="oneBox">
						<view class="comtent2">
							<view class="left2" style="width: 35%;">模型代码：</view>
							<view class="right2">{{item.mdcode}}</view>
						</view>

					</view>

				</view>
				<image src="../../static/img/rightArrow.png" mode="" style="width: 12rpx; height: 20rpx"></image>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		
		data() {
			return {
				epc_id: '',
				title: '',
				iStatusBarHeight: '',
				searchValue: '',
				xingList: [],
				access_time: '',
				yearList: [],
				yearShow: false,
				carModelShow: false,
				xinghaoShow: false,
				xinghaoList: [],
				modelname:'',
			}
		},
		onLoad(opt) {
			console.log('opt', opt);
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.epc_id = opt.epc_id;
			this.title = opt.title;
			this.getItemData();
		},
		methods: {
			goNext(item) {
				if (item.next_restrain == 1) {
					this.title += ' > ' + item.model_name;
					this.modelname=item.model_name
					this.getYueSuData(item)
				}
			},
			goNext2(item) {
				if (item.next_restrain == 1) {
					this.title += ' > ' + item.year;
					this.getYueSuData(item)
				}
			},
			//获取车型约束列表
			getYueSuData(item) {
				let that = this
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getRestrain', {
					epc_id: this.epc_id,
					token: item.token,
					param: item.param,
					access_time: this.access_time,
					// page: this.page
				}, 'GET').then(res => {
					uni.hideLoading();
					if (res.data.result.caption == '年份') {


						that.carModelShow = false;
						that.yearShow = true;

						that.yearList = res.data.result.list;
						that.access_time = res.data.result.access_time;
					}
					if (res.data.result.next_level.caption == '总组') {

						that.title += ' > ' + res.data.result.caption;

						that.carModelShow = false;
						that.yearShow = false;
						that.xinghaoShow = true;

						that.xinghaoList = res.data.result.list;
						that.access_time = res.data.result.access_time;
					}


				});
			},
			//获取车型
			getItemData() {
				let that = this
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getModel', {
					epc_id: this.epc_id,
					// token: this.token,
					// param: this.param,
					// access_time: this.access_time,
					// page: this.page
				}, 'GET').then(res => {
					uni.hideLoading();

					if (res.data.result.caption == '车型') {
						that.xingList = res.data.result.list;
						that.access_time = res.data.result.access_time;
						that.carModelShow = true;
					}
				});
			},
			
			gogroup(item) {
				uni.navigateTo({
					url: 'group?type=2&token='+item.token+'&param='+item.param+'&access_time='+this.access_time+'&epc_id='+this.epc_id+'&modelname='+this.modelname
				})
			},

			goOemSearch() {
				uni.navigateTo({
					url: 'OemSearch'
				})
			},
			goback() {
				console.log('返回');
				this.carModelShow = true;
				this.yearShow = false;
				// uni.navigateBack({})
			},
		}
	}
</script>

<style>
	.box {
		min-height: 100vh;
		background: #ffffff;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	.zdyNavBox {
		width: 100vw;
		background: #FFFFFF;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999999;

	}

	.zdyNav {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 14rpx 6rpx;
	}


	.zdyNavTitle {
		background: #FFFFFF;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
	}

	.zdyNavRight {
		background: #FFFFFF;
		text-align: center;
		font-size: 28rpx;
		color: #3F90F7;
		width: 120rpx;
	}

	.top {
		color: #FFFFFF;
		font-size: 28rpx;
		padding: 24rpx;

		background: linear-gradient(110deg, #48B9F9 0%, #3F90F7 100%);
	}

	.cangBox {
		background: #FFFFFF;
	}

	.cangTitle {
		padding: 10rpx 24rpx;
		background: #F4F5F7;
		color: #333333;
		font-size: 28rpx;
	}

	.xingBox {
		font-size: 28rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 24rpx;
		border-bottom: 1rpx solid #eeeeee;
	}

	.oneBox {
		display: flex;
		justify-content: space-between;
		align-items: baseline;
		font-size: 26rpx;
		padding-bottom: 20rpx;
	}

	.comtent2 {
		display: flex;
		align-items: baseline;
		font-size: 26rpx;
		width: 50%;
	}

	.workBox2 {

		background: #FFFFFF;
		border-bottom: 1rpx solid #EEEEEE;
		padding: 20rpx 24rpx 0rpx;

		display: flex;
		align-items: center;
	}

	.leftBox {
		width: calc(100vw - 20rpx);
	}

	.rightBox {
		width: 20rpx;
	}

	.left2 {
		width: 20%;
		color: #999999;
		white-space: nowrap;
	}

	.right2 {
		width: 80%;
		color: #333333;
		margin-right: 20rpx;
	}
</style>
