<template>
	<view class="content">
		<view class="indexTab">
			<view class="indexTabline" :class="{active:tabIndex==1}" @click="tabClick(1)">按车型</view>
			<view class="indexTabline" :class="{active:tabIndex==2}" @click="tabClick(2)">VIN查询</view>
			<view class="indexTabline" :class="{active:tabIndex==3}" @click="tabClick(3)">商品</view>
		</view>
	<!-- 	<view class="kogjian"></view> -->
		<carModel ref="carModelView" v-if="tabIndex==1"></carModel>
		<vinquery ref="vinView" v-if="tabIndex==2"></vinquery>
		<!-- <goods ref="goodsView" v-if="tabIndex==3"></goods> -->
		<view class="goodsBox" v-if="tabIndex==3">
			<view style="height: 90rpx;"></view>
			<view class="goodscontent">
				<view class="carSs goodsSs">
					<view class="carssBox" >
						<img src="../../static/img/icon_search.png" alt="" class="carSsImg">
						<input type="text" placeholder="名称、规格、出厂编码、OE、品牌" class="carssInput" v-model="goodsName" @confirm="getgoodsList">
					</view>
					
				</view>
				<view class="listBox">
					<view class="listLine" v-for="(item,index) in list" @click="godetail(item)">
						<img :src="item.imgs.split(',')[0]|| require('../../static/img/pic_def_bj.png')" alt="图片加载失败" class="lineIMg">
					    <view class="listlineRight">
					    	<view class="lineName">{{ item.brand }} {{ item.name }}</view>
							<view class="linespecificationModel">{{ item.specificationModel }} | {{ item.factoryNumber }}</view>
							<view class="linemodelRemark">备注：{{ item.modelRemark||'--' }}</view>
					    </view>
					</view>
					
				</view>
				<view class="nodata" v-if="!list.length&&!loading">
					<img src="../../static/img/pic_empty_def.png" alt="" class="nodataImg">
					<view class="nodataTxt">暂无匹配商品</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import carModel from './carModel.vue'
	import vinquery from './../vin/vinquery.vue'
	import goods from './../goods/goods.vue'
	export default {
		components: {
			carModel, //注册子组件
			vinquery,
			goods
		},
		data() {
			return {
				tabIndex:1,
				list:[],
				goodsName:'',
				page:1,
				limit:10,
				loading:true,
			}
		},
		onLoad() {
         // console.log(this.$getHashQuery("openId")openId=o2Rn3v1Mv_lXX3xijvHF6Z8EclAw)
		// console.log(this.$store.state.openId)
		  if (this.$getHashQuery('openId')) {
		    const openId = this.$getHashQuery('openId')
		    this.$store.commit('mutationsopenId', openId)
			uni.setStorageSync('openId', openId);
		  } else if (!this.$store.state.openId) {
		   // location.href = this.$baseURL + '/weChat/authorize'
		  }
		  var that=this;
		  setTimeout(function(){
			  that.$refs.carModelView.getdata();
		  },500)
		  /* this.$http('matchingByOpen/queryCarModelGroupPackage', {
		  	
		  	
		  }, 'POST').then(res => {
		  	
		  	
		  }) */
		},
		methods: {
			godetail(item){
				  uni.navigateTo({
					url:'datail?id='+item.id
				  })
		  },
          tabClick(index){
			  
			  this.tabIndex=index;
			  if(index==1){
				  var that=this;
				  setTimeout(function(){
				  		that.$refs.carModelView.getdata();
				  },500)
			  }
			  if(index==3){
				  this.getgoodsList
			  }
		  },
		  getgoodsList(){
			  this.page=1;
			  this.list=[];
			 uni.showLoading({ title: '加载中'});
			 this.loading=true;
			 this.$http('partsByOpen/queryPartsList', {
				name:this.goodsName,
				page:this.page,
				limit:10,
			 }, 'POST').then(res => {
				this.list=res.data;
				 this.loading=false;
				uni.hideLoading();
			 }) 
		  }
		},
		onReachBottom(){
			console.log("上拉");
			if(this.goodsName){
				uni.showLoading({ title: '加载中'});
				this.loading=true;
				this.page++
				this.$http('partsByOpen/queryPartsList', {
					name:this.goodsName,
					page:this.page,
					limit:10,
				}, 'POST').then(res => {
					var list=res.data
					this.list=this.list.concat(list);
					this.loading=false;
					uni.hideLoading();
				}) 
			}
			
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getgoodsList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		
	}
</script>

<style scoped>
	.content{
		min-height: 100vh;
		background: #F4F5F7;
	}
	
	.indexTab{
		display: flex;
		justify-content: space-around;
		line-height: 90rpx;
		background: #FFFFFF;
		border-bottom: 2rpx solid #eee;
		color: #333333;
		font-size: 30rpx;
		width: 100%;
		position: fixed;
		top: 0px;
		left: 0;
		z-index: 9999;
	}
	.indexTabline{
		font-size: 32rpx;
		width: 130rpx;
		text-align: center;
	}
	.active{
		border-bottom: 4rpx solid #3F90F7;
		color: #3F90F7;
	}
	.kogjian{
		height: 96rpx;
	}
	.goodscontent{
		min-height:calc(100vh - 44px) ;
		background: #FFFFFF;
	}
	.carSs{
		width: 750rpx;
		height: 96rpx;
		background: #FFFFFF;
		padding-top: 24rpx;
		position: relative;
	}
	.carssBox{
		width: 702rpx;
		height: 72rpx;
		background: #F4F5F7;
		border-radius: 36rpx;
		margin: 0 auto;
		
	}
	.carSsImg{
		width: 40rpx;
		height: 40rpx;
		margin-top: 16rpx;
		margin-left: 20rpx;
	}
	.carssInput{
		line-height:72rpx;
		font-size: 28rpx;
		height:72rpx;
		padding-left: 16rpx;
		width: 600rpx;
	}
	.carssBox{
		display: flex;
	}
	.listBox{
		padding: 0 24rpx;
		background: #FFFFFF;
		padding-top: 120rpx;
		width: 702rpx;
	}
	.lineIMg{
		width: 110rpx;
		height: 110rpx;
	}
	.listLine{
		padding: 20rpx 0;
		border-bottom: 1px solid #EEEEEE;
		display: flex;
	}
	.listlineRight{
		width: 600rpx;
		padding-left: 20rpx;
	}
	.lineName{
		color: #3C3C3C;font-size: 28rpx;
	}
	.linespecificationModel{
		color: #999999;font-size: 24rpx;padding-top: 5rpx;
	}
	.linemodelRemark{
		color: #999999;font-size: 24rpx;padding-top: 10rpx;
		overflow: hidden; 
	   text-overflow: ellipsis; 
		white-space: nowrap; 
		width: 550rpx;
	}
	
	.nodataImg{
		width: 452rpx;
	}
	.nodata{
		text-align: center;
		height: calc(100vh - 310rpx );
	}
	.nodataTxt{
		color: #999999;
		line-height: 40px;
		font-size: 28rpx;
		padding-top: 12rpx;
	}
	.goodsSs{
		position: fixed !important;
		width: 100vw;
		top: 90rpx;
		left: 0;
	}
</style>
