<template>
	<view class="box">
		<!-- 自定义导航 -->
		<view class="zdyNavBox">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view class="zdyNav">
				<view class="zdyNavLeft">
					<!-- <div @click="goback" class="uni-page-head-btn"><i class="uni-btn-icon"
							style="color: rgb(0, 0, 0); font-size: 27px;"></i></div> -->
					<div class="gobackBox" @click="goback">
						<image src="/static/img/goback.png" mode="" class="gobackImg"></image>
					</div>
					<div class="goHomeBox" @click="goHome">
						<image src="/static/img/home.png" mode="" class="goHomeImg"></image>
					</div>		
					
				</view>
				<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="$noMultipleClicks(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="peizhiShow" class="cangBox">
			<view @click="goNext2(item)" class="xingBox" v-for="(item,index) in peizhiList">
				<view class="xing">{{item.combine_cp}}</view>
				<image src="../../static/img/rightArrow.png" mode="" style="width: 12rpx; height: 20rpx"></image>
			</view>
		</view>
		

	</view>
</template>

<script>
	import { getHashQuery } from '../../utils/index.js'
	export default {
		
		data() {
			return {
				epc_id: '',
				brand_name:'',
				title: '',
				iStatusBarHeight: '',
				access_time: '',
				token:'',
				param:'',
				carModelShow:false,
				peizhiShow:false,
				xingList: [],
				peizhiList:[],
				modelname:'',
				noClick:true,
			    carName:'',
			}
		},
		onLoad(opt) {
			console.log('opt', opt);
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.epc_id = opt.epc_id;
			this.brand_name = opt.brand_name;
			this.title = opt.brand_name;
			this.modelname = opt.brand_name;
            this.brand_id = opt.brand_id;
			this.imageicon = opt.imageicon
			this.getItemData();
			
		},
		methods: {
			goNext(item) {
				this.token = item.token;
				this.param = item.param;
				
				
				if (item.next_restrain == 1) {
					this.title += ' > ' + item.model_name;
					this.modelname += ' ' + item.model_name;
					this.carName=this.modelname
					this.getYueSuData(item)
				}
				else{
					this.gogroup(item);
				}
			},
			goNext2(item) {
				this.token = item.token;
				this.param = item.param;
				this.modelname += ' ' + item.combine_cp;
				
                if(!this.modelname.includes(item.combine_cp)){
					this.modelname += ' ' + item.combine_cp;
				}
				if (item.next_restrain == 1) {
					this.title += ' > ' + item.combine_cp;
					this.getYueSuData(item)
				}
				else{
					this.gogroup(item);
				}
			},
			//获取车型约束列表
			getYueSuData(item) {
				
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getRestrain', {
					epc_id: this.epc_id,
					token: this.token,
					param: this.param,
					access_time: this.access_time,
					
				}, 'GET').then(res => {
					uni.hideLoading();

						this.carModelShow = false;
						this.peizhiShow = true;

						this.peizhiList = res.data.result.list;
						this.access_time = res.data.result.access_time;
					

				});
			},
			//获取车型
			getItemData() {
				
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getModel', {
					epc_id: this.epc_id,
					
				}, 'GET').then(res => {
					uni.hideLoading();
					
					
						this.xingList = res.data.result.list;
						this.access_time = res.data.result.access_time;
						this.carModelShow = true;
						this.token = res.data.result.list[0].models[0].token;
						this.param = res.data.result.list[0].models[0].param;
					
				});
			},
			
			gogroup(item) {
				console.log(item)
				var json={
					brand: this.brand_name,
					epc_id:this.epc_id,
					param:item.param,
					token:item.token,
					access_time:this.access_time,
					modelname:this.modelname,
					carName:this.carName,
					brand_id:this.brand_id,
				}
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/cachekey', {
					value: JSON.stringify(json),
					
				}, 'GET').then(res => {
					uni.hideLoading();
					console.log(res.data)
					uni.setStorageSync('cachekey',res.data ) 
					uni.navigateTo({
						url: 'group?type=2&cart='+item.token+'&param='+item.param+'&access_time='+this.access_time
						+'&epc_id='+this.epc_id+'&modelname='+this.modelname+'&brand_id='+this.brand_id+'&imageicon='+this.imageicon
						+"&caption="+item.caption
					}) 
				});
				/*  */
			},

			goOemSearch() {
				
				
				uni.navigateTo({
					url: 'OemSearch?brand=' + this.brand_name + '&epc_id=' + this.epc_id + '&param=' + this.param +
						'&token=' + this.token + '&access_time=' + this.access_time
				}) 
				
			},
			goback() {
				console.log('返回');
				uni.navigateBack({})
				
			},
			goHome(){
				var token= uni.getStorageSync("token")
				/* var encodedToken= uni.getStorageSync("encodedToken")
				var token =  decodeURIComponent(encodedToken) */
				//var token=getHashQuery('token')
				var url = 'http://byweb.66km.cn/#/home?token='+token
				//window.history.back()
				window.location.href =url
			}
		}
	}
</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;
	}
	.zdyNavLeft{
		width: 120rpx;
		display: flex;
	}
	.goHomeBox{
		padding-left: 20rpx;
		padding-top: 4rpx;
	}
	
    .goHomeImg{
		width: 22px;
		height: 22px;
		
	}
	.gobackBox{
		padding-left: 20rpx;
		padding-top: 6rpx;
	}
	.gobackImg{
		width: 10px;
		height: 20px;
		padding-right: 20rpx;
	}
	.zdyNavTitle {
		background: #FFFFFF;
		text-align: center;
		/* font-size: 32rpx; */
		font-weight: bold;
		font-size: 18px!important;
		color: #333333!important;
	}

	.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%); */
		background-color: #1777FF ; 
	
	}

	.cangBox {
		background: #FFFFFF;
	}

	.cangTitle {
		padding: 10rpx 24rpx;
		background: #F4F5F7;
		color: #333333;
		font-size: 28rpx;
		text-align: center;
		font-weight: bold;
	}

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

	
</style>
