<template>
	<view class="content">
		<homenav :iStatusBarHeight="iStatusBarHeight" :title="'适配蓄电池'"></homenav>
		<view class="box">
			<view class="historyLine">
				<view class="historyLogoBox">
					<image :src="optdata.logo" mode="" class="historylinecarImg"></image>
				</view>
				<view>
					<view class="historylinecar">{{optdata.value}}</view>
					<view class="historyLineVin" v-if="optdata.isVin==1"><!--  -->
					     <view style="display: flex; padding-top: 16rpx;">
							 <view class="vinms">VIN</view>
							 <view class="vinNum">{{optdata.vin}}</view>
						 </view>
						
						<view class="copyVin" @click="copyFn(optdata.vin)">复制</view>
					</view>
				</view>
				
			</view>
			<view class="topBtnBox">
				<view class="topBtn" @click="goinstallation">电池安装</view>
				<view class="topBtn" @click="gopz">车辆详情</view>
			</view>
		</view>
		<view class="goodscont">
			<!-- <view class="topBox">
				<view class="topLine" @click="goby">
					<image src="../../static/img/icon_baoyang.png" mode="" class="toplineImg"></image>
					<view class="topName">保养周期</view>
				</view>
				<view class="topsx"></view>
				<view class="topLine" @click="gopz">
					<image src="../../static/img/icon_cheliang.png" mode="" class="toplineImg"></image>
					<view class="topName">车辆配置</view>
				</view>
			</view> -->
			<!-- <view class="goosLeft">
				<view class="goodsLefeLine" :class="{glActive:leftIndex==index}"
				 @click="leftFn(index,item)" v-for="(item,index) in leftData">
				    <view class="leftKK" v-if="leftIndex==index"></view>
					<view v-else  class="leftKK2"></view>
					<view class="glName">{{item.name}}</view>
				</view>
			</view> -->
			<view class="jiyouBox">
				
				<view class="brandBox">
					<!-- <view class="brandBtn" :class="{brandActive:type==1}" @click="ckBrand(1)">阿诺德</view>
					<view class="brandBtn" :class="{brandActive:type==2}" @click="ckBrand(2)">鸿雁</view>
					<view class="brandBtn" :class="{brandActive:type==3}" @click="ckBrand(3)">三冠</view>
					<view class="brandBtn" :class="{brandActive:type==4}" @click="ckBrand(4)">威斯康</view> -->
					<view class="brandBtn" v-for="(item,index) in brandList" :class="{brandActive:item.ck}" @click="ckBrand(item)">{{item.name}}</view>
				</view>
				<!-- <view class="ckName">
					{{componentName}}
				</view> -->
				<view class="jylineBox"  v-if="loading">
					<view class="jyline" v-for="(item,index) in MaintainPartList" @click="godetail(item)"><!-- MaintainPartList -->
						<view class="jyimgBox">
						    <image v-if="item.imgs.split(',')[0]" :src="item.imgs.split(',')[0]" mode="aspectFit" class="jyimg"></image>
							<image v-else src="../../static/img/noimg.png" mode="aspectFit" class="jyimg"></image>
						</view>
						<view class="lineRgiht">
							<!-- <view class="goodsName">{{item.name}}| {{item.partsCode}}</view> -->
							<view class="goodsName">附属型号：{{item.brand}} {{item.factoryNumber}} </view>
							<view class="goodsMs">电池型号：{{item.specificationModel}} </view>
							<view class="goodsMs">系列：<span>{{item.GeneralpurposeName}}</span> <span class="englishname" v-if="item.englishname">{{item.englishname}}</span>  </view>
							<view class="goodsMs" v-if="item.carmodelremark">适用车型:{{item.carmodelremark}} </view>
						</view>
						
					</view>
				</view>
				<nodata v-if="MaintainPartList.length==0"></nodata>
			</view>
			
			<!-- <view class="jiyouBox"  v-if="loading">
				<view class="jiyouTop">
					<view class="jiyoutopTitle">原厂售后推荐</view>
				</view>
				<view class="salesLine">
					<view class="salesLeft">建议加注量</view>
					<view class="salesRight">{{oilusage}}</view>
				</view>
				<view class="salesLine">
					<view class="salesLeft">规格型号</view>
					<view class="salesRight">{{spec}}</view>
				</view>
			</view> -->


		</view>



	</view>
</template>

<script>
	import nodata from '../../components/nodata/nodata.vue'
	import homenav from "../../components/homenav/nav.vue"
	export default {
		components: {
            nodata,homenav
		},
		data() {
			return {
               optdata:'',
			   MaintainPartList:[],
			   oilusage:'',
			   iStatusBarHeight:'',
			   loading:false,
			   spec:'',
			   modelRemarkNum:1,
			   oldMaintainPartList:'',
			   type:'',
			   leftIndex:0,
			   leftData:[
				   {name:'机油',componentCode:'015001'},
				   {name:'变速箱油',componentCode:'007005'},
				   {name:'变速箱滤清器',componentCode:'007004'},
				   {name:'雨刷',componentCode:'006004'},
			   ],
			  // componentCode:'015001',
			   componentCode:'',
			   componentName:'机油',
			   brandList:[
				   {name:'三冠',id:'fc89e243-3358-4037-80ed-67c5d8c35085',ck:false},
				   {name:'威斯康',id:'ee21a0d0-f181-42be-990b-73eb692c196d',ck:false},
				   {name:'阿诺德',id:'a136f3b8-0586-4fe5-ac49-389aa4cc990b',ck:false},
				   {name:'鸿雁',id:'8fa5f395-86c7-4488-b4ea-ac058c7ae330',ck:false},
			   ],
			   brandId:'',
			   defaultPic:'../../static/goods-image/defaultPic.png'
			}
		},
		onLoad(opt) {
			  console.log(opt)
			   this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
              this.optdata=opt;
			  if(this.optdata.type){
			  				  this.type=this.optdata.type
			  }
			
			  if(opt.scarid){
					   this.scarid=opt.scarid;
					   this.queryCarModelGroupInfo()
			  }else{
					   if(opt.isVin==1){
						   this.isVin=1;
						   this.vin=opt.vin
					   }
							 
					   this.saveQueryHistory()
					   this.queryMaintainPartList()
					   this.queryOilInfoByGroupID()
			  }
			 
		},
		methods: {
			queryCarModelGroupInfo(){
			   uni.showLoading({ title: '加载中'});
			   this.$http('matchingByOpen/queryCarModelGroupInfo', {
				 id:this.scarid,
				
				},'POST').then(res => {
					uni.hideLoading();
					var data={
						value:res.data.value,
						id:res.data.id,
						nLevelID:res.data.carModelInfo.nLevelID,
						logo:res.data.carModelInfo.logo,
					}
					 this.optdata=data;
					//this.saveQueryHistory();
					 this.queryMaintainPartList()
			   })
			},
			saveQueryHistory(){
			   this.$http2('saveQueryHistory', {
				 nLevelID:this.optdata.nLevelID,
				 logo:this.optdata.logo,
				 title:this.optdata.value,
				 groupId:this.optdata.id,
				 isVin:this.isVin,
				 vin:this.vin
				},'POST').then(res => {
							
					
			   })
			},
			leftFn(index,item){
			  this.leftIndex=index
			  this.componentCode=item.componentCode
			  this.componentName=item.name
			  this.queryMaintainPartList()
			},
		    ckBrand(item){
				item.ck=!item.ck
			  //this.type=num	
			  var ids=[]
			  this.brandList.forEach(item=>{
				  if(item.ck){
					  ids.push(item.id)
				  }
			  })
			  this.brandId=ids.join(',')
			  this.queryMaintainPartList()
			},
			goinstallation(){
				
				 uni.showLoading({ title: '加载中'});
				this.$http('partsByOpen/queryCarmodelhelp', {
				  componentCode:"005001",
				  groupId:this.optdata.id
				 
				 },'POST').then(res => {
						uni.hideLoading();	
							
									//this.imgUrl=res.data.yhzl.imgUrl
						var mtList=res.data.yhzl.mtList
						if(mtList){
							this.goinstallationRouter()	
						}else{
							uni.showToast({
							  title: '数据待完善',
							  icon: 'none',
							  duration: 3000
							});
						}
								
				}).catch(err=>{
					uni.hideLoading();
					uni.showToast({
					  title: '数据待完善',
					  icon: 'none',
					  duration: 3000
					});
				})
			  	
			},
			goinstallationRouter(){
				uni.navigateTo({
					url:'installation?groupIds='+this.optdata.id+'&componentCode='+this.componentCode
				})
			},
			 modelRemarkTab(num){
				 this.modelRemarkNum=num
				 if(num == 1){
					 var name='0-10万公里'
					 var arr=[]
					 this.oldMaintainPartList.forEach(item=>{
						 var state=false
						 item.ruleList.forEach(v=>{
							 if(v.version == name){
								 state=true
							 }
						 })
						 if(state){
						 	 arr.push(item)
						 }
					 })
					
					 this.MaintainPartList=arr
					  //this.MaintainPartList= this.oldMaintainPartList.filter(item => item.modelRemark.includes(name))
				 }else{
					 var name='10万公里以上'
					 var arr=[]
					this.oldMaintainPartList.forEach(item=>{
						 var state=false
						 item.ruleList.forEach(v=>{
							 if(v.version == name){
								 state=true
							 }
						 })
						 if(state){
							 arr.push(item)
						 }
					})
					 this.MaintainPartList=arr 
					 //this.MaintainPartList= this.oldMaintainPartList.filter(item => item.modelRemark.includes(name))
				 }
			 },
             queryMaintainPartList(){
				 this.loading=false;
				 uni.showLoading({ title: '加载中'});
				 if(this.componentCode){
					 var json={
						 groupId:this.optdata.id,
						 componentCode:this.componentCode,
						 brandId:this.brandId
					 }
				 }else{
					 var json={
					 	 groupId:this.optdata.id,
					 	 brandId:this.brandId				 
					 }
					 
				 }
				
				 this.$http('partsByOpen/queryMaintainPartList', json,'POST').then(res => {
					  this.loading=true;
				 	  uni.hideLoading();
				 	  this.MaintainPartList=res.data
					  this.oldMaintainPartList=res.data
					 // this.modelRemarkTab(1)
				 })
			 },
			 queryOilInfoByGroupID(){
				 var that=this;
				 this.$http('matchingByOpen/queryOilInfoByGroupID', {
				  // mileage:'30000',
				   groupId:this.optdata.id,
				   
				  },'POST').then(res => {
				 		var arr = res.data
						arr.forEach(item=>{
							if(item[0]=='机油'){
								that.oilusage=item[2]
								that.spec=item[1]
							}
							
						})
						console.log(that.oilusage)
				 })
			 },
			 goby(){
				 uni.navigateTo({
				 	url:'/pages/index/maintenance?nLevelID='+this.optdata.nLevelID+'&id='+this.optdata.id
				 })
			 },
			 godetail(e){
				 uni.navigateTo({
				 	url:'/pages/index/goodsDetail?id='+e.id
				 })
			 },
			 gopz(){
				 uni.navigateTo({
				 	url:'/pages/index/carConfiguration?nLevelID='+this.optdata.nLevelID
				 })
			 },
			 copyFn(e){
				uni.setClipboardData({
				   data: e,
				   success: function () {
					 uni.showToast({
					   title: '复制成功',
					   icon: 'success',
					   duration: 2000
					 });
				   },
				   fail: function () {
					 console.log('复制失败');
					
				   }
				 });
			 }
		}
	}
</script>

<style scoped>
.goodscont{
	display: flex;margin-top: 20rpx;
	min-height: calc(100vh - 450rpx);
}
.salesLine{
	display: flex;
	font-size: 24rpx;
	line-height: 30rpx;
	padding: 20rpx 0;
}
.goodsLefeLine{
	display: flex;justify-content: center;
	padding: 22rpx 0;
}
.brandBox {
	padding: 30rpx 20rpx;
	padding-bottom: 24rpx;
}
.goosLeft{
	width: 190rpx;
	font-size: 26rpx;
	color: #3C3C3C;
	background: #F6F6F6;
}
.salesLeft{
	width: 200rpx;
	color: #999999;
	
}
	.content {
		min-height: 100vh;
		background: #F4F5F7;
	}
    .jyimgBox{
		border: 1px solid #EEEEEE;    width: 120rpx;border-radius: 10rpx;
		height: 120rpx;
	}
	.box {
		padding: 0 24rpx;
		background: #ffffff;
	}

	.historylinecarImg{
		width: 54rpx;
		height: 54rpx;
	}
	.historyLogoBox{
			display: flex;align-items: center;
			padding-right: 14rpx;
		}

	.historylinecar {
		font-weight: 500;
		font-size: 26rpx;
		color: #1A1A1A;
		line-height: 46rpx;
		width: 636rpx;
	}

	.historyLine {
		 display: flex;
		padding: 30rpx 0;
		/* border-top: 1rpx solid #EEEEEE; */
		padding-bottom: 16rpx;
	}

	.cont {
		/* padding: 30rpx 24rpx; */
	}
	.toplineImg{
		width: 35rpx;
		height: 34rpx;
	}
	.topName{
		line-height: 34rpx;font-weight: 400;
color: #FFFFFF;font-size: 28rpx;padding-left: 16rpx;
	}
	.topBox{
		width: 702rpx;
		height: 98rpx;
		background: #FFFFFF linear-gradient(132deg, #FF8635 0%, #FF4828 100%);
		border-radius: 16rpx;
		display: flex;justify-content: center;
	}
	.topsx{
		width: 2rpx;background: #ffffff;
		margin-left: 85rpx;margin-right: 85rpx;
		height: 54rpx;margin-top: 22rpx;
	}
	.topLine{
		display: flex;padding-top: 34rpx;
	}
	.jiyouTop{
		display: flex;justify-content: space-between;
	}
	.jiyouBox{
		/* margin-top: 30rpx; */
		background: #ffffff;
		/* padding: 30rpx; */
		/* width: 560rpx; */
	}
	.jiyoutopTitle{
		font-weight: 500;font-size: 28rpx;
		color: #1A1A1A;
		line-height: 40rpx;
	}
	.jyzl{
		font-weight: 400;line-height: 40rpx;
		color: #666666;font-size: 24rpx;
	}
	.jyimg{
		width: 120rpx;
		height: 120rpx;
		border-radius: 10rpx;
	}
	.jyline{
		padding: 24rpx 20rpx;
		display: flex;
		border-bottom: 1px solid #EEEEEE;
	}
	.jyline:last-child{
		border: none;
	}
	.jyName{
		font-weight: 400;font-size: 22rpx;
		color: #1A1A1A;
		line-height:36rpx ;
		overflow: hidden; 
		text-overflow: ellipsis; 
		display: -webkit-box; 
		-webkit-box-orient: vertical; 
		-webkit-line-clamp: 2;
		padding-top: 10rpx;
	}
	.best{
		color: #FF4F00;border-radius: 6rpx;
		padding: 0 8rpx;border: 1px solid #FF4F00;
	}
	.jylineBox{
		/* display: flex;justify-content: space-between;flex-wrap: wrap; */
	}
	.historyLineVin{
		display: flex;background: #ffffff;justify-content: space-between;
	}
	.historyLineCar{
		display: flex;justify-content: space-between;
	}
	.vinNum{
		font-weight: 400;font-size: 26rpx;padding-left: 10rpx;
		color: #999999;line-height: 30rpx;
	}
	.vinms{
		width: 38rpx;
		height: 26rpx;
	/* 	background: linear-gradient(224deg, #FFDA28 0%, #FFBF35 100%); */
		border-radius: 4rpx;
		text-align: center;
		line-height: 26rpx;
		font-weight: 600;
		color: #FFFFFF;
		font-size: 18rpx;
		margin-top: 2rpx;
		 background: #254A90;
	}
	.ruleListSpan{
		font-weight: 400;
		font-size: 22rpx;
		color: #999999;
		    line-height: 36rpx;
			padding-right: 6rpx;
	}
	.modelRemarkBox{
		display: flex;padding-bottom: 20rpx;
	}
	.modelRemarkLine{
		background: #eee;
		padding: 6rpx 20rpx;
		border-radius: 6rpx;
		margin-right: 30rpx;
		font-size: 26rpx;
	}
	.activeMr{
		background: #FFFFFF linear-gradient(132deg, #FF8635 0%, #FF4828 100%);
		color: #FFF;
	}
	.topBtnBox{
		display: flex;padding-bottom: 30rpx;
		padding-left: 70rpx;
	}
	.topBtn{
		font-weight: 400;
		font-size: 26rpx;
		color: #254A90;
		width: 180rpx;
		height: 56rpx;
		border-radius: 28rpx;
		border: 1px solid #254A90;
		line-height: 56rpx;
		text-align: center;
		margin-right: 30rpx;
	}
	.copyVin{
		font-weight: 400;
		font-size: 26rpx;
		color:#3F90F7;
		width: 62rpx;
		height: 34rpx;
		line-height: 34rpx;
		text-align: right;
		padding-top: 16rpx;
	}
	.brandBox{
		display: flex;
	}
	.brandBtn{
		font-size: 26rpx;
		color: #3C3C3C;
		padding: 10rpx 20rpx;
		background: #F6F6F6;
		border-radius: 6rpx;
		margin-right: 20rpx;
	}
	.lineRgiht{
		padding-left: 16rpx;
	}
	.goodsName{
		font-size: 28rpx;
		color: #254A90;
		line-height: 40rpx;
	}
	.goodsMs{
		font-size: 24rpx;
		color: #222222;
		line-height: 33rpx;
		padding-top: 10rpx;
	}
	.brandActive{
		background: rgba(37,74,144,0.08);
		border-radius: 6rpx;
		color: #254A90;
	}
.glActive{
	background: #ffffff;
}
.glActive .glName{
font-weight: 500;
font-size: 26rpx;
color: #E60006;
/* border-left:4rpx solid #E60006; */
}
.leftKK{
	background: #E60006;
	width: 6rpx ;
	height: 24rpx;
	border-radius: 4rpx;
	margin-top: 6rpx;
	overflow: hidden;
}
.leftKK2{
	width: 4rpx ;
}
.glName{
	width: 170rpx;text-align: center;
	font-size: 26rpx;
}
.ckName{
	width: 532rpx;
	height: 60rpx;
	background: #F6F6F6;
	border-radius: 4rpx;
	font-size: 26rpx;
	color: #3C3C3C;
	line-height: 60rpx;
	margin-left: 20rpx;
	padding-left: 20rpx;
	font-weight: 600;
}
.jiyouBox{
  width: 100%;
}
.englishname{
	padding: 0 6rpx;
	border-radius: 8rpx;
	border:1px solid #254A90;
	margin-left: 10rpx;
	display: inline-block;
}
</style>