<template>
	<view class="contentStyle">
	<!-- 	<view class="status-bar"></view>
		<uni-nav-bar title="投诉详情" backgroundColor="transparent" :border="false" left-icon="left" @clickLeft="goBack">
		</uni-nav-bar> -->

		<!-- 表单区域 -->
		<scroll-view class="page" scroll-y>
			<view class="page-container">
				<!-- 投诉状态 -->
				<view class="status-section">
					<view class="section-title">
						<text class="title-line"></text>
						<text class="title-text">投诉状态</text>
					</view>
					<text class="status-value" :class="statusClass">{{ statusText }}</text>
				</view>
				<view class="completedDesc" v-if="detail.status === '2' && detail.handleContent">
					{{ detail.handleContent }}
				</view>

				<!-- 投诉详情 -->
				<view class="detail-section">
					<view class="section-title">
						<text class="title-line"></text>
						<text class="title-text">投诉详情</text>
					</view>

					<view class="info-item">
						<text class="info-label">投诉类型</text>
						<text class="info-value">{{ detail.typeName}}</text>
					</view>

					<view class="info-item desc-item">
						<text class="info-label">问题描述</text>
						<text class="info-value desc-value">{{ detail.problemDes }}</text>
					</view>

					<view class="info-item">
						<text class="info-label">投诉人姓名</text>
						<text class="info-value">{{ detail.complaintName }}</text>
					</view>

					<view class="info-item">
						<text class="info-label">手机号码</text>
						<text class="info-value">{{ detail.phone}}</text>
					</view>

					<view class="photo-section" v-if="photoList.length > 0">
						<text class="photo-label">问题照片</text>
						<view class="photo-list">
							<image v-for="(img, index) in photoList" :key="index" :src="img" mode="aspectFit"
								class="photo-item" @click="previewImage(index)"></image>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script setup>
import { ref, computed } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getComplainDetail } from '../api/apiSub.js'

const id = ref('')

const detail = ref({})
const photoList = ref([])

// 状态映射
const statusMap = {
	'0': { text: '待处理', class: 'pending' },
	// '1': { text: '处理中', class: 'processing' },
	'1': { text: '已完成', class: 'completed' }
}

const statusText = computed(() => {
	return statusMap[detail.value.status]?.text || '待处理'
})

const statusClass = computed(() => {
	return statusMap[detail.value.status]?.class || 'pending'
})

onLoad((option) => {
	id.value = option.id || ''
	if (id.value) {
		detailData()
	}
})
// 获取详情
const detailData = async () => {
	try {
		const res = await getComplainDetail({ id: id.value })
		if (res.code === 200 && res.data) {
			detail.value = res.data
			// 图片URL逗号分隔转数组
			if (res.data.problemImageUrl) {
				photoList.value = res.data.problemImageUrl.split(',').filter(url => url.trim())
			} else {
				photoList.value = []
			}
		} else {
			uni.showToast({ title: res.msg || '获取失败', icon: 'none' })
		}
	} catch (err) {
		uni.showToast({ title: typeof err === 'string' ? err.msg : '网络异常', icon: 'none' })
	}
}

// 预览图片
const previewImage = (index) => {
	uni.previewImage({
		current: photoList.value[index],
		urls: photoList.value
	})
}

// 返回
	const goBack = () => {
		uni.navigateBack()
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}
</style>

<style scoped>
	.contentStyle {
		display: flex;
		flex-direction: column;
		height: 100vh;
	}

	.page {
		flex: 1;
		overflow-y: auto;
		padding: 0px 40rpx;
		box-sizing: border-box;
	}

	.page-container {}

	.section-title {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.title-line {
		width: 8rpx;
		height: 36rpx;
		background-color: #007AFF;
		margin-right: 12rpx;
		border-radius: 4rpx;
	}

	.title-text {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}

	.status-section {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-bottom: 20rpx;
		border-bottom: 1rpx solid #eeeeee;
		margin-bottom: 30rpx;
	}

	.completedDesc {
		color: #2F77FD;
		font-size: 28rpx;
		margin-bottom: 30rpx;

	}

	.status-value {
		font-size: 32rpx;
		color: #007AFF;
		font-weight: 500;
	}

	.info-item {
		display: flex;
		padding: 24rpx 0;
		border-bottom: 1rpx solid #eeeeee;
		align-items: flex-start;
	}

	.info-label {
		width: 220rpx;
		font-size: 28rpx;
		color: #333333;
		flex-shrink: 0;
		line-height: 1.5;
	}

	.info-value {
		flex: 1;
		font-size: 28rpx;
		color: #000;
		line-height: 1.5;
	}

	.desc-item {
		align-items: flex-start;
	}

	.desc-value {
		white-space: pre-line;
		word-break: break-all;
	}

	.photo-section {
		padding: 24rpx 0;
	}

	.photo-label {
		display: block;
		font-size: 30rpx;
		color: #666666;
		margin-bottom: 20rpx;
	}

	.photo-list {
		display: flex;
		flex-wrap: wrap;
		gap: 20rpx;
		margin: 10rpx 0px 20rpx 0px;
	}

	.photo-item {
		width: calc(33.333% - 14rpx);
		height: 66px;
		object-fit: cover;
	}

	.pending {
		color: #2F77FD;
	}

	.processing {
		color: #2F77FD;
	}

	.completed {
		color: #999999;
	}

	.status-bar {
		width: 100vw;
		height: 46px;
	}
</style>
