<template>
	<view class="content">

		<!-- 自定义导航 -->
		<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: #333333; font-size: 27px;" ></i></div>

				</view>
				<view class="xx" style="margin-left: -70rpx;" @click="goToSelectCarModel">
					<image src="/static/img/group2.png" style="width: 27rpx;height: 27rpx;"></image>
				</view>
				<view class="tab-box2" v-if="type!=2">车型件</view>
				
				<view class="tab-box" v-if="type==2">
					<span class="tab-box-title jian" :class="{clickbu:clickType==1}" @click="clickbu(1)">简易版</span>
					<span class="tab-box-title zhuan" :class="{clickbu:clickType==2}" @click="clickbu(2)">专业版</span>
				</view>
				
				<view v-if="param.length != 0 " class="zdyNavRight"></view>
				<view v-else style="width: 120rpx;"></view>

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


		<!-- <view v-if="type != 2" class="top">
			<view class="topCont">
				<view class="carBox">
					<view class="carTxt" v-if="!description">{{brand_name}}</view>
					<view class="carTxt" v-if="description">{{description}}</view>
				</view>
				<view class="vinBox">
					<view class="vinBox2">
						<view class="vinB">VIN</view>
						<view class="vinNum">{{vin}}</view>
					</view>
					<view v-if="chexingMesList.length != 0" class="vinBox2">
						<view class="vindetail" @click="goCarDetail()">车型详情</view>
						<image src="../../static/img/icon_arrow_blue_r@2x.png" mode=""
							style="width: 24rpx; height: 24rpx"></image>
					</view>
				</view>
			</view>
		</view> -->
		<!-- <view class="top" v-if="type !=2">
			
			<view class="carBox2">
				<view class="carTxt2" v-if="!description">{{brand_name}}</view>
				<view class="carTxt2" v-if="description">{{description}}</view>
			</view>

		</view> -->
		<view class="top" >
			
				<!-- <view class="carBox2">
					<view class="carTxt2" v-if="!description">{{brand_name}}</view>
					<view class="carTxt2" v-if="description">{{description}}</view>
				</view> -->
				<view class="head-box">
					<view class="searchBtn" @click="goOemSearch()">
						<image src="../../static/img/icon_search.png" class="searchImg"></image>
						<view class="searchTitle">搜索配件名称/OE号</view>
					</view>
					<view class="cardDetail" :class="{novin: vin ==undefined || vin=='undefined' || vin =='' }">
						<view class="image-box" v-if="vin ==undefined || vin=='undefined' || vin ==''">
							<image :src="imageicon" style="width: 78rpx;height: 78rpx;"></image>
						</view>
						<view class="detail" :class="{detailNoVin: vin ==undefined || vin=='undefined' || vin =='' }">
							<view class="code" v-if="vin !=undefined" >
								<view>{{vin}}</view>
							</view>
							<view class="head-this-title" >{{description}}</view>
						</view>
					</view>
				</view>
		</view>
		<!--车辆配置  -->
		<view class="mainBox" v-if="restrainShow">
			<view class="maintitle">{{caption}}</view>
			<view class="mainLine" v-for="(item,index) in restrains" @click="restrainsClick(item)">
				<view class="lineName">{{item.combine_cp?item.combine_cp:item.catalog_name}}</view>
                <view class="lineName" v-if="vin">{{item.combine_cp?item.combine_cp:item.model_name}}</view>
				<view class="lineName" v-else>{{item.car_name}}</view> 
				<image src="../../static/img/jt.png" mode="" class="mainLineJt"></image>
			</view>
		</view>
		<!-- 总组 -->
		
		<view class="mainBox" :style="{background: type==2 ? '#F4F5F7' : ''}" v-if="groupShow">
			<view class="mainBoxChildJian" v-if="type == 2 && clickType==1">
				<!-- 简版 -->
				<view class="childTitle">选择分类</view>
				<view class="jianShowContent">
					<view class="jianChildbox" v-for="item in groupList" @click="toDetail(item)">
						<view class="childBoxImage">
							<image :src="item.image" mode="aspectFit" style="width: 230rpx;height: 300rpx;"></image>
						</view>
						<view class="childBoxTitle">
							{{item.title}}
						</view>
					</view>
				</view>
				
			</view>
			<view class="mainBoxChildZhuan" style="margin-top: 20rpx;" v-if="clickType==2 || type != 2">
				<!-- 专业版 -->
				<view class="maintitle">{{caption}}</view>
				<view class="mainLine" v-for="(item,index) in zlist" @click="goTwo(item)">
					<view class="lineName">{{item.caption}}</view>
					<image src="../../static/img/jt.png" mode="" class="mainLineJt"></image>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import { getHashQuery } from '../../utils/index.js'
	export default {
		data() {
			return {
				vin: '',
				iStatusBarHeight: '',
				restrains: '',
				zlist: '',
				brand_name: '',
				brand_id: '',
				access_time: '',
				zzTime: '',
				caption: '',
				restrainShow: false,
				groupShow: false,
				param: '',
				token: '',
				epc_id: '',
				chexingMesList: [],
				chexing: '',
				description: '',
				type: '',
				clickType:1,
				brand_id:'',
				groupList:[],
				imageicon:'',
				captionOld:'', //名称
			}
		},
		onLoad(opt) {
			
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.vin = opt.vin;
			this.type = 2;
			if (opt.type == 2 && (this.vin == undefined || this.vin=='')) {
				
				this.token = opt.cart;
				this.param = opt.param;
				this.access_time = opt.access_time;
				this.epc_id = opt.epc_id;
				this.description = opt.modelname;
				this.brand_id = opt.brand_id;
				this.imageicon = opt.imageicon;
				this.captionOld = opt.caption;
				//车型点选
				this.getModelGroup()
				this.getDataByBtnType()
			} else {
				var token=getHashQuery('token')
				uni.setStorageSync('token',token) 
				uni.removeStorageSync("cachekey")
				this.description = opt.modelname;
				this.vin = opt.vin
				this.getData()
			}

		},
		methods: {
			getModelGroup() {
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getModelGroup', {
					token: this.token,
					param: this.param,
					epc_id: this.epc_id,
					access_time: this.access_time
				}, 'GET').then(res => {
					uni.hideLoading();
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						this.brand_name = res.data.result.brand_name;
						this.brand_id = res.data.result.brand_id;
						this.access_time = res.data.result.access_time;
						this.caption = res.data.result.caption
						this.epc_id = res.data.result.epc_id;

						if (res.data.result.restrains.length > 0) {
							this.restrains = res.data.result.restrains;
							this.restrainShow = true;

						} else {
							this.zzTime = res.data.result.access_time;
							this.zlist = res.data.result.list;
							this.restrainShow = false;
							this.groupShow = true;
							this.token = res.data.result.list[0].token;
							this.param = res.data.result.list[0].param;
							if (res.data.result.vehicle.description) {
								this.description = res.data.result.vehicle.description
							}
						}
						if (Object.keys(res.data.result.vehicle).length != 0) {
							this.chexingMesList = res.data.result.vehicle.tree;
							this.chexing = res.data.result.vehicle.description;
						}
					} else {

						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}

				});
			},
			getData() {
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getVinGroup', {
					vin: this.vin,

				}, 'GET').then(res => {
					uni.hideLoading();
					
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						
						this.brand_name = res.data.result.brand_name;
						this.brand_id = res.data.result.brand_id;
						this.access_time = res.data.result.access_time;
						this.caption = res.data.result.caption
						this.epc_id = res.data.result.epc_id;

						if (res.data.result.restrains.length > 0) {
							this.restrains = res.data.result.restrains;
							this.restrainShow = true;
                           
						} else {
							console.log("res.data.result.list.length=="+res.data.result.list.length)
							if(res.data.result.list.length==0){
								uni.showModal({
									title: '提示',
									content: '暂无数据,请去点选车型',
									showCancel:false,
									success: function (res) {
										if (res.confirm) {
											uni.navigateTo({
												url:'SelectCarModel'
											})
										} 
									}
								});
								return false
							}
							this.zzTime = res.data.result.access_time;
							this.zlist = res.data.result.list;
							this.restrainShow = false;
							this.groupShow = true;
							this.token = res.data.result.list[0].token;
							this.param = res.data.result.list[0].param;
							if (res.data.result.vehicle.description) {
								this.description = res.data.result.vehicle.description
							}
						}
						if(res.data.number == 200 || res.data.number == 5212){
							let data = res.data.result;
							this.brand_name = data.brand_name;
							this.brand_id = data.brand_id;
							this.epc_id = data.epc_id;
							if(this.token){
								this.getModelGroup()
								this.getDataByBtnType()
							}else{
								//没有简版
								this.type = 1;
								this.clickType = 2;
							}
							
						}
						if (Object.keys(res.data.result.vehicle).length != 0) {
							this.chexingMesList = res.data.result.vehicle.tree;
							this.chexing = res.data.result.vehicle.description;
						}
					} else {

						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}

				});
			},
			restrainsClick(item) {
				this.param = item.param;
				this.token = item.token;

				this.getcarVinGroup()
			},

			getcarVinGroup() {
				uni.showLoading({
					title: '加载中'
				});
				this.$http('advancedEpc/getVinGroup', {
					vin: this.vin,
					access_time: this.access_time,
					param: this.param,
					token: this.token
				}, 'GET').then(res => {
					uni.hideLoading();
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						this.brand_name = res.data.result.brand_name;
						this.access_time = res.data.result.access_time;
						this.caption = res.data.result.caption
						if (res.data.result.restrains.length > 0) {
							this.restrains = res.data.result.restrains;
							this.restrainShow = true;
							this.token = res.data.result.restrains[0].token;
							this.param = res.data.result.restrains[0].param;
						} else {
							
							this.token = res.data.result.list[0].token;
							this.param = res.data.result.list[0].param;
							this.zzTime = res.data.result.access_time;
							this.zlist = res.data.result.list;
							this.restrainShow = false;
							this.groupShow = true;
							if (res.data.result.vehicle.description) {
								this.description = res.data.result.vehicle.description
							}
						}

						if (Object.keys(res.data.result.vehicle).length != 0) {
							this.chexingMesList = res.data.result.vehicle.tree;
							this.chexing = res.data.result.vehicle.description;
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}

				});
			},
			goCarDetail() {
				var that = this;
				uni.setStorage({
					key: 'chexing',
					data: that.chexing,
					success: function() {

						uni.setStorage({
							key: 'chexingMesList',
							data: that.chexingMesList,
							success: function() {
								uni.navigateTo({
									url: 'CarDetail'
								})
							}
						});
					}
				});


			},
			goOemSearch() {
				uni.navigateTo({
					url: 'OemSearch?brand=' + this.brand_name + '&epc_id=' + this.epc_id + '&vin=' + this.vin +
						'&param=' + this.param +
						'&token=' + this.token + '&access_time=' + this.access_time
				})
			},
			goback() {
				uni.navigateBack({})
				//判断返回
				// let vin = this.vin;
				// if(vin ==undefined || vin =='' || vin == 'undefined' ){
				// 	uni.navigateTo({url:'SelectCarModel'});
				// }else{
				// 	uni.navigateTo({url:'index'});
				// }
			},
			goHome(){
				var token= uni.getStorageSync("token")
				console.log(token)
				if(!token){
					var token=getHashQuery('token')
				}
			    var cachekey= uni.getStorageSync("cachekey")
				if(this.vin){
					var url = 'http://byweb.66km.cn/#/home?token='+token//+'&cachekey='+cachekey
				}else{
					var url = 'http://byweb.66km.cn/#/home?token='+token+'&cachekey='+cachekey
				}
				
				window.location.href =url 
			 },
			//返回选品牌
			goToSelectCarModel(){
				/* let vin = this.vin;
				if(vin ==undefined || vin =='' || vin == 'undefined' ){
					uni.navigateTo({url:'SelectCarModel'});
				}else{
					uni.navigateTo({url:'index'});
				} */
				this.goHome()
			},
			goTwo(item) {
				var that = this;
				uni.setStorage({
					key: 'chexing',
					data: that.chexing,
					success: function() {
						
						uni.setStorage({
							key: 'chexingMesList',
							data: that.chexingMesList,
							success: function() {
								uni.navigateTo({
									url: 'modelTwo?vin=' + that.vin + '&zzTime=' + that
										.zzTime + '&param=' + item.param +
										'&token=' + item.token + '&epc_id=' + that.epc_id +
										'&description=' + that.description + '&type=' + that.type+"&image="+that.imageicon
								})
							}
						});
					}
				});

			},
			clickbu(type){
				this.clickType = type;
			},
			/**
			 * 查询简版数据
			 */
			getDataByBtnType(){
				uni.showLoading({
					title: '加载中'
				});
				this.$http('simpleEpc/getAllCata', {
					token: this.token,
					param: this.param,
					epc_id: this.epc_id,
					access_time: this.access_time,
					brand_id: this.brand_id,
				}, 'GET').then(res => {
					uni.hideLoading();
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						//查询成功
						this.groupList = res.data.result.list;
						let size = Object.keys(res.data.result.list).length;
						if(size == 0){
							//没有简版
							this.type = 1;
							this.clickType = 2;
							
						}
						
					} else {
				
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}
				
				});
			},
			toDetail(item){
				uni.removeStorageSync('epcChildren');
				uni.removeStorageSync('epcAllChildren');
				uni.setStorageSync('epcChildren', item); 
				uni.setStorageSync('epcAllChildren', this.groupList); 
				
				uni.navigateTo({
					url: 'epcSimpleDetailOne?type=2&token='+this.token+'&param='+this.param+'&access_time='+this.access_time+'&epc_id='
					+this.epc_id+'&brand_id='+this.brand_id+"&brand_name="+this.brand_name+"&caption="+this.captionOld+"&vin="+this.vin
					+"&imageicon="+this.imageicon+"&modelname="+this.description
					
				})
			}
		}
	}
</script>

<style scoped>
	.content {
		background: #ffffff;
		min-height: 100vh;
		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;
	}

	.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 {
		padding: 20rpx 0;
		background-color: #ffffff;
		margin-bottom: 10rpx;
	}

	.topCont {
		width: 750rpx;
		height: 160rpx;
		background: #FFFFFF;

	}

	.carLogo {
		width: 72rpx;
		height: 72rpx;
	}

	.carTxt {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 36rpx;
		width: 606rpx;

	}

	

	.carJt {
		width: 25rpx;
		height: 24rpx;
		margin-top: 6rpx;
	}

	.carBox {
		display: flex;
		justify-content: space-between;
		padding: 30rpx 24rpx 24rpx 34rpx;
	}
	.carBox2{
		background-color: #FFFFFF;
		padding: 30rpx 24rpx;
	}
	.carTxt2 {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 36rpx;
		/* width: 606rpx; */
		height: 75rpx;
		/* 隐藏文字显示 ...超过2行省略 */
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}
	.vinBox {
		display: flex;
		justify-content: space-between;
		padding-left: 34rpx;
		padding-right: 24rpx;
	}

	.vinBox2 {
		display: flex;
		align-items: center;
	}

	.vindetail {
		color: #3F90F7;
		font-size: 24rpx;
		margin-right: 10rpx;
	}
	
	.cardDetail{
		display: flex;
		flex-direction: row;
		
		width: 100%;
		height: 78rpx;
		margin: 20rpx 0;
	}
	.image-box{
		background-color: #ffffff;
		width: 80rpx;
		height: 80rpx;
		border-radius: 80rpx;
	}
	
	.detail{
		color: #333333;
		width: 500rpx;
		height: 78rpx;
		font-size: 28rpx;
		margin: 20rpx 10rpx;
			
	}
	.detailNoVin{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.head-title{
		height: 24rpx;
	}
	.head-this-title{
		font-size: 28rpx;
		
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2; /* 控制显示的行数 */
		overflow: hidden;
		text-overflow: ellipsis;

	}
	.novin{
		align-items: center;
	}

	.vinB {
		background: #F19D01;
		width: 60rpx;
		height: 30rpx;
		text-align: center;
		line-height: 30rpx;
		color: #FFFFFF;
		font-size: 22rpx;
		border-radius: 5rpx;
	}

	.vinNum {
		color: #999999;
		font-size: 24rpx;
		line-height: 30rpx;
		padding-left: 10rpx;
	}

	.mainBox {
		background: #FFFFFF;
	}

	.maintitle {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		text-align: center;
		line-height: 88rpx;
		border-bottom: 1px solid #EEEEEE;
	}

	.mainLineJt {
		width: 25rpx;
		height: 24rpx;
		margin-top: 8rpx;
	}

	.mainLine {
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #EEEEEE;
		padding: 24rpx;
	}

	.lineName {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		line-height: 40rpx;
	}
	.tab-box{
		width: 360rpx;
		display: flex;
		height: 65rpx;
		background-color: #EFEFEF;
		border-radius: 10rpx;
		align-items: center;
		
	}
	.tab-box2{
		width: 360rpx;
		display: flex;
		height: 65rpx;
		align-items: center;
		justify-content: center;
		/* font-size: 32rpx;
		font-weight: bold; */
	}
	.tab-box-title{
		width: 175rpx;
		height: 55rpx;
		font-size: 28rpx;
		border-radius: 10rpx;
		font-weight: 400;
		text-align: center;
		line-height: 55rpx;
		margin: 0 5rpx;
	}
	.clickbu{
		background-color: #FFFFFF;
		font-weight: 700;
	}
	.tab-box-jian{
		
	}
	.tab-box-zhuan{
		
	}
	.head-box{
		width: 660rpx;
		height: 160rpx;
		margin: 10rpx auto;
	}
	.searchBtn{
		background-color: #F8FBFF;
		width: 100%;
		height: 80rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
	}
	.searchImg{
		width: 27rpx;
		height: 27rpx;
		margin: auto 20rpx;
		padding-top: 10rpx;
		
	}
	
	.searchTitle{
		font-size: 26rpx;
		color: #9E9E9E;
		padding-top: 10rpx;
	}
	

	

	
	.mainBoxChildJian{
		width:100%;
		padding: 10rpx;
		background: #ffffff;
	}
	.childTitle{
		/* text-align: center;
		font-size: 24rpx;
		font-weight: 700;
		margin-bottom: 10rpx; */
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		text-align: center;
		line-height: 88rpx;
		margin-bottom: -20rpx;
		
		
	}
	.jianShowContent{
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		background: #ffffff;
		place-items: center;
	}
	.jianChildbox{
		background: #ffffff;
		 min-height: 200rpx; 
		 width: 345rpx;
		 height: 421rpx;
		 border-radius: 10rpx;
		 margin: 6rpx 10rpx 10rpx 0rpx;
		 /* box-shadow: 1rpx -1rpx 3rpx 1rpx  #999999; */
		 border: 1rpx solid #dddddd;
	}
	.childBoxImage{
		width: 230rpx;
		height: 300rpx;
		margin: 20rpx auto;
	}
	.childBoxTitle{
		font-size: 28rxp;
		text-align: center;
		margin-top: 20rpx;
	}
	
	
	
</style>
