<template>
	<view class="box">
		<homenav :iStatusBarHeight="iStatusBarHeight" :title="'我的车库'" :cj="3"></homenav>
		<view class="carlistBox" style="display: none;">
			<view class="line" v-for="(item,index) in carList" @click="itemClick(item)">
				<view class="lineCont">
					<view>
						<image :src="item.brandLogo" v-if="item.brandLogo" mode="widthFix" class="brandLogo"></image>
						  <img src="../../../static/timg/nocar.png" alt="" class="brandLogo" v-else>
					</view>
					<view style="padding-left: 29rpx;">
						<view class="carName">
						    <span>{{item.plateNumber}}</span>
							<view class="plateNumber" v-if="item.milage">{{item.milage}}km</view>
							<view class="nextCare" v-if="item.nextReturnDate||item.nextCareMilage">
								<image class="carByIcon" src="../../../static/timg/car2.png" mode=""></image>
							   <span class="nextCareTitle">下次保养</span>
							   <span class="nextCaretxt" v-if="item.nextReturnDate">{{item.nextReturnDate}}天后</span>
							   <span class="nextCaretxt" v-if="item.nextReturnDate&&item.nextCareMilage">或</span>
							   <span class="nextCaretxt" v-if="item.nextCareMilage&&item.nextCareMilage>-1">{{item.nextCareMilage}}km</span>
							</view>
						</view>
						<!-- <view class="carMS">{{item.carModel?item.carModel:''}}</view> -->
						<view class="carMS">{{item.brand?item.brand:''}} {{item.series?item.series:''}}</view>
					</view>
				</view>
				<view class="lineBottom">
					<!-- <view class="lineDel" @click.stop="editCar(item.id)">编辑</view> -->
					<view class="lineDel" v-if="openMCar.showType==1" @click.stop="maintain(item)">保养信息</view>
					<!-- <view class="Default" v-show="item.isDefault!=1" @click.stop="defaultCar(item)">设为默认</view>
					<view class="DefaultYES" v-show="item.isDefault==1">已设为默认</view> --> 
				</view>
				<view class="DefaultIcon" v-show="item.isDefault==1">默认</view>
			</view>
		</view>
		<view class="carlistBox">
			<view class="line" v-for="(item,index) in carList" @click="itemClick(item)">
				<view class="lineTop">
					<view class="lineplateNumber">{{item.plateNumber}}</view>
					<view class="lineSx1"></view>
					<view class="linekk">
						<view class="linekkrow" v-if="item.nextCareMilage" style="color: #333333;font-size: 24rpx;">{{item.nextCareMilage}}km</view>
						<view class="linekkrow" v-else>-</view>
						<view class="linekkrow">建议下次</view>
						<view class="linekkrow" >保养里程</view>
					</view>
					<view class="lineSx"></view>
					<view class="linekk">
						<view class="linekkrow" v-if="item.nextCareDate" style="color: #333333;font-size: 24rpx;">{{item.nextCareDate.slice(0,10)}}</view>
						<view class="linekkrow" v-else>-</view>
						<view class="linekkrow">建议下次</view>
						<view class="linekkrow" >保养日期</view>
					</view>
				</view>
				<view class="lineBottom">
					 <view class="lineDel" @click.stop="editCar(item.id)">编辑</view>
					<view class="lineDel"  @click.stop="maintain(item)">保养信息</view>
				</view>
				<view class="DefaultIcon2"  v-show="item.isDefault==1">默认</view>
			</view>
		</view>
		<view v-if="carList==''&&loding" class="nodataBox">

			<image src="http://dmsphoto.66km.com.cn/thFiles/3C95A4C5-73F8-4B34-902B-703B8A0825C9.png" mode="widthFix" class="nodataImg"></image>

			<view class="noTxt">暂无数据</view>
		</view>



		<view class="bottomView">
			<view class="saveCar" :style="{background:'#'+themeColor}" @click="addBtn">
				<view>添加爱车</view>
			</view>
		</view> 
		
		<!-- 手机号授权 -->
			<view class="authorizBox" v-if="authorizShow" @click="authorizShow=false">
				<view class="authorizCont" @click.stop="">
					<view class="authorizName">{{wxOpenData.miniAppName}}</view>
					<view class="authorizMs">您好，欢迎访问本店，授权手机号登录能获取我们最新的促销活动哦~</view>
					<button class="authorizContbutton" type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">授权</button>
				</view>
				<view style="text-align: center;padding-top: 56rpx;">
					<image src="../../../static/timg/icon_guanbi@2x.png" mode="" class="authorizCloseImg"></image>
				</view>
			</view>

	</view>
</template>

<script>
	import homenav from "@/components/homenav/nav.vue"
	export default {
		components: {
			homenav
		},
		data() {
			return {
				carList: '',
				loding: false,
				type: '',
				carId: '',
				fromMe: false,
				themeColor:'',
				iStatusBarHeight:'',
				openMCar:'',
				userInfo:'',
				ext:'',
				wxOpenData:'',
				authorizShow:false,
				code:'',
			}
		},
		onLoad(opt) {
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.$common.isUserId()
			this.type = opt.type;
			// console.log(this.type)
			this.fromMe = opt.fromMe
			 this.themeColor = uni.getStorageSync("themeColor");
            this.openMCar=uni.getStorageSync("openMCar");
			this.userInfo=this.$store.state.userInfo;
			this.ext=this.$common.getExtStoreId();
			if(this.userInfo){
				this.getqueryMyBMemberCar()
			}else{
				this.$common.automaticlogin().then(val => {
					this.userInfo=this.$store.state.userInfo;
					this.wxOpenData=this.$store.state.wxOpenData;
					this.themeColor = uni.getStorageSync("themeColor");
					this.getqueryMyBMemberCar();
					if(!this.userInfo){
						this.authorizShow=true
					}
				})
			}
		},
		onShow() {
			this.getqueryMyBMemberCar();
			this.carId = uni.getStorageSync("maintainCarData").id
		},
		methods: {
			decryptPhoneNumber: function(e) {
			  console.log(e);
			  this.code=e.detail.code
			  this.wxPhoneLogin()
			  this.authorizShow=false;
			},
			wxPhoneLogin(){
					 var that=this;
					 this.$http('miniApp2/sys/wxPhoneLogin', {
					   appId:this.ext.appId,
					   unionId:this.ext.unionId,
					   code:this.code,
					   openId:this.wxOpenData.openid
					  },'POST').then(res => {
						var data = res.data;
						if(data.loginInfo){
							this.userInfo=data.loginInfo.openUser;
							this.wxOpenData=data.loginInfo;
							this.$store.commit('mutationswxOpenData', data)
							this.$store.commit('mutationsuserInfo', this.userInfo)
						    this.getqueryMyBMemberCar()
						}	
					  })
			},
			
			maintain(item){
				uni.navigateTo({
					
					url:'../../index/handbook?mileage='+item.milage+'&liyangId='+item.nLevelID
				})
			},
			getqueryMyBMemberCar() {
				uni.showLoading({
					title: '加载中'
				})
				this.loding = false;
				this.$http('opencarOwnerHome/queryCarInfoList', {

				}, 'GET').then(res => {
					uni.hideLoading();
					this.carList = res.data;
					this.loding = true;
				})
			},
			addBtn() {
				uni.navigateTo({
					url: 'addCar'
				})
				
				
	

			},
			editCar(id) {

				uni.navigateTo({
					url: 'addCar?id=' + id + '&isEditCar=true'
				})
			},
			itemClick(item){
				if(this.type!=3){
					this.$store.commit('mutationscarInfo', item)
					uni.navigateBack({
					 	delta: 1
					})
				}
				
			},
			
			
		},
		
		// 下拉刷新
		onPullDownRefresh() {
			// this.page = 1
			this.getqueryMyBMemberCar()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		
	}
</script>

<style scoped>
	.lineTop{
		display: flex;justify-content: space-between;
		color: #3C3C3C;
		font-size: 30rpx;
	}
	.linekk{
		text-align: center;
		color: #999999;
		font-size: 22rpx;
		line-height: 36rpx;
		width: 32%;
	}
	.lineSx1{
		width: 2rpx;height: 60rpx;
		background: #DDDDDD;margin-top: 24rpx;
	}
	.lineSx{
		width: 2rpx;height: 80rpx;
		background: #DDDDDD;margin-top: 14rpx;
	}
	.lineplateNumber{
		font-weight: 600;
		display: flex;
	    align-items: center;
		width: 32%;
		justify-content: center;
	}
	.carByIcon{
		width: 34rpx;height: 34rpx;
	}
	.nextCaretxt{
		color: #FF0000;
	}
	.nextCare{
		font-size: 20rpx;
		line-height: 36rpx;
		display: flex;
		padding-left: 6rpx;
	}
	.box {
		min-height: 100vh;
		background: #F4F5F7;
		padding-bottom: 120rpx;
	}

	.nodataImg {
		width: 400rpx;
		padding-top: 100rpx;
	}

	.noTxt {
		font-size: 36rpx;
		color: #999999;
		padding-top: 50rpx;
	}

	.nodataBox {
		text-align: center;
	}

	.bottomView {
		background-color: #FFFFFF;
		width: 100%;
		height: 120rpx;
		position: fixed;
		bottom: 0rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	.saveCar {

		background: #D53533;
		margin: 23rpx 30rpx;
		height: 74rpx;

		border-radius: 37rpx;
		color: #FFFFFF;
		font-size: 30rpx;
		font-weight: bold;

		align-items: center;
		display: flex;
		justify-content: center;
	}

	.carlistBox {
		padding-bottom: 120rpx;
	}

	.carlistBox {
		padding: 24rpx;
		padding-bottom: 120rpx;
	}

	.brandLogo {
		width: 63rpx;
		height: 63rpx;
	}

	.line {
		background: #FFFFFF;
		padding: 20rpx 20rpx;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
		position: relative;
	}

	.lineCont {
		display: flex;
	}

	.carName {
		color: #3C3C3C;
		font-size: 30rpx;
		display: flex;
	}

	.plateNumber {
		border-radius: 4px;
		border: 1px solid #F19D01;
		height: 32rpx;
		line-height: 32rpx;
		padding: 0 10rpx;
		color: #F19D01;
		font-size: 22rpx;
		margin-left: 20rpx;
		margin-top: 5rpx;

	}

	.carMS {
		color: #666666;
		font-size: 26rpx;
		padding-top: 5px;
	}

	.lineBottom {
		display: flex;
		justify-content: flex-end;
		padding-top: 30rpx;
	}

	.lineDel {
		/* width: 94rpx; */
		height: 50rpx;
		border-radius: 25rpx;
		border: 1px solid #DDDDDD;
		text-align: center;
		line-height: 50rpx;
		font-size: 26rpx;
		color: #3C3C3C;
		margin-left: 29rpx;
		padding: 0 20rpx;
	}

	.Default {
		width: 148rpx;
		height: 50rpx;
		border-radius: 25rpx;
		border: 1px solid #FF4F00;
		line-height: 50rpx;
		text-align: center;
		color: #FF4F00;
		font-size: 26rpx;
	}

	.DefaultYES {
		width: 148rpx;
		height: 50rpx;
		border-radius: 25rpx;
		border: 1px solid #DDDDDD;
		line-height: 50rpx;
		text-align: center;
		color: #999999;
		font-size: 26rpx;
	}

	.DefaultIcon {
		position: absolute;
		top: 0;
		right: 0;
		width: 109rpx;
		height: 40rpx;
		background: linear-gradient(131deg, #FFA72C 0%, #FF450F 100%);
		border-radius: 0px 10rpx 0px 10rpx;
		text-align: center;
		line-height: 40rpx;
		color: #FFFFFF;
		font-size: 22rpx;
	}
	.DefaultIcon2{
		position: absolute;
		top: 0;
		left: 0;
		width: 109rpx;
		height: 40rpx;
		background: linear-gradient(131deg, #FFA72C 0%, #FF450F 100%);
		border-radius: 10px 0rpx 10px 0rpx;
		text-align: center;
		line-height: 40rpx;
		color: #FFFFFF;
		font-size: 22rpx;
	}
	
	.authorizBox{
			width: 100vw;
			height: 100vh;
			background: rgba(0, 0, 0, 0.5);
			position: fixed;
			top: 0;
			left: 0;
		}
		.authorizCont{
			margin-top: 30vh;
			width: 564rpx;
			height: 408rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			margin-left: 93rpx;
			position: relative;
		}
		.authorizCloseImg{
			width: 62rpx;
			height: 62rpx;
		}
		.sqLogoBox{
			width: 180rpx;
			height: 180rpx;
			background: #FFFFFF;
			border-radius: 90rpx;
			text-align: center;
			position: absolute;
			top: -50rpx;
			left: 192rpx;
		}
		.authorizName{
			color: #333333;
			line-height: 42rpx;
			font-size: 30rpx;
			text-align: center;
			padding-top: 58rpx;
		}
		.authorizMs{
			color: #999999;
			line-height: 36rpx;
			font-size: 26rpx;
			width: 452rpx;
			padding-top: 24rpx;
			text-align: center;
			margin-left: 56rpx;
		}
		.authorizContbutton{
			width: 422rpx;
			height: 88rpx;
			background: #D53533;
			border-radius: 44rpx;
			line-height: 88rpx;
			text-align: center;
			font-size:30rpx;
			color: #FFFFFF;
			margin-top: 62rpx;
			margin-left:71rpx;
		}
		.shopBoxpt{
			margin-top: 20rpx;
		}
		button::after{
		 	border: none;
		}
		button{
			position: relative;
			display: block;
			margin-left: 0;
			margin-right: 0;
			padding-left: 0px;
			padding-right: 0px;
			box-sizing: border-box;
			// font-size: 18px;
			text-align: center;
			text-decoration: none;
			// line-height: 1;
			line-height: 1.35;
			// border-radius: 5px;
			-webkit-tap-highlight-color: transparent;
			overflow: hidden;
			color: #000000;
			background-color: #fff;
			
			height: 100%;
			}
</style>
