<template>
	<view class="content" style="background-color: #ffffff;">
		<!-- 自定义导航 -->
		<view class="zdyNavBox">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view class="zdyNav">
				<view class="zdyNavLeft">
					<div @click="goback" class="uni-page-head-btn"><i class="uni-btn-icon"
							style="color: rgb(0, 0, 0); font-size: 27px;"></i></div>
				</view>
				<view class="xx" style="margin-left: -70rpx;" @click="goToSelectCarModel">
					<image src="/static/img/group2.png" style="width: 27rpx;height: 27rpx;"></image>
				</view>
				<view class="tab-box2">车型件</view>
				<!-- <view v-if="param.length != 0" class="zdyNavRight" @click="goOemSearch()">OEM搜索</view> -->
				<view v-if="param.length != 0" class="zdyNavRight" ></view>
				<view v-else style="width: 120rpx;"></view>
				
			</view>
		</view>
		
		<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
		<view style="height: 44px;"></view>
		
		
		<!-- <view v-if="type != 2" class="top">
			<view class="topCont">
				<view class="carBox">
					<view class="carTxt">{{description}}</view>
				</view>
				<view class="vinBox">
					<view class="vinBox2">
						<view class="vinB">VIN</view>
						<view class="vinNum">{{vin}}</view>
					</view>
					<view class="vinBox2"  v-if="chexingMesList.length != 0">
						<view class="detail" @click="goCarDetail()">车型详情</view>
						<image src="../../static/img/icon_arrow_blue_r@2x.png" mode="" style="width: 24rpx; height: 24rpx"></image>
					</view>
				</view>
			</view>
		</view>
		<view  class="top">
			
				<view class="carBox2">
					<view class="carTxt2">{{description}}</view>
				</view>
		
		</view> -->
		<view class="top" >
			
				<!-- <view class="carBox2">
					<view class="carTxt2" v-if="!description">{{brand_name}}</view>
					<view class="carTxt2" v-if="description">{{description}}</view>
				</view> -->
				<view class="head-box">
					<view class="searchBtn" @click="goOemSearch()">
						<image src="../../static/img/icon_search.png" class="searchImg"></image>
						<span class="searchTitle">搜索配件名称/OE号</span>
					</view>
					<!-- <view class="cardDetail">
						<view class="image-box">
							<image :src="image" style="width: 78rpx;height: 78rpx;"></image>
						</view>
						<view class="detail">
							<view class="code" v-if="vin !=undefined && vin !='undefined'" >
								<view>{{vin}}</view>
							</view>
							<view class="head-this-title">{{description}}</view>
						</view>
					</view> -->
					<view class="cardDetail" :class="{novin: vin ==undefined || vin=='undefined' || vin =='' }">
						<view class="image-box">
							<image :src="image" style="width: 78rpx;height: 78rpx;"></image>
						</view>
						<view class="detail" :class="{detailNoVin: vin == undefined || vin=='undefined' || vin =='' }">
							<view class="code" v-if="vin !=undefined &&  vin!='undefined' && vin !='' " >
								<view>{{vin}}</view>
							</view>
							<view class="head-this-title" >{{description}}</view>
						</view>
					</view>
				</view>
		</view>
		
		<view class="mainBox">
			<view class="maintitle">{{caption}}
				<view @click="goback" class="backBox">
					<image src="../../static/img/icon_arrow_blue_l@2x.png" mode="" class="backZongImg"></image>
					<view class="backTxt">返回总组</view>
				</view>
			</view>
			<view class="searchBox" v-if="lastShow">
				<view class="inputBox">
					<img src="../../static/img/icon_search.png" alt="" class="searchImg2">
					<input type="text" placeholder="快速查找子组" class="topInput" v-model="childrenss"
						@confirm="childrenkeyup">
				</view>
			</view>

			<view class="mainLine" v-for="(item,index) in childrenList" @click="goThree(item,index)" v-if="lastShow">
				<view class="lineLeft">
					<image class="lineIMg" :src="item.image_url" v-if="item.image_url" mode="aspectFit"></image>
					<image class="lineIMg" src="../../static/img/noimg.png" v-else mode="aspectFit"></image>
				</view>
				<view class="lineRIght">
					<view class="lineName">{{item.caption}}</view>
					<view class="lineBm">{{item.code}}</view>
					<view class="linejs" v-html="item.remark"></view>
				</view>


			</view>
			<view class="mainBox m1" v-if="restrainShow1">
				<view class="mainLine2" v-for="(item,index) in restrainList1" @click="restrainClickOne(item)">
					<view class="lineName2">{{item.caption}}</view>
					<image src="../../static/img/jt.png" mode="" class="mainLineJt"></image>
				</view>
			</view>
			<view class="mainBox m2" v-if="restrainShow2">
				<view class="mainLine2" v-for="(item,index) in restrainList2" @click="restrainClickTwo(item)">
					<view class="lineName2">{{item.caption}}</view>
					<image src="../../static/img/jt.png" mode="" class="mainLineJt"></image>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				vin: '',
				brand_name: '',
				access_time: '',
				zzTime: '',
				caption: '',
				param: '',
				token: '',
				list: '',
				restrainShow1: false,
				restrainList1: '',
				restrainShow2: false,
				restrainList2: '',
				lastShow: false,
				childrenList: '',
				oldList: '',
				childrenss: '',
				iStatusBarHeight: '',
				epc_id:'',
				description:'',
				chexingMesList:[],
				type:'',
				image:'',
				vin:'',
			}
		},
		onLoad(opt) {
			this.vin = opt.vin;
			this.zzTime = opt.zzTime;
			this.param = opt.param;
			this.token = opt.token;
			this.epc_id = opt.epc_id;
			this.description=opt.description;
			this.type = opt.type;
			this.image = opt.image;
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.getData()
			this.chexingMesList = uni.getStorageSync('chexingMesList');
		},
		methods: {
			goOemSearch(){
				uni.navigateTo({
					url:'OemSearch?brand='+ this.brand_name + '&epc_id=' + this.epc_id + '&vin=' + this.vin + '&param=' + this.param +
						'&token=' + this.token + '&access_time=' + this.access_time
				})
			},
			//返回选品牌
			goToSelectCarModel(){
				this.goHome();
			},
			goHome(){
				var token= uni.getStorageSync("token")
				console.log(token)
				if(!token){
					var token=getHashQuery('token')
				}
			    var cachekey= uni.getStorageSync("cachekey")
				if(this.vin){
					var url = 'http://byweb.66km.cn/#/home?token='+token//+'&cachekey='+cachekey
				}else{
					var url = 'http://byweb.66km.cn/#/home?token='+token+'&cachekey='+cachekey
				}
				
				window.location.href =url 
			 },
			goback() {
				console.log('返回');
				uni.navigateBack({})
			},
			restrainClickOne(item) {
				this.param = item.param;
				this.token = item.token;
				if (item.next_restrain == 1) {
					this.getYsone()
				} else {
					this.getYsDlist()
				}
			},

			restrainClickTwo(item) {
				this.param = item.param;
				this.token = item.token;
				if (item.next_restrain == 1) {
					//this.getYsDlist()
					this.getYsone()
				} else {
					this.getYsDlist()
				}
			},
			getYsDlist() {
				uni.showLoading({
					title: '加载中'
				});
				let vin = this.vin =="undefined" ? '':this.vin;
				console.log(vin);
				this.$http('advancedEpc/getSubgroup', {
					vin: vin,
					access_time: this.access_time,
					param: this.param,
					token: this.token,
					 epc_id:this.epc_id,

				}, 'GET').then(res => {
					uni.hideLoading();
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						this.caption = res.data.result.caption;
						this.brand_name = res.data.result.brand_name;
						this.access_time = res.data.result.access_time;
						this.restrainShow2 = false;
						this.restrainShow1 = false;
						this.lastShow = true;
						this.childrenList = res.data.result.list;
						this.oldList = this.childrenList

					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}

				});
			},
			getYsone() {
				uni.showLoading({
					title: '加载中'
				});
				let vin = this.vin =="undefined" ? '':this.vin;
				console.log(vin);
				this.$http('advancedEpc/getSubgroup', {
					vin: vin,
					access_time: this.access_time,
					param: this.param,
					token: this.token,
                     epc_id:this.epc_id,
				}, 'GET').then(res => {
					uni.hideLoading();
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						this.caption = res.data.result.caption;
						this.brand_name = res.data.result.brand_name;
						this.access_time = res.data.result.access_time;
						if (res.data.result.level_identify == 'group_restrain' || res.data.result.level_identify ==
							'subgroup') { //约束
							console.log("约束2")
							if(res.data.result.list[0].next_restrain==1){
								this.restrainShow2 = true;
								this.restrainShow1 = false;
								this.restrainList2 = res.data.result.list;
							}else{
								this.lastShow = true;
								this.restrainShow2 = false;
								this.restrainShow1 = false;
								this.childrenList = res.data.result.list;
								this.oldList = this.childrenList
							}
							

						} else {
							this.lastShow = true;
							this.restrainShow1 = false;
							this.childrenList = res.data.result.list;
							this.oldList = this.childrenList
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}

				});
			},
			getData() {
				uni.showLoading({
					title: '加载中'
				});
				let vin = this.vin =="undefined" ? '':this.vin;
				console.log(vin);
				this.$http('advancedEpc/getSubgroup', {
					vin: vin,
					access_time: this.zzTime,
					param: this.param,
					token: this.token,
                    epc_id:this.epc_id,
				}, 'GET').then(res => {
					uni.hideLoading();
					//console.log(res.data.number);
					if (res.data.number == 200 || res.data.number == 5212) {
						this.caption = res.data.result.caption;
						this.brand_name = res.data.result.brand_name;
						this.access_time = res.data.result.access_time;
						if (res.data.result.level_identify == 'group_restrain' ) { //约束
							console.log("约束1")
							this.restrainShow1 = true;
							this.restrainList1 = res.data.result.list;
						} else {
							if(res.data.result.list[0].next_restrain==1){
								this.restrainShow1 = true;
								this.restrainList1 = res.data.result.list;
							}else{
								this.lastShow = true;
								this.childrenList = res.data.result.list;
								this.oldList = this.childrenList
							}
							
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 3000
						});
					}

				});
			},
			goCarDetail() {
				uni.navigateTo({
					url: 'CarDetail'
				})
			},
			goThree(item, index) {
				var that = this;
				uni.setStorage({
					key: 'childrenList',
					data: that.childrenList,
					success: function() {
						uni.navigateTo({
							url: 'vinDetail?vin=' + that.vin + '&token=' + item.token + '&param=' +
								item.param + '&access_time=' + that.access_time + '&tabIndex=' + index+'&epc_id='+that.epc_id
						})
					}
				});



			},
			childrenkeyup() {
				this.childrenList = this.oldList;
				if (this.childrenss == '') {

					this.childrenList = this.oldList;
				} else {

					this.childrenList = this.query(this.childrenList, this.childrenss, 'caption')

				}
			},
			query(list, keyWord, attribute = 'caption') {
				const reg = new RegExp(keyWord) // 创建正则表达式
				const arr = []
				for (let i = 0; i < list.length; i++) {
					if (reg.test(list[i][attribute])) {
						arr.push(list[i])
					}
				}
				return arr

			},
		}
	}
</script>

<style scoped>
	.searchImg2 {
		width: 40rpx;
		height: 40rpx;
		margin-top: 16rpx;
		margin-left: 20rpx;
	}

	.searchBox {
		padding-top: 24rpx;
		width: 100vw;
	}

	.inputBox {
		width: 702rpx;
		height: 72rpx;
		background: #F4F5F7;
		border-radius: 36rpx;
		margin-left: 24rpx;
		display: flex;
		position: relative;
	}

	.topInput {
		font-size: 28rpx;
		height: 72rpx;
		line-height: 72rpx;
		padding-left: 16rpx;
		width: 500rpx;
	}

	.top {
		padding: 20rpx 0;
		background-color: #ffffff;
		margin-bottom: ;
	}

	.topCont {
		width: 750rpx;
		height: 160rpx;
		background: #FFFFFF;

	}
	.head-box{
		width: 660rpx;
		height: 160rpx;
		margin: 10rpx auto;
	}
	.searchBtn{
		background-color: #F8FBFF;
		width: 100%;
		height: 75rpx;
		border-radius: 10rpx;
		line-height: 75rpx;
		
	}
	.searchImg{
		width: 27rpx;
		height: 27rpx;
		margin: -6rpx 20rpx;
		
	}
	.image-box{
		background-color: #ffffff;
		width: 80rpx;
		height: 80rpx;
		border-radius: 80rpx;
	}
	/* .head-this-title{
		font-size: 24rpx;
		margin-top: 6rpx;
	} */
	.searchTitle{
		height: 75rpx;
		font-size: 26rpx;
		color: #9E9E9E;
		line-height: 78rpx;
	}
	.cardDetail{
		display: flex;
		flex-direction: row;
		width: 100%;
		margin: 20rpx 0;
	}
	.image-box{
		background-color: #ffffff;
		width: 80rpx;
		height: 80rpx;
		border-radius: 80rpx;
	}
	.detail{
		color: #333333;
		width: 500rpx;
		font-size: 20rpx;
		margin: 20rpx 10rpx;
		
	}
	
	.detailNoVin{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.head-title{
		height: 24rpx;
	}
	.head-this-title{
		font-size: 28rpx;
		
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2; /* 控制显示的行数 */
		overflow: hidden;
		text-overflow: ellipsis;
	
	}
	.novin{
		align-items: center;
	}
	
	
	.content {
		background: #F4F5F7;
		min-height: 100vh;
		width: 100vw;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
	.zdyNavBox {
		width: 100vw;
		background: #FFFFFF;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999999;
	
	}
	
	.zdyNav {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 13rpx 6rpx;
	}
	.zdyNavLeft{
		width: 120rpx;
	}
	
	.zdyNavTitle {
		background: #FFFFFF;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
	}
	
	.zdyNavRight {
		background: #FFFFFF;
		text-align: center;
		font-size: 28rpx;
		color: #3F90F7;
		width: 120rpx;
	}

	.top {
		padding: 20rpx 0;
	}

	.topCont {
		width: 750rpx;
		height: 160rpx;
		background: #FFFFFF;
	}

	.carLogo {
		width: 72rpx;
		height: 72rpx;
	}

	.carTxt {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 36rpx;
		width: 606rpx;
	}

	.carJt {
		width: 25rpx;
		height: 24rpx;
		margin-top: 6rpx;
	}

	.carBox {
		display: flex;
		justify-content: space-between;
		padding: 30rpx 24rpx 24rpx 34rpx;
	}
	
	.carBox2{
		background-color: #FFFFFF;
		padding: 30rpx 24rpx;
	}
	.carTxt2 {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 36rpx;
		/* width: 606rpx; */
		height: 75rpx;
		/* 隐藏文字显示 ...超过2行省略 */
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}
	.vinBox {
		display: flex;
		justify-content: space-between;
		padding-left: 34rpx;
		padding-right: 24rpx;
	}

	.vinBox2 {
		display: flex;
		align-items: center;
	}

	/* .detail {
		color: #3F90F7;
		font-size: 24rpx;
		margin-right: 10rpx;
	} */

	.vinB {
		background: #F19D01;
		width: 60rpx;
		height: 30rpx;
		text-align: center;
		line-height: 30rpx;
		color: #FFFFFF;
		font-size: 22rpx;
		border-radius: 5rpx;
	}

	.vinNum {
		color: #999999;
		font-size: 24rpx;
		line-height: 30rpx;
		padding-left: 10rpx;
	}

	.mainBox {
		background: #FFFFFF;
		width: 100vw;
	}

	.maintitle {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		text-align: center;
		line-height: 88rpx;
		border-bottom: 1px solid #EEEEEE;
		position: relative;
	}

	.backZongImg {
		width: 25rpx;
		height: 24rpx;
		margin-top: 4rpx;
	}

	.backBox {
		display: flex;
		position: absolute;
		left: 23rpx;
		top: 28rpx;
	}

	.backTxt {
		color: #3F90F7;
		font-size: 24rpx;
		line-height: 33rpx;
	}

	.mainLineJt {
		width: 25rpx;
		height: 24rpx;
		margin-top: 8rpx;
	}

	.mainLine {
		display: flex;
		width: calc(100vw - 48rpx);
		border-bottom: 1px solid #EEEEEE;
		padding: 29rpx 24rpx;
	}

	.lineName {
		font-size: 26rpx;
		
		font-weight: bold;
		color: #333333;
		line-height: 40rpx;
		
		
	}

	.mainLine2 {
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #EEEEEE;
		padding: 24rpx;
	}

	.lineName2 {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		line-height: 40rpx;
	}

	.lineIMg {
		width: 160rpx;
		height: 160rpx;
	}

	.lineRIght {
		padding-left: 20rpx;
		padding-right: 24rpx;
	}

	.lineBm {
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		padding: 10rpx 0;
	}

	.linejs {
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		
	}
	.tab-box2{
		width: 360rpx;
		display: flex;
		height: 65rpx;
		align-items: center;
		justify-content: center;
		/* font-size: 32rpx;
		font-weight: bold; */
	}
</style>
