<template>
	<view>
		<ujp-navbar title="车辆管理页面"></ujp-navbar>
		<view v-if="false">
			<view class="carNone" v-if="carList.length == 0">
				<img src="@/assets/static/img/none2.svg" alt="">
				<p class="oldTextjp2" oldstyle="font-size: 18px;">暂无绑定车辆</p>
				<view class="carNone-btn" @click="addCar">
					添加车牌
				</view>
			</view>
			<view class="car" v-else>
				<view class="car-item" v-for="(item,index) in carList" :key="item.id" @click="toCarAdd(item)">
					<span v-if="item.defaultFlag">默认</span>
					<font>{{item.carNum}}</font>
				</view>
				<view class="car-btn oldTextjp2" oldstyle="font-size: 18px;" @click="addCar">添加车牌</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import * as userApi from '@/apis/user.js'
	
	export default {
		data() {
			return {
				carList: [],
				jpcode:"",
			}
		},
		onShow() {
			this.getCarList();
		},
		onLoad(op) {
			if(op.jpcode){
				this.jpcode=op.jpcode
			}
				
		},
		methods: {
			toCarAdd(item) {
				var url='/pages/user/car/carAdd?id=' + item.id;
				if(this.jpcode){
					url+="&jpcode="+this.jpcode
				}
				uni.navigateTo({
					url: url
				})
			},
			getCarList() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})		
				userApi.regUserCarList().then((res) => {
					uni.hideLoading();
					
					this.carList = res.data;
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			addCar() {
				var url='/pages/user/car/carDet' ;
				if(this.jpcode){
					url+="?jpcode="+this.jpcode
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>
<style>
	page{
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.carNone{
		display: flex;
		flex-direction: column;
		justify-content: center;
		height: calc(100vh - 44px);
		align-items: center;
		img{
			width: 256px;
			height: 256px;
		}
		p{
			margin-top: -60px;
		}
		.carNone-btn{
			font-size: 16px;
			color:#00B962;
			border: 1px solid #00B962;
			padding: 10px 70px;
			border-radius: 20px;
			margin-top: 48px;
		}
	}
	.car{
		padding: 24px;
		.car-item{
			margin: 10px;
			background-color: #00B962;
			height: 80px;
			border-radius: 8px;
			position: relative;
			text-align: center;
			font{
				color:#fff;
				font-size: 36px;
				line-height:80px;
			}
			span{
				position: absolute;
				height: 24px;
				width: 48px;
				background-color: #008A4B ;
				color:#fff;
				right: 0;
				top: 0;
				text-align: center;
				line-height: 24px;
				border-radius: 0 8px 0 8px;
			}
		}
		.car-btn{
			margin:12px 10px 0;
			font-size: 16px;
			color:#00B962;
			border: 1px solid #00B962;
			border-radius: 21px;
			padding: 10px 0;
			text-align: center;
			
		}
	}
</style>
