<template>
	<view class="page">
		<view class="box-info">
			<view class="title margin-bottom">商品详细</view>
			<view class="flex top">
				<image :src="detail.goodsCover" style="width: 140rpx;height: 140rpx;margin-right: 18rpx;"></image>
				<view class="flex-1">
					<view class="title" style="margin-bottom: 60rpx;">{{ detail.goodsName}}</view>
					<view class="flex justify-between" style="width: 100%;">
						<text>数量：{{ orderDetail.redeemNum }}</text>
						<view class="flex align-center">
							<text class="cuIcon-rechargefill"
								style="color: #FEE034;margin-right:12rpx;font-size: 36rpx;"></text>
							{{detail.redeemedNum}}
						</view>
					</view>
				</view>
			</view>

			<view style="padding: 40rpx 0 0px;">
				<view class="flex align-center justify-end margin-bottom">合计：<text class="cuIcon-rechargefill"
						style="color: #FEE034;margin-right:12rpx;font-size: 36rpx;">
					</text>{{ totalNum}}</view>
				<view class="flex align-center justify-end" style="font-size: 20rpx;color: #5E5F60;">
					<image src="/static/info-circle.png" style="width: 40rpx;height: 40rpx;"></image>
					兑换取消后啤酒币不可恢复
				</view>
			</view>

		</view>

		<view class="box-info">
			<view class="title margin-bottom">订单信息</view>
			<view class="order-item flex justify-start">
				<view style="width: 150rpx;">订单号</view>
				<view>{{ orderDetail.orderSn }}</view>
			</view>
			<view class="order-item flex justify-start">
				<view style="width: 150rpx;">支付方式</view>
				<view>啤酒币兑换</view>
			</view>
			<view class="order-item flex justify-start">
				<view style="width: 150rpx;">下单时间</view>
				<view>{{ orderDetail.createTime }}</view>
			</view>
			<view class="order-item flex justify-start">
				<view style="width: 150rpx;">支付时间</view>
				<view>{{ orderDetail.paidTime }}</view>
			</view>
		</view>

		<view class="fun-box">

			<view class="btn" @click="handleRedeem">
				联系客服
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getGoodsInfo,
		getOrderView
	} from "@/api/bar.js"
	export default {
		data() {
			return {
				goodsId: '', // 商品id
				orderId: '', // 订单id
				detail: {},
				orderDetail: {},
				num: 0,
				form: {
					goodsNum: 1,
					goodsId: '',
				}
			};
		},
		onLoad({
			goodsId,
			orderId
		}) {
			console.log(goodsId, orderId)
			this.goodsId = goodsId
			this.orderId = orderId
			this.form.goodsId = goodsId
			this.getDetailFun()
			this.getOrderViewFun()
		},
		computed: {
			totalNum() {
				return this.detail.redeemedNum * this.orderDetail.redeemNum
			}
		},
		methods: {
			// 获取订单详情
			getOrderViewFun() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getOrderView(this.orderId).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.orderDetail = res.data
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			// 获取详情
			getDetailFun() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getGoodsInfo(this.goodsId).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.detail = res.data
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			// 联系客服
			handleRedeem() {
				uni.navigateTo({
					url: '/pagesMy/addAiad'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background: #F2F2F2;
		padding: 32rpx;

		.box-info {
			background: #FFFFFF;
			padding: 40rpx 32rpx;
			border-radius: 12rpx;
			margin-bottom: 32rpx;

			.title {
				font-size: 32rpx;
				font-weight: 500;
				color: #0B0E26;
				// margin-left: 20rpx;
			}

			.top {
				padding: 20rpx 0 40rpx;
				border-bottom: 1px dashed #D8D8D8;

				.btn {
					width: 50rpx;
					height: 50rpx;
					border-radius: 6rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 36rpx;
					color: #000000;
					margin: 0 20rpx;
					border: 1px solid #979797;
				}
			}

			.order-item {
				padding: 24rpx 0 20rpx;
				border-top: 1px dashed #D8D8D8;
				font-family: Roboto;
				font-size: 24rpx;
				font-weight: normal;
				color: #484C4F;
			}
		}

		.fun-box {
			position: fixed;
			left: 0;
			width: 100%;
			bottom: 0;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			padding: 40rpx 32rpx 40rpx 64rpx;
			padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
			padding-bottom: calc(24rpx + env(safe-area-inset-bottom));

			.btn {
				width: 150rpx;
				height: 72rpx;
				background: #39E5B1;
				border-radius: 12rpx;
				font-size: 20rpx;
				color: #0B0E26;
				;
				text-align: center;
				line-height: 72rpx;
			}
		}
	}
</style>