<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="请输入商品型号" 
				placeholder-class="ip" class="ssinput" @confirm="searchFn" focus>
				<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="goodscont">
			
			<view class="jiyouBox" >
				<view class="brandBox">
					<view class="brandBtn" v-for="(item,index) in brandList" :class="{brandActive:item.ck}" @click="ckBrand(item)">{{item.name}}</view>
				</view>
				<view class="jylineBox" >
					<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.factoryNumber}} </view>
							<view class="goodsMs">电池型号：{{item.specificationModel}} </view>
							<view class="goodsMs">系列：{{item.brand}} <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>



	</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:'',
			   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:'',
			   pageIndex:1,
			   value:'',
			}
		},
		onLoad(opt) {
			  console.log(opt)
			   this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
              this.optdata=opt;
			  this.queryMaintainPartList()
			 // this.queryOilInfoByGroupID()
		},
		methods: {
			queryMaintainPartList(){
				 this.loading=false;
				 uni.showLoading({ title: '加载中'});
				 this.$http('partsByOpen/queryPartsListV2', {
				   pageSize:20,
				   pageIndex:this.pageIndex,
				   categoryCodes:'',
				   name:this.value,
				    brandId:this.brandId
				   
				  },'POST').then(res => {
					  this.loading=true;
					  uni.hideLoading();
					  if(res.data.length>1){
					  	res.data.reverse()
					  }
					  this.MaintainPartList=this.MaintainPartList.concat(res.data)
					 
					 // this.oldMaintainPartList=res.data
					 // this.modelRemarkTab(1)
				 })
			},
			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.MaintainPartList=[];
			  this.pageIndex=1
			  this.queryMaintainPartList()
			},
			searchDel(){
				this.value=''
			},
			searchFn(){
				this.MaintainPartList=[];
				this.pageIndex=1
				this.queryMaintainPartList()
			},
			goinstallation(){
			   uni.navigateTo({
			   	url:'installation?groupIds='+this.optdata.id+'&componentId='
			   })	
			},
			 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))
				 }
			 },
            
			 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
				 })
			 }
		},
		// 上拉加载更多
			onReachBottom() {
				this.pageIndex++;
				this.queryMaintainPartList()
			},
	}
</script>

<style scoped>
.salesLine{
	display: flex;
	font-size: 24rpx;
	line-height: 30rpx;
	padding: 20rpx 0;
}
.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: 28rpx;
		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{
		
		background: #ffffff;
		padding: 30rpx;
	
	}
	.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-bottom: 24rpx;
		display: flex;
		border-bottom: 1px solid #eaeaea;
		padding-top: 24rpx;
	}
	.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;
	}
	.historyLineCar{
		display: flex;justify-content: space-between;
	}
	.vinNum{
		font-weight: 400;font-size: 22rpx;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;
	}
	.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;
		justify-content: flex-end;
	}
	.topBtn{
		font-weight: 400;
		font-size: 26rpx;
		color: #F19D01;
		width: 180rpx;
		height: 56rpx;
		border-radius: 28rpx;
		border: 1px solid #F19D01;
		line-height: 56rpx;
		text-align: center;
		margin-left: 30rpx;
	}
	.copyVin{
		font-weight: 400;
		font-size: 22rpx;
		color: #3C3C3C;
		width: 62rpx;
		height: 34rpx;
		background: #F4F5F7;
		border-radius: 4rpx;
		line-height: 34rpx;
		text-align: center;
		margin-left: 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: #254A90;
			border-radius: 6rpx;
			color: #FFFFFF;
		}
	.glActive{
		background: #ffffff;
	}
	.glActive .glName{
	font-weight: 500;
	font-size: 26rpx;
	color: #E60006;
	/* border-left:4rpx solid #E60006; */
	}
	.sTopBox{
		display: flex;padding: 30rpx 24rpx;
		padding-bottom: 0;
	}
	.searchBtn{
		font-weight: 400;font-size: 28rpx;padding-left: 24rpx;
		color: #1A1A1A;line-height: 80rpx;
	}
	.searchInputBox{
		width: 600rpx;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;
			z-index: 11;
	}
	.simg{
		width: 36rpx;height: 34rpx;margin-top: 23rpx;margin-left:30rpx;
	}
.englishname{
	padding: 0 6rpx;
	border-radius: 8rpx;
	/* border:1px solid #254A90; */
	margin-left: 10rpx;
	display: inline-block;
	background: #254A90;
	font-size: 22rpx;
	color: #ffffff;
}
</style>