<template>
	<view class="negotiation-history-page">
		<view class="history-list" v-if="list.length > 0">
			<view class="history-item" v-for="(item, index) in list" :key="index">
				<!-- 左侧头像 -->
				<view class="avatar-box">
					<image class="avatar" :src="item.imgPath || 'https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/logo3.png'" mode="aspectFill"></image>
				</view>
				
				<!-- 右侧内容 -->
				<view class="content-box">
					<view class="user-info">
						<text class="name">{{ item.userName || '书嗨' }}</text>
						<text class="time">{{ item.createTime }}</text>
					</view>
					
					<view class="message-card">
						<view class="msg-title" v-if="item.title">{{ item.title }}</view>
						<view class="msg-content" v-if="item.content">
							<text>{{ item.content }}</text>
						</view>
						
						<!-- 凭证图片 -->
						<view class="img-grid" v-if="item.imgList && item.imgList.length > 0">
							<image 
								class="grid-img" 
								v-for="(img, imgIndex) in item.imgList" 
								:key="imgIndex" 
								:src="img" 
								mode="aspectFill"
								@click="previewImage(item.imgList, imgIndex)"
							></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty-box" v-else-if="!loading">
			<u-empty text="暂无协商历史" mode="history"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				refundOrderId: '',
				list: [],
				loading: true
			};
		},
		onLoad(options) {
			if (options.refundOrderId) {
				this.refundOrderId = options.refundOrderId;
				this.getList();
			}
		},
		methods: {
			getList() {
				this.loading = true;
				uni.showLoading({ title: '加载中' });
				this.$u.api.refundDisposeListAjax({ refundOrderId: this.refundOrderId }).then(res => {
					uni.hideLoading();
					this.loading = false;
					if (res.code == 200) {
						this.list = res.data || [];
					} else {
						uni.showToast({
							title: res.msg || '获取失败',
							icon: 'none'
						});
					}
				}).catch(() => {
					uni.hideLoading();
					this.loading = false;
				});
			},
			previewImage(imgList, current) {
				uni.previewImage({
					urls: imgList,
					current: current
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.negotiation-history-page {
		min-height: 100vh;
		background-color: #F5F5F5;
		padding: 30rpx;
		
		.history-list {
			background-color: #fff;
			border-radius: 16rpx;
			padding: 30rpx 20rpx;
			
			.history-item {
				display: flex;
				margin-bottom: 40rpx;
				
				&:last-child {
					margin-bottom: 0;
					
					.content-box {
						border-bottom: none;
					}
				}
				
				.avatar-box {
					width: 80rpx;
					margin-right: 20rpx;
					flex-shrink: 0;
					
					.avatar {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						background-color: #eee;
					}
				}
				
				.content-box {
					flex: 1;
					padding-bottom: 40rpx;
					border-bottom: 1rpx solid #F0F0F0;
					
					.user-info {
						display: flex;
						flex-direction: column;
						margin-bottom: 16rpx;
						
						.name {
							font-size: 28rpx;
							font-weight: bold;
							color: #666;
							margin-bottom: 6rpx;
						}
						
						.time {
							font-size: 24rpx;
							color: #999;
						}
					}
					
					.message-card {
						.msg-title {
							font-size: 28rpx;
							font-weight: bold;
							color: #333;
							margin-bottom: 10rpx;
						}
						
						.msg-content {
							font-size: 28rpx;
							color: #333;
							line-height: 1.6;
							word-break: break-all;
						}
						
						.img-grid {
							display: flex;
							flex-wrap: wrap;
							margin-top: 20rpx;
							
							.grid-img {
								width: 160rpx;
								height: 160rpx;
								border-radius: 8rpx;
								margin-right: 16rpx;
								margin-bottom: 16rpx;
								background-color: #f8f8f8;
								
								&:nth-child(3n) {
									margin-right: 0;
								}
							}
						}
					}
				}
			}
		}
		
		.empty-box {
			padding-top: 200rpx;
		}
	}
</style>
