<template>
	<view class="">
		<radio-group @change="radioChange">
			<view class="setMeal" v-for="(item, index) in setMealList" :key="index" @tap="goBack(item)">
				<view class="">
					<view class="classBody">
						<view class="">
							<image class="classImg" :src="baseImagePath +item.imgUrl">
						</view>
						<view style="padding: 0 0 0 22rpx;">
							<view class="classBodyHead">
								{{item.name}}
							</view>
							<view class="classBodyContent">
								{{item.title}}
							</view>
						</view>
						<view class="viewRight">
							剩
							<view style="font-weight: bold;font-size: 26rpx;">
								{{item.surplusSum}}
							</view>
							次
						</view>
					</view>
					<view class="border">
						<view class="classTime">
							有效期至{{item.invalidDay}}
						</view>
						<radio style="line-height: 66rpx;" color="#0078FF" :value="index" :checked="id==index+1" />
					</view>
				</view>
			</view>
		</radio-group>
	</view>
</template>

<script>
	import {
		getMyPackage
	} from "@/api/carWash.js"
	export default {
		data: function() {
			return {
				id: 0,
				baseImagePath: this.baseImagePath,
				setMealList: [],
				pageNo:1,
				pageSize:10,
				shopId:"",
				carId:"",
				carWashType:""
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			this.id = parseInt(option.id);
			this.setMealList = JSON.parse(option.setMealList);
			this.shopId =option.shopId;
			this.carId = option.carId;
			this.carWashType = option.carWashType;
			this.getMyPackage();
			for (let index in this.setMealList) {
				let dateTime = Number(this.setMealList[index].invalidDay)
				let date = new Date(dateTime);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				this.setMealList[index].invalidDay =  y + '.' + MM + '.' + d
			}
		},
		onReachBottom() {
			this.getMyPackage()
		},
		methods: {
			radioChange(e) {

			},
			getMyPackage(){
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					carwashcode:this.carWashType,
					shopId:this.shopId,
					carId:this.carId
				}
				let that = this;
				// debugger
				getMyPackage(data).then((res) => {
					this.setMealList = [...this.setMealList,...res.data.data]
					// that.pageNo++
				})
			},
			goBack(datas) {
				uni.$emit('setMeal', datas)
				uni.navigateBack({
					delta: 1
				})
			},
		},
	}
</script>

<style>
	page {
		background: #EDEDED;
	}

	.setMeal {
		width: 710rpx;
		height: 232rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin-left: 20rpx;
		margin-top: 20rpx;

	}

	.classBody {
		width: 100%;
		display: flex;
		padding: 28rpx 28rpx 0 28rpx;
	}

	.classImg {
		width: 120rpx;
		height: 120rpx;
		/* background: linear-gradient(135deg, #D10498 0%, #D21728 100%); */
		border-radius: 8rpx;
	}

	.classBodyHead {
		height: 31rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 31rpx;
	}

	.classBodyContent {
		width: 370rpx;
		height: 23rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		line-height: 31rpx;
		padding-top: 22rpx;
	}

	.viewRight {
		display: flex;
		height: 100%;
		margin-left: 68rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		line-height: 31rpx;
	}

	.border {
		display: flex;
		justify-content: space-between;
		width: 660rpx;
		height: 84rpx;
		margin-left: 25rpx;
		height: 1px;
		border-top: 1px dashed #D4D4D4;
	}

	.classTime {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #0062FF;
		line-height: 66rpx;
	}
</style>
