<template>
	<view class="">
		<view class="card">
			<view class="classHead">
				<view class="classBorder">

				</view>
				<view class="classTitle">
					套餐详情
				</view>
			</view>
			<view class="body">
				<image :src="'https://biaodianfuhao.oss-cn-beijing.aliyuncs.com/'+setMeal.packages.imgUrl" alt="">
					<view class="content">
						<view class="title">
							{{setMeal.packages.name}}
						</view>
						<view class="explain">
							<a href="##">购买的套餐仅限选择的车辆使用</a>
						</view>
					</view>
			</view>
		</view>
		<Card titles="使用车辆" :data="setMeal.userCar"></Card>
		<view class="bottomBtn">
			<view class="leftView">
				<view class="unit">
					需支付：
				</view>
				<view class="chooseNum">
					<view style="font-size: 26rpx;">
						￥
					</view>
					<view style="font-size: 56rpx;">
						{{setMeal.price}}
					</view>
				</view>
			</view>
			<view class="rightView" @click="createOrder(setMeal.packages.id,setMeal.userCar.id,setMeal.price)">
				确定
			</view>
		</view>
	</view>

</template>

<script>
	import {
		packageBuy
	} from "@/api/maintain.js"
	import {
		buyPackage
	} from "@/api/myApi.js"
	import Card from '@/components/Card'
	export default {
		components: {
			Card
		},
		data() {
			return {
				setMeal: {
					packages: {},
					userCar: {},
					price: null
				},
				url: "",
				name: "",
				cardMsg: [],
				provider: '',
				payType: 1
			};
		},
		onLoad(options) {
			this.packageBuys(JSON.parse(options.item).id)
		},
		methods: {
			createOrder(packageId, carId, price) {
				let data = {
					packageId: packageId,
					carId: carId,
					payPrice: price,
					payType: this.payType
				}
				console.log(data);
				buyPackage(data).then(res => {
					console.log(res);
					if (this.payType === 1) {
						this.provider = 'wxpay'
					}
					console.log(res.data.wechatOrder);
					uni.requestPayment({
						
						provider: this.provider,
						orderInfo: res.data.wechatOrder,
						success: (res) => {
							console.log('下单支付===============>', res);
							uni.showToast({
								icon: 'none',
								title: '下单成功'
							})
							uni.redirectTo({
								url: '/pages/preCarWash/washOrder/index'
							})
						},
						fail: (res) => {
							console.log(res, '支付失败fail');
							uni.showToast({
								icon: 'none',
								title: '支付失败：' + res.errMsg + '，code：' + res.code +
									'，errCode：' + res.errCode
							})
						}
					})
				})
			},
			packageBuys(id) {
				packageBuy({
					packageId: id
				}).then(res => {
					console.log('获取参数=================>', res);
					this.setMeal = res.data;
				})
			},

		}
	}
</script>

<style lang="less">
	page {
		background: #EDEDED;
	}

	.bottomBtn {
		width: 690rpx;
		height: 110rpx;
		background: #FFFFFF;
		border: 1px solid #EEEEEE;
		box-shadow: 0px 8rpx 17rpx 0px rgba(168, 165, 165, 0.26);
		border-radius: 55rpx;
		margin-left: 30rpx;
		position: absolute;
		bottom: 67rpx;
		z-index: 9998;

		.leftView {
			float: left;
			height: 100%;
			display: flex;
			align-items: center;

			.unit {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				line-height: 31rpx;
				padding-left: 52rpx;
			}

			.chooseNum {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FF3C00;
				line-height: 31rpx;
				display: flex;
				align-items: baseline;
			}
		}

		.rightView {
			float: right;
			width: 210rpx;
			height: 108rpx;
			background: linear-gradient(0deg, #005AFF 0%, #0078FF 100%);
			border-radius: 0 55rpx 55rpx 0;
			font-size: 34rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FEFEFE;
			line-height: 108rpx;
			text-align: center;
		}
	}

	.card {
		width: 94%;
		height: 239rpx;
		margin-left: 3%;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin-top: 28rpx;

		.classHead {
			display: flex;
			padding-top: 28rpx;
			width: 100%;
			height: 28rpx;

			.classBorder {
				width: 5rpx;
				height: 28rpx;
				background: linear-gradient(0deg, #005AFF 0%, #0078FF 100%);
				border-radius: 3rpx;
			}

			.classTitle {
				height: 25rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				padding-left: 28rpx;
				line-height: 28rpx;
			}
		}

		.body {
			display: flex;
			align-items: center;
			padding: 36rpx 0 0 26rpx;

			image {
				width: 120rpx;
				height: 120rpx;
			}

			.content {
				padding-left: 30rpx;

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

				.explain {
					margin-top: 23rpx;

					a {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #005BFF;
						line-height: 31rpx;
						text-decoration: none;
					}
				}
			}
		}
	}
</style>