<template>
	<view class="container">
		<!-- 内容区域 -->
		<view class="content">
			<!-- 支付结果状态 -->
			<view class="result-section">
				<!-- 状态图标 -->
				<view class="result-icon" :class="resultIconClass">
					<text class="icon-text">{{ resultIcon }}</text>
				</view>
				
				<!-- 状态文字 -->
				<text class="result-text">{{ resultText }}</text>
				
				<!-- 成功状态显示积分信息 -->
				<view v-if="isSuccess" class="points-info">
					<text class="points-value">{{ pointsValue }}</text>
					<text class="points-unit">积分</text>
				</view>
				
				<!-- 失败状态显示失败原因 -->
				<view v-if="!isSuccess" class="failure-info">
					<text class="failure-reason">{{ failureReason }}</text>
				</view>
				
				<!-- 支付方式信息 - 仅成功状态显示 -->
				<view v-if="isSuccess" class="payment-info">
					<view class="payment-row">
						<text class="payment-label">支付方式</text>
						<text class="payment-value">积分兑换</text>
					</view>
				</view>
			</view>

			<!-- 底部操作按钮 -->
			<view class="action-section">
				<button class="action-btn" @click="handleAction">{{ actionButtonText }}</button>
			</view>

			<!-- 活动banner -->
			<view class="activity-banner">
				<text class="banner-text">活动banner</text>
			</view>
		</view>

		<!-- 客服按钮 -->
		<view class="service-btn">
			<image class="service-icon" :src="$baseUrl + 'homepage/Q3Res/settlementCenter_serviceBtn.png'" mode="aspectFit"></image>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 支付结果数据 - 可根据实际需要修改
			resultData: {
				isSuccess: true, // true: 成功, false: 失败
				pointsValue: '',
				failureReason: '',
				orderId: '', // 订单ID，用于跳转订单详情
				// 新增字段
				goodsName: '',
				goodsImage: '',
				goodsSpec: '',
				quantity: 1,
				creditsTypeName: '积分',
				priceData: '',
				gid: '',
				skuld: '',
				buy_num: 1
			}
		}
	},
	computed: {
		// 是否成功
		isSuccess() {
			return this.resultData.isSuccess;
		},
		
		// 结果图标
		resultIcon() {
			return this.isSuccess ? '✓' : '✕';
		},
		
		// 结果图标样式类
		resultIconClass() {
			return this.isSuccess ? 'icon-success' : 'icon-failure';
		},
		
		// 结果文字
		resultText() {
			return this.isSuccess ? '兑换成功' : '兑换失败';
		},
		
		// 积分值
		pointsValue() {
			return this.resultData.pointsValue;
		},
		
		// 失败原因
		failureReason() {
			return this.resultData.failureReason;
		},
		
		// 操作按钮文字
		actionButtonText() {
			return this.isSuccess ? '查看订单' : '返回首页';
		}
	},
	onLoad(options) {
		console.log('支付结果页面接收到的参数:', options);
		
		// 处理页面参数
		if (options.isSuccess !== undefined) {
			this.resultData.isSuccess = options.isSuccess === 'true';
		}
		if (options.pointsValue) {
			this.resultData.pointsValue = options.pointsValue;
		}
		if (options.failureReason) {
			this.resultData.failureReason = decodeURIComponent(options.failureReason);
		}
		if (options.orderId) {
			this.resultData.orderId = options.orderId;
		}
		
		// 保存其他参数供后续使用
		this.resultData.goodsName = options.goodsName || '';
		this.resultData.goodsImage = options.goodsImage || '';
		this.resultData.goodsSpec = options.goodsSpec || '';
		this.resultData.quantity = parseInt(options.quantity) || 1;
		this.resultData.creditsTypeName = options.creditsTypeName || '积分';
		this.resultData.priceData = options.priceData || '';
		this.resultData.gid = options.gid || '';
		this.resultData.skuld = options.skuld || '';
		this.resultData.buy_num = parseInt(options.buy_num) || 1;
		
		console.log('支付结果数据:', this.resultData);
	},
	methods: {
		// 处理操作按钮点击
		handleAction() {
			if (this.isSuccess) {
				// 查看订单 - 跳转到订单详情页面
				if (this.resultData.orderId) {
					uni.navigateTo({
						url: `/v3/orderDetail/orderDetail?orderId=${this.resultData.orderId}`
					});
				} else {
					// 如果没有订单ID，跳转到订单列表页面
					uni.navigateTo({
						url: '/v3/orderList/orderList'
					});
				}
			} else {
				// 返回首页
				uni.reLaunch({
					url: '/pages/index/index'
				});
			}
		},
		
		// 设置支付结果 - 供外部调用
		setPaymentResult(isSuccess, pointsValue = '', failureReason = '', orderId = '') {
			this.resultData.isSuccess = isSuccess;
			this.resultData.pointsValue = pointsValue;
			this.resultData.failureReason = failureReason;
			this.resultData.orderId = orderId;
		}
	}
}
</script>

<style scoped>
.container {
	width: 100%;
	min-height: 100vh;
	background-color: #f5f5f5;
	box-sizing: border-box;
}


/* 内容区域 */
.content {
	padding: 0;
	box-sizing: border-box;
}

/* 支付结果状态 */
.result-section {
	background-color: #fff;
	padding: 80rpx 30rpx 40rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
}

.result-icon {
	width: 120rpx;
	height: 120rpx;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-bottom: 30rpx;
}

.result-icon.icon-success {
	background-color: #d3a458;
}

.result-icon.icon-failure {
	background-color: #d3a458;
}

.icon-text {
	font-size: 60rpx;
	color: #fff;
	font-weight: bold;
}

.result-text {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
}

.points-info {
	display: flex;
	align-items: baseline;
	margin-bottom: 30rpx;
}

.points-value {
	font-size: 48rpx;
	font-weight: bold;
	color: #d3a458;
}

.points-unit {
	font-size: 32rpx;
	color: #d3a458;
	margin-left: 10rpx;
}

.failure-info {
	margin-bottom: 30rpx;
}

.failure-reason {
	font-size: 28rpx;
	color: #999;
}

.payment-info {
	width: 100%;
}

.payment-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx 0;
}

.payment-label {
	font-size: 28rpx;
	color: #999;
}

.payment-value {
	font-size: 28rpx;
	color: #999;
}

/* 操作按钮区域 */
.action-section {
	padding: 40rpx 30rpx;
	background-color: #fff;
}

.action-btn {
	width: 100%;
	height: 88rpx;
	border-radius: 44rpx;
	font-size: 32rpx;
	font-weight: bold;
	background-color: #fff;
	color: #333;
	border: 1rpx solid #ddd;
}

/* 活动banner */
.activity-banner {
	background-color: #e6e6e6;
	padding: 60rpx 30rpx;
	margin: 20rpx 30rpx;
	border-radius: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.banner-text {
	font-size: 28rpx;
	color: #333;
}

/* 客服按钮 */
.service-btn {
	position: fixed;
	bottom: 200rpx;
	right: 30rpx;
	width: 120rpx;
	height: 120rpx;
	background-color: #d3a458;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
}

.service-icon {
	width: 100%;
	height: 100%;
}
</style>
