<!--
 * @Author: euzhi
 * @Description: 爱车管理
-->
<template>
<view class="appCotent">
<div class="loveCar">
    <div class="love-car__title">
        我的爱车
    </div>
    <div class="love-car__list">
        <div class="love__item" v-for="(vo,inx) in carList" :key="inx" @click="goGetPrice(vo.id)">
            <div class="itme__img">
                <image src="@/static/move-car/love-car6.png" />
            </div>
            <div class="item__title">
                {{vo.brand}}-{{vo.carModel}}
            </div>
            <div class="item__edit" @click="editCar(vo.id)">
                <image src="@/static/move-car/love-car2.png" />
            </div>
            <div class="item__del" @click="deleteModal(vo.id)">
                <image src="@/static/move-car/love-car3.png" />
            </div>
        </div>
    </div>
	<div>
		<u-modal :show="deleteShow" :title="deleteTitle" :content='deleteContent'
			@confirm="confirmModal" @cancel="cancelModal" showCancelButton="true"></u-modal>
	</div>
    <div class="love__btn" @click="addCar">
        <image src="@/static/move-car/love-car5.png"> 添加车辆
    </div>
</div>
</view>
</template>

<script>
export default {
    data() {
        return {
			carList: [],
			deleteShow: false,
			deleteTitle: '删除车辆',
			deleteContent: '确定删除车辆？',
			carId: '',
			price: '',
        };
    },
    methods: {
        addCar() {
            uni.navigateTo({
                url: '/pagesB/pages/move-car/addCar'
            })
        },
        editCar(id) {
            uni.navigateTo({
                url: '/pagesB/pages/move-car/editCar?id='+id
            })
        },
		//打开确认删除框
		deleteModal(id){
			this.deleteShow = true
			this.carId = id
		},
		//确认删除车辆
		confirmModal(){
			let opts = { url: '/app/vehicleAdmin/remove/' + this.carId, method: 'delete' };
			this.http.httpTokenRequest(opts, {}).then(res => {
				if (res.data.code == 200) {
					uni.showToast({
						title: '删除成功',
						icon: "success",
					});
					this.getCarList()
				}else{
					uni.showToast({
						title: res.data.msg,
						icon: "error",
					});
				}
			})
			this.deleteShow = false
		},
		cancelModal(){
			this.deleteShow = false
		},
		getCarList(){
			let opts = { url: '/app/vehicleAdmin/list', method: 'get' };
			this.http.httpTokenRequest(opts, {}).then(res => {
				if (res.data.code == 200) {
					this.carList = res.data.rows
				}
			})
		},
		goGetPrice(id){
			if(this.price == 1){
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]
				prevPage.$vm.carId = id;
				uni.navigateBack({
					delta: 1
				})
			}
		}
    },
	onShow(){
		this.getCarList()
	},
	onLoad(e) {
		this.price = e.price
	},
	
}
</script>

<style lang="scss" scoped>
.loveCar {
    padding: 40rpx;

    .love-car__title {
        font-size: 38rpx;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
        position: relative;
        z-index: 999;
        margin-bottom: 30rpx;
    }

    .love-car__title::before {
        content: "";
        width: 76rpx;
        height: 14rpx;
        display: inline-block;
        background: url('@/static/move-car/love-car1.png') no-repeat;
        background-size: contain;
        position: absolute;
        bottom: 7rpx;
        z-index: -1;

    }

    .love-car__list {
        margin-bottom: 60rpx;

        .love__item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: #FFFFFF;
            box-shadow: 0rpx 0rpx 28rpx 1rpx rgba(232, 232, 232, 0.2);
            border-radius: 20rpx;
            padding: 30rpx;
            margin-bottom: 30rpx;

            .itme__img {
                image {
                    width: 100rpx;
                    height: 100rpx;
                }
            }

            .item__title {
                font-size: 32rpx;
                font-family: PingFang SC;
                font-weight: 500;
                color: #333333;
                line-height: 48rpx;
                width: 350rpx;
            }

            .item__edit {
                image {
                    width: 32rpx;
                    height: 34rpx;
                }
            }

            .item__del {
                image {
                    width: 33rpx;
                    height: 36rpx;
                }
            }
        }
    }

    .love__btn {
        height: 76rpx;
        background: url('@/static/move-car/love-car4.png') no-repeat;
        background-size: contain;
        font-size: 32rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #FFFFFF;
        line-height: 76rpx;
        text-align: center;

        image {
            width: 30rpx;
            height: 30rpx;
            margin-right: 20rpx;

        }
    }
}
</style>
