<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="name" 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 style="height: 20rpx;background: #F4F5F7;"></view>
		<view class="cont">
			<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="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}} </view>
							<view class="goodsMs">型号：{{item.specificationModel}} <span class="factoryNumber" v-if="item.factoryNumber">{{item.factoryNumber}}</span></view>
							<view class="goodsMs modelRemark" @click.stop="modelRemarkFn(item.modelRemark)">适用车型：{{item.modelRemark}}</view>
						</view>
						
					</view>
				</view>
				<view style="width: 500rpx;padding-top: 200rpx;" v-if="MaintainPartList.length==0">
					<nodata ></nodata>
				</view>
				
			</view>
			
			


		</view>

<uni-popup ref="popup"  background-color="#fff">
<!-- <uni-popup-message type="center" :message="messageText" :duration="2000"></uni-popup-message> -->
 <view class="popup-content" ><text
						class="text">{{messageText}}</text></view>
</uni-popup>

	</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:'',
			   componentCode:'',
			   leftData:[
				   {name:'全部',componentCode:''},
				   {name:'点火线圈',componentCode:'001006003'},
				   {name:'火花塞',componentCode:'001006001'},
			   ],
			   leftIndex:0,
			   pageIndex:1,
			   name:'',
			   messageText:'',
			}
		},
		onLoad(opt) {
			  console.log(opt)
			   this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
              this.optdata=opt;
			  this.queryMaintainPartList()
			 // this.queryOilInfoByGroupID()
		},
		methods: {
			modelRemarkFn(txt){
				this.messageText=txt
				this.$refs.popup.open('center')
			},
			leftFn(index,item){
			  this.pageIndex=1
			  this.MaintainPartList=[]
			  this.leftIndex=index
			  this.componentCode=item.componentCode
			 // this.componentName=item.name
			  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))
				 }
			 },
			 searchFn(){
				 this.pageIndex=1
				 this.MaintainPartList=[]
				 this.queryMaintainPartList()
			 },
             queryMaintainPartList(){
				 this.loading=false;
				 uni.showLoading({ title: '加载中'});
				 this.$http('partsByOpen/queryPartsListV2', {
				   //groupId:this.optdata.id,
				   pageSize:20,
				   pageIndex:this.pageIndex,
				   categoryCodes:this.componentCode,
				   name:this.name
				   
				  },'POST').then(res => {
					  this.loading=true;
				 	  uni.hideLoading();
				 	  //this.MaintainPartList=res.data
					  this.MaintainPartList=this.MaintainPartList.concat(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
				 })
			 }
		},
		// 上拉加载更多
		onReachBottom() {
			this.pageIndex++;
			this.queryMaintainPartList()
		},
	}
</script>

<style scoped lang="less">
.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: 90rpx;border-radius: 10rpx;
		height: 90rpx;
	}
	.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; */
		display: flex;
		/* margin-top: 20rpx; */
	}
	.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-top: 0;
		
	}
	.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: 90rpx;
		height: 90rpx;
		border-radius: 10rpx;
	}
	.jyline{
		padding-bottom: 26rpx;
		display: flex;
		border-bottom: 1px solid #eaeaea;
		padding-top: 26rpx;
		padding-left: 20rpx;
	}
	.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;
	}
	.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-right: 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: 30rpx;
		color: #222;
		line-height: 40rpx;
	}
	.goodsMs{
		font-size: 26rpx;
		color: #3C3C3C;
		line-height: 33rpx;
		padding-top: 6rpx;
	}
	.sTopBox{
		display: flex;padding: 30rpx 24rpx;
		padding-bottom: 20rpx;
	}
	.searchBtn{
		font-weight: 400;font-size: 28rpx;padding-left: 24rpx;
		color: #3E86F0;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: 24rpx;
		position: absolute;
		    right: 0;
	}
	.simg{
		width: 36rpx;height: 34rpx;margin-top: 25rpx;margin-left:30rpx;
	}
.goosLeft{
		width: 170rpx;
		font-size: 26rpx;
		color: #3C3C3C;
		background: #F6F6F6;
		height: calc(100vh - 350rpx);
	}
	.goodscont{
		display: flex;margin-top: 20rpx;
		min-height: calc(100vh - 450rpx);
	}
.goodsLefeLine{
	display: flex;justify-content: center;
	padding: 22rpx 10rpx;
}
.glActive{
	background: #ffffff;
}
.glActive .glName{
font-weight: 500;
font-size: 30rpx;
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: 30rpx;
}
.modelRemark{
	overflow: hidden;
	  text-overflow: ellipsis;
	  white-space: nowrap; /* 防止文本换行 */
	width: 430rpx;
}
.popup-content {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 15px;
	
		background-color: #fff;
		max-height: 60vh;
		overflow: scroll;
	}
.factoryNumber{
	   padding: 0 10rpx;
	   border-radius: 8rpx;
	    border:1px solid #E60006; 
	   margin-left: 10rpx;
	   display: inline-block;
	   /* background: #E60006; */
	   font-size: 26rpx;
	   color: #E60006;
}
</style>