<template>
	<view class="content">
	  <homenav :iStatusBarHeight="iStatusBarHeight" :title="'搜索'"></homenav>
	  <view class="sTopBox">
		  <view class="searchInputBox" >
		  	<image src="../../static/img/icon_search.png" mode="" class="simg"></image>
		  	<input v-model="value" type="text"  placeholder="请输入车辆品牌、车系或VIN码" 
			placeholder-class="ip" ref="myInput" 
			  class="ssinput" @confirm="searchFn" :focus="focuszt">
			<image src="../../static/img/icon_search_del.png" mode="" class="search_del" @click="searchDel"></image>
		  </view>
		  <view class="searchBtn" @click="searchFn">
		  	搜索
		  </view>
	  </view>
		
	  <view class="box">
		  <view class="historyLine" v-for="(item,index) in carMlist">
		  <!-- 	<image src="http://img.db.66km.cn/carbrandlogo/B - 宝马.png" mode="" class="historylinecarImg"></image> -->
		  	<view class="historylinecar" @click="carMbtn(item)">{{item.title}}</view>
		  </view>
		  <nodata v-if="loading&&carMlist.length==0"></nodata>
	  </view>
	  
	  <!-- 选择车型 -->
	  <view class="ckcarBox" v-if="ckCarShow">
	  	<view class="ckcar">
	  		<view class="ckcarTop flex">
	  			<view class="ckcarTitle">请选择车型</view>
	  			<image src="../../static/img/icon_quxiao.png" mode="" class="ckcarClose" @click="ckcarClose"></image>
	  		</view>
	  		<view class="ckcarlineBox" v-for="(item,index) in vinList" @click="goDetal(item)">
	  			<view class="ckcarline flex" >
	  				<view class="ckcarLeft">{{item.title}}</view>
	  				<image src="../../static/img/icon_arrow.png" mode="" class="ckcarJtimg"></image>
	  			</view>
	  		</view>
	  	</view>
	  </view>
	  
	  <view class="popupone"  @click="popupc" v-if="popuponeShow">
	  	<view class="popup-content" @click.stop="">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view style="height: 44px;"></view>
			<view style="padding: 24rpx 0;">
				<view class="manufactorP">{{manufactor}}</view>
			</view>
	  		
	  		<scroll-view class="brandList" scroll-y="true">
	  			<view class="pLine" v-for="(item,index) in popuponeList" @click="popuponeBtn(item)">{{item.title}}</view>
	  		</scroll-view>
	  		
	  	</view>
	  </view>
	  <view class="popupone popupTwo" @click="popupcTwo" v-if="popupTwoShow">
	  	<view class="popup-content" @click.stop="">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view style="height: 44px;"></view>
	  		<view style="">
	  			<!-- <view class="manufactorP">{{displacement}}</view> -->
				<view class="manufactorPTow"> <span>{{displacement}}</span>  
				  <span @click="poneHide">上一步</span>
				</view>
	  		</view>
	  		
	  		<scroll-view class="brandList" scroll-y="true">
	  			<view class="pLine" v-for="(item,index) in displacementList" @click="goDetalcx(item)">{{item.displacement}}</view>
	  		</scroll-view>
	  		
	  	</view>
	  </view>
	  
	  
	</view>
</template>

<script>
	import homenav from "../../components/homenav/nav.vue"
	import nodata from '../../components/nodata/nodata.vue'
	export default {
		components: {
			homenav,nodata
		},
		data() {
			return {
				value:'',
				ckCarShow:false,
				vinList:[],
				carMlist:[],
				carMshow:false,
				popuponeShow:false,
				popuponeList:[],
				manufactor:'',
				displacementList:'',
				type:'',
				popupTwoShow:false,
				displacement:'',
				brand:'',
				carSeries:'',
				isVin:'',
				vin:'',
				iStatusBarHeight:'',
				focusKuwei:false,
				loading:false,
				bizType:'',
				carModel:'',
				focuszt:false,
			}
		},
		onLoad(opt) {
         this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
		 var that=this;
		  setTimeout(() => {  
		       this.focusKuwei=true;
				 
		  }, 500)
		 /* this.$nextTick(() => {
		     this.$refs.myInput.focus();
		  }); */
		
		},
		 onReady() {
		    // 确保在渲染完成后触发
		    this.$nextTick(() => {
		      this.focuszt = true;
		    });
		  },
		methods: {
		   searchDel(){
			   console.log("清除")
			   this.value=''
		   },
		   goDetal(e){
			  /* uni.navigateTo({
			   	url:'/pages/index/byItem?nLevelID='+e.carModelInfo.nLevelID+'&logo='+e.carModelInfo.logo+'&isVin='+this.isVin+'&value='+e.value+'&id='+e.ids+'&vin='+this.vin
			   }) */ 
			   uni.navigateTo({
			    	url:'/pages/index/goodsList?nLevelID='+e.carModelInfo.nLevelID+'&logo='+e.carModelInfo.logo+'&isVin='+this.isVin+'&value='+e.value+'&id='+e.ids+'&vin='+this.vin
			    })
		   },
		   goDetalcx(e){
			   console.log(e)
			  /* uni.navigateTo({
			   	url:'/pages/index/byItem?scarid='+e.id
			   }) */ 
			   uni.navigateTo({
			   	url:'/pages/index/goodsList?scarid='+e.id
			   }) 
		   },
		   carMbtn(e){
			   this.type=e.type;
			  
			   if(e.type==1){
				   this.manufactor=e.manufactor;
				   this.getpopuponeList()
			   }else{
				   this.brand=e.brand
				   this.carSeries=e.carSeries
				   this.manufactor=e.manufactor
				   this.carModel=e.carModel
				    this.bizType=e.bizType
				   this.getpopuponeList(e)
			   }
		   },
		   popuponeBtn(item){
			 
			   this.displacementList=item.displacementList;
			   this.displacement=item.title;
			   this.popupTwoShow=true;
			     console.log( this.displacementList)
		   },
		   poneHide(){
			   this.popupTwoShow=false;
		   },
		   popupcTwo(){
			   this.popupTwoShow=false;
		   },
		   getpopuponeList(e){
			   uni.showLoading({ title: '加载中'});
			   if(this.type==1){
				  var params={
				  		manufactor: this.manufactor,type:this.type
				  } 
				  this.$http('matchingByOpen/queryCarModelGroupIiPackageSecond', params,'POST').then(res => {
				    	uni.hideLoading();
				       this.popuponeList=res.data;
				  		this.popuponeShow=true;
				  })
			   }else if(this.type==2){
				 var params={
				 		manufactor: this.manufactor,type:this.type,carSeries:this.carSeries,brand:this.brand,
						bizType:this.bizType,carModel:this.carModel
				 }   
				 this.$http('matchingByOpen/queryCarModelGroupIiPackageSecond', params,'POST').then(res => {
				   	uni.hideLoading();
				      this.popuponeList=res.data;
				 	  this.popuponeShow=true;
				 })
			   }else{
				   uni.hideLoading();
				   console.log(e)
				   this.displacementList=e.displacementList;
				   this.popupTwoShow=true;
			   }
			   
			   
		   },
		   popupc(){
			   this.popuponeShow=false;
		   },
           searchFn(){
			  
			   console.log(this.value.length)
			   if(!this.value){
				   uni.showToast({
				       title: '请输入车辆品牌、车系或VIN码',
				   	   icon:'none',
				       duration: 3000,
				   });
				   return false
			   }
			   if(this.value.length==17){
				   uni.showLoading({ title: '加载中'});
				   this.isVin=1;
				   this.vin=this.value;
				   this.vinList=[];
				   this.loading=false;
				   this.$http('matchingByOpen/queryCarModelGroupByVinAggregation', {
				     vin: this.value,type:2
				    },'POST').then(res => {
				     	
						this.loading=true;
						if(res.code==0){
							uni.hideLoading();
							this.vinList=res.data;
							if(this.vinList.length==1){
								this.goDetal(this.vinList[0])
							}else{
								this.ckCarShow=true;
								this.carMshow=false;
							}
							
						}
				       
				   })
			   }else{
				   uni.showLoading({ title: '加载中'});
				   this.isVin=0;
				   this.vin='';
				   this.loading=false;
				   this.$http('matchingByOpen/queryCarModelGroupIiPackage', {
				     name: this.value,
				    },'POST').then(res => {
				     	uni.hideLoading();
						this.loading=true;
				        this.carMlist=res.data;
				   		this.carMshow=true;
						this.ckCarShow=false;
				   })
			   }
			   
			   
		   },
		   ckcarClose(){
			   this.ckCarShow=false;
		   }
		}
	}
</script>

<style scoped>
	.manufactorP{
		line-height: 69rpx;padding-left: 24rpx;
		 width: 504rpx;margin-left: 30rpx;
		 height: 69rpx;
		 background: #FF4F00 linear-gradient(132deg, #FF8635 0%, #FF4828 100%);
		 border-radius: 16rpx;
		 font-weight: 500;
		 color: #FFFFFF;font-size: 28rpx;
	}
	.manufactorPTow{
		line-height: 69rpx;padding-left: 24rpx;
		padding-right: 24rpx;display: flex;
		justify-content: space-between;
		background: #FF4F00 linear-gradient(132deg, #FF8635 0%, #FF4828 100%);
		font-weight: 500;
		color: #FFFFFF;font-size: 28rpx;
	}
	.brandList{
		height: calc(100vh - 200rpx);
		/* padding-bottom:var(--status-bar-height); */
	}
	.pLine{
		border-bottom: 1rpx solid #EEEEEE;
		font-weight: 400;
		color: #333333;font-size: 26rpx;
		padding: 30rpx 24rpx;
	}
	.popupone{
		width: 100vw;height: 100vh;
		background:rgba(0, 0, 0, 0.4) ;
		position: fixed;top: 0;left: 0;
		z-index: 11;
	}
	.popupTwo{
		z-index: 111;
	}
	.popup-content{
		width: 80vw;
		background: #FFFFFF;
		height: 100vh;
		margin-left: 20vw;
	}
	.ckcarJtimg{
		width: 26rpx;height: 26rpx;margin-top: 4rpx;
	}
	.ckcarlineBox{
	  padding:24rpx ;	
	  border-bottom: 1px solid #EEEEEE;
	}
	.ckcarLeft{
		font-weight: 400;line-height: 36rpx;
		color: #1A1A1A;font-size: 26rpx;
	}
	.ckcarBox{
		width: 100vw;height: 100vh;
		background:rgba(0, 0, 0, 0.4) ;
		position: fixed;top: 0;left: 0;
	}
	.ckcar{
		width: 750rpx;
		height: 772rpx;
		background: #FFFFFF;
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		position: absolute;
		left: 0;
		bottom: 0;
	}
	.ckcarClose{
		width: 30rpx;height: 30rpx;
	}
	.ckcarTitle{
		font-weight: 500;font-size: 28rpx;
		color: #1A1A1A;
		line-height: 40rpx;
	}
	.ckcarTop{
		padding: 40rpx 26rpx 20rpx 24rpx;
	}
.box{
	padding: 0 24rpx;
}
.sTopBox{
	display: flex;padding: 30rpx 24rpx;
}
.searchBtn{
	font-weight: 400;font-size: 28rpx;padding-left: 24rpx;
	color: #1A1A1A;line-height: 80rpx;
}
.searchInputBox{
	width: 622rpx;display: flex;
	height: 80rpx;position: relative;
	background: #F9F9F9;
	border-radius: 16rpx;
}
.ssinput{
	font-size: 28rpx;font-weight: 400;padding-left: 24rpx;line-height: 80rpx;height: 80rpx;
	width: 480rpx;
}
.search_del{
	width: 36rpx;height: 36rpx;padding-top: 23rpx;padding-bottom: 10px;padding-right: 10rpx;
	position: absolute;
	    right: 0;
}
.simg{
	width: 36rpx;height: 34rpx;margin-top: 23rpx;margin-left:30rpx;
}
.historylinecarImg{
	width: 46rpx;
	height: 46rpx;
}
.historylinecar{
	font-weight: 400;font-size: 26rpx;
	color: #1A1A1A;
	line-height: 37rpx;width: 636rpx;
}
.historyLine{
	display: flex;justify-content: space-between;
	padding: 30rpx 0;border-bottom: 1rpx solid #EEEEEE;
}
</style>
