<template>
	<view class="page-content">
		<!-- 发货状态卡片 -->
		<view class="section">
			<view class="section-title">发货状态</view>
			<view class="delivery-status">
				<view class="status-timeline">
					<view class="status-item" :class="{ active: orderDetail.status >= 1, completed: orderDetail.status > 1 }">
						<view class="status-dot">
							<view class="dot-inner"></view>
							<view class="dot-outer"></view>
						</view>
						<text class="status-text">待发货</text>
						<text class="status-time" v-if="orderDetail.status > 1">{{ orderDetail.createTime }}</text>
					</view>
					<view class="status-line" :class="{ active: orderDetail.status >= 2 }"></view>
					<view class="status-item" :class="{ active: orderDetail.status >= 2, completed: orderDetail.status > 2 }">
						<view class="status-dot">
							<view class="dot-inner"></view>
							<view class="dot-outer"></view>
						</view>
						<text class="status-text">已发货</text>
						<text class="status-time" v-if="orderDetail.status > 2">{{ orderDetail.shipTime }}</text>
					</view>
					<view class="status-line" :class="{ active: orderDetail.status >= 3 }"></view>
					<view class="status-item" :class="{ active: orderDetail.status >= 3 }">
						<view class="status-dot">
							<view class="dot-inner"></view>
							<view class="dot-outer"></view>
						</view>
						<text class="status-text">已完成</text>
						<text class="status-time" v-if="orderDetail.status >= 3">{{ orderDetail.completeTime || '待完成' }}</text>
					</view>
				</view>
			</view>
			
			<!-- 物流信息 -->
			<view class="delivery-section">
				<view class="section-header">
					<view class="tab-group">
						<view class="tab-item" :class="{ active: activeTab === 'address' }" @click="switchTab('address')">
							<text>收货信息</text>
						</view>
						<view class="tab-item" :class="{ active: activeTab === 'logistics' }" @click="switchTab('logistics')">
							<text>物流信息</text>
						</view>
					</view>
					<view class="tab-line">
						<view class="tab-indicator" :style="{ transform: `translateX(${activeTab === 'address' ? '0' : '100%'})` }"></view>
					</view>
				</view>
				
				<swiper class="delivery-swiper" :current="activeTab === 'address' ? 0 : 1" @change="handleSwiperChange">
					<swiper-item>
						<view class="delivery-info">
							<view class="info-item">
								<text class="item-label">收货人</text>
								<text class="item-value">{{ orderDetail.barName || '暂无' }}</text>
							</view>
							<view class="info-item">
								<text class="item-label">联系电话</text>
								<text class="item-value">{{ orderDetail.contactPhone || '暂无' }}</text>
							</view>
							<view class="info-item">
								<text class="item-label">收货地址</text>
								<text class="item-value">{{ orderDetail.address || '暂无' }}</text>
							</view>
						</view>
					</swiper-item>
					<swiper-item>
						<view class="logistics-info" v-if="orderDetail.status >= 2">
							<view class="info-item">
								<text class="item-label">物流公司</text>
								<text class="item-value">{{ orderDetail.logisticsCompany || '暂无' }}</text>
							</view>
							<view class="info-item">
								<text class="item-label">快递单号</text>
								<text class="item-value">{{ orderDetail.trackingNumber || '暂无' }}</text>
							</view>
							<view class="info-item">
								<text class="item-label">发货时间</text>
								<text class="item-value">{{ orderDetail.shipTime || '暂无' }}</text>
							</view>
						</view>
						<view class="empty-logistics" v-else>
							<text class="empty-text">暂无物流信息</text>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		
		<!-- 商品信息卡片 -->
		<view class="section">
			<view class="section-title">商品详情</view>
			<view class="goods-info">
				<image class="goods-image" :src="detail.goodsCover" mode="aspectFill"></image>
				<view class="goods-detail">
					<text class="goods-name">{{ detail.goodsName}}</text>
					<view class="specs-info" v-if="detail.specs">
						<text class="specs-label">规格：</text>
						<text class="specs-value">{{detail.specs}}</text>
					</view>
					<view class="price-info">
						<view class="coin-amount">
							<text class="amount">{{detail.redeemedNum}}</text>
							<text class="cuIcon-rechargefill coin-icon"></text>
						</view>
						<text class="price-label">/件</text>
					</view>
				</view>
			</view>
			
			<!-- 数量信息 -->
			<view class="quantity-info">
				<text class="info-label">兑换数量</text>
				<text class="info-value">{{ orderDetail.redeemNum }}件</text>
			</view>
			
			<!-- 合计信息 -->
			<view class="total-info">
				<view class="total-row">
					<text class="total-label">合计</text>
					<view class="total-amount">
						<text class="amount">{{ totalNum}}</text>
						<text class="cuIcon-rechargefill coin-icon"></text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 订单信息卡片 -->
		<view class="section">
			<view class="section-title">订单信息</view>
			<view class="order-info">
				<view class="info-item">
					<text class="item-label">订单号</text>
					<text class="item-value">{{ orderDetail.orderSn }}</text>
				</view>
				<view class="info-item">
					<text class="item-label">支付方式</text>
					<text class="item-value">啤酒币兑换</text>
				</view>
				<view class="info-item">
					<text class="item-label">下单时间</text>
					<text class="item-value">{{ orderDetail.createTime }}</text>
				</view>
				<view class="info-item">
					<text class="item-label">支付时间</text>
					<text class="item-value">{{ orderDetail.paidTime }}</text>
				</view>
			</view>
		</view>
		
		<!-- 底部操作栏 -->
		<view class="bottom-bar">
			<view class="back-button" @click="goBack">
				<text>返回</text>
			</view>
			<view class="action-button" @click="handleRedeem">
				<text>联系客服</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getGoodsInfo,
		getOrderView
	} from "@/api/bar.js"
	export default {
		data() {
			return {
				goodsId: '', // 商品id
				orderId: '', // 订单id
				detail: {},
				orderDetail: {},
				num: 0,
				activeTab: 'address', // 当前激活的标签
				form: {
					goodsNum: 1,
					goodsId: '',
				}
			};
		},
		onLoad({
			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'
				})
			},
			goBack() {
				uni.navigateBack()
			},
			switchTab(tab) {
				this.activeTab = tab;
			},
			handleSwiperChange(e) {
				this.activeTab = e.detail.current === 0 ? 'address' : 'logistics';
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page-content {
		min-height: 100vh;
		background: #F6F7FB;
		padding: 32rpx;
		padding-bottom: calc(32rpx + env(safe-area-inset-bottom) + 180rpx);
		
		/* 卡片通用样式 */
		.section {
			background: #FFFFFF;
			border-radius: 24rpx;
			padding: 32rpx;
			margin-bottom: 32rpx;
			box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.08);
			
			.section-title {
				font-size: 40rpx;
				font-weight: 600;
				color: #333333;
				margin-bottom: 32rpx;
				position: relative;
				padding-left: 24rpx;
				
				&::before {
					content: '';
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
					width: 8rpx;
					height: 40rpx;
					background: #19367A;
					border-radius: 4rpx;
				}
			}
		}
		
		/* 发货状态样式 */
		.delivery-status {
			padding: 32rpx 0;
			
			.status-timeline {
				display: flex;
				justify-content: space-between;
				align-items: flex-start;
				position: relative;
				padding: 0 16rpx;
				
				.status-line {
					flex: 1;
					height: 4rpx;
					background: #E5E5E5;
					margin: 0 16rpx;
					position: relative;
					top: 24rpx;
					transition: all 0.3s ease;
					
					&.active {
						background: linear-gradient(90deg, #19367A, #2C4C99);
					}
				}
				
				.status-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					position: relative;
					z-index: 1;
					
					.status-dot {
						width: 48rpx;
						height: 48rpx;
						position: relative;
						margin-bottom: 16rpx;
						
						.dot-inner {
							position: absolute;
							left: 50%;
							top: 50%;
							transform: translate(-50%, -50%);
							width: 24rpx;
							height: 24rpx;
							border-radius: 50%;
							background: #E5E5E5;
							transition: all 0.3s ease;
						}
						
						.dot-outer {
							position: absolute;
							left: 50%;
							top: 50%;
							transform: translate(-50%, -50%);
							width: 48rpx;
							height: 48rpx;
							border-radius: 50%;
							border: 2rpx solid #E5E5E5;
							transition: all 0.3s ease;
						}
					}
					
					.status-text {
						font-size: 28rpx;
						color: #999999;
						margin-bottom: 8rpx;
						transition: all 0.3s ease;
					}
					
					.status-time {
						font-size: 24rpx;
						color: #999999;
						transition: all 0.3s ease;
					}
					
					&.active {
						.status-dot {
							.dot-inner {
								background: #19367A;
								box-shadow: 0 0 0 4rpx rgba(25, 54, 122, 0.1);
							}
							
							.dot-outer {
								border-color: #19367A;
							}
						}
						
						.status-text {
							color: #19367A;
							font-weight: 500;
						}
						
						.status-time {
							color: #666666;
						}
					}
					
					&.completed {
						.status-dot {
							.dot-inner {
								background: #19367A;
							}
							
							.dot-outer {
								border-color: #19367A;
							}
						}
					}
				}
			}
		}
		
		/* 物流信息样式 */
		.logistics-info {
			padding: 32rpx 0;
			border-top: 2rpx solid #F5F5F5;
			
			.info-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 24rpx;
				
				&:last-child {
					margin-bottom: 0;
				}
				
				.item-label {
					font-size: 28rpx;
					color: #666666;
				}
				
				.item-value {
					font-size: 28rpx;
					color: #333333;
				}
			}
		}
		
		/* 收货信息样式 */
		.delivery-info {
			padding: 32rpx 0 0;
			
			.info-item {
				display: flex;
				justify-content: space-between;
				align-items: flex-start;
				margin-bottom: 24rpx;
				
				&:last-child {
					margin-bottom: 0;
				}
				
				.item-label {
					font-size: 28rpx;
					color: #666666;
					width: 140rpx;
					flex-shrink: 0;
				}
				
				.item-value {
					font-size: 28rpx;
					color: #333333;
					flex: 1;
					text-align: right;
				}
			}
		}
		
		/* 商品信息卡片 */
		.goods-info {
			display: flex;
			align-items: flex-start;
			padding: 24rpx 0;
			border-bottom: 2rpx solid #F5F5F5;
			
			.goods-image {
				width: 160rpx;
				height: 160rpx;
				border-radius: 12rpx;
				margin-right: 24rpx;
				background: #F5F5F5;
			}
			
			.goods-detail {
				flex: 1;
				
				.goods-name {
					font-size: 32rpx;
					color: #333333;
					font-weight: 500;
					margin-bottom: 16rpx;
					line-height: 1.4;
				}
				
				.specs-info {
					display: flex;
					align-items: center;
					margin-bottom: 16rpx;
					
					.specs-label {
						font-size: 28rpx;
						color: #666666;
					}
					
					.specs-value {
						font-size: 28rpx;
						color: #333333;
					}
				}
				
				.price-info {
					display: flex;
					align-items: center;
					
					.coin-amount {
						display: flex;
						align-items: center;
						
						.amount {
							font-size: 36rpx;
							color: #333333;
							font-weight: 600;
						}
						
						.coin-icon {
							color: #FEE034;
							font-size: 36rpx;
							margin-left: 8rpx;
						}
					}
					
					.price-label {
						font-size: 24rpx;
						color: #999999;
						margin-left: 8rpx;
					}
				}
			}
		}
		
		/* 数量信息 */
		.quantity-info {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 32rpx 0;
			border-bottom: 2rpx solid #F5F5F5;
			
			.info-label {
				font-size: 28rpx;
				color: #333333;
			}
			
			.info-value {
				font-size: 28rpx;
				color: #333333;
				font-weight: 500;
			}
		}
		
		/* 合计信息 */
		.total-info {
			padding: 32rpx 0 0;
			
			.total-row {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 16rpx;
				
				.total-label {
					font-size: 28rpx;
					color: #333333;
				}
				
				.total-amount {
					display: flex;
					align-items: center;
					
					.amount {
						font-size: 40rpx;
						color: #333333;
						font-weight: 600;
					}
					
					.coin-icon {
						color: #FEE034;
						font-size: 40rpx;
						margin-left: 8rpx;
					}
				}
			}
		}
		
		/* 订单信息 */
		.order-info {
			.info-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 24rpx 0;
				border-bottom: 2rpx solid #F5F5F5;
				
				&:last-child {
					border-bottom: none;
				}
				
				.item-label {
					font-size: 28rpx;
					color: #666666;
				}
				
				.item-value {
					font-size: 28rpx;
					color: #333333;
				}
			}
		}
		
		/* 底部操作栏 */
		.bottom-bar {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			background: #FFFFFF;
			padding: 32rpx;
			padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-shadow: 0 -4rpx 12rpx rgba(0, 0, 0, 0.05);
			backdrop-filter: blur(10px);
			-webkit-backdrop-filter: blur(10px);
			z-index: 100;
			
			.back-button {
				width: 344rpx;
				height: 88rpx;
				background: #F5F5F5;
				border-radius: 44rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 32rpx;
				color: #333333;
				transition: all 0.3s ease;
				margin-right: 32rpx;
				
				&:active {
					transform: scale(0.98);
					background: #EEEEEE;
				}
			}
			
			.action-button {
				width: 344rpx;
				height: 88rpx;
				background: linear-gradient(135deg, #19367A, #2C4C99);
				border-radius: 44rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 32rpx;
				color: #FFFFFF;
				transition: all 0.3s ease;
				box-shadow: 0 4rpx 16rpx rgba(25, 54, 122, 0.2);
				
				&:active {
					transform: scale(0.98);
					box-shadow: 0 2rpx 8rpx rgba(25, 54, 122, 0.1);
				}
			}
		}
		
		/* 收货和物流信息切换样式 */
		.delivery-section {
			.section-header {
				margin-bottom: 32rpx;
				
				.tab-group {
					display: flex;
					justify-content: space-between;
					margin-bottom: 16rpx;
					
					.tab-item {
						flex: 1;
						text-align: center;
						padding: 16rpx 0;
						font-size: 28rpx;
						color: #666666;
						position: relative;
						transition: all 0.3s ease;
						
						&.active {
							color: #19367A;
							font-weight: 500;
						}
					}
				}
				
				.tab-line {
					height: 2rpx;
					background: #F5F5F5;
					position: relative;
					
					.tab-indicator {
						position: absolute;
						left: 0;
						top: 0;
						width: 50%;
						height: 100%;
						background: #19367A;
						transition: transform 0.3s ease;
					}
				}
			}
			
			.delivery-swiper {
				height: 240rpx;
			}
			
			.empty-logistics {
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				
				.empty-text {
					font-size: 28rpx;
					color: #999999;
				}
			}
		}
	}
</style>