<template>
	<view class="vehicle_body">
		<view  v-for="(item,index) in cars" :key="index" class="vehicle_item">
			<view class="vehicle_item_top flex jw ac">
				<view class="vehicle_item_plateNumber">{{item.plateNumber}}</view>
				<view @click="delect(item)">
					<uni-icons type="trash" size="15"></uni-icons>
					<text>删除</text>
				</view>
			</view>
			<view class="vehicle_item_bottom">
				已绑定车辆
			</view>
		</view>
		<view @click="goAdd" class="vehicle_add flex ac ">
			<uni-icons type="plus-filled" size="30"></uni-icons>
			<text>添加车辆</text>
		</view>
	</view>
</template>

<script>
	import station from '@/api/station.js'
	export default {
		data() {
			return {
				cars:[]
			}
		},
		onShow() {
			this.init()
		},
		created() {
		},
		methods: {
			delect(item){
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否确定删除车牌号？',
					success: function (res) {
						if (res.confirm) {
							station.deleteVehicleById(item.id).then(res=>{
								setTimeout(()=>{
									uni.showToast({
										title:'删除成功',
										icon:'none',
										success() {
											that.getcars()
										}
									})
								},1000)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			
			},
			init(){
				this.getcars()
			},
			goAdd(){
				uni.navigateTo({
					url:'/ChargingStation/pages/vehicle/binding/index'
				})
			},
			getcars(){
				station.getVehicleAll().then(res=>{
					this.cars = res.data
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
 @import 'index.scss';
</style>
