<template>
	<view class="main">
		<view class="top" :style="{height:iSMT+'px'}"></view>
		<!-- 头部导航 -->
		<view class="header">
			<view class="back-icon">
				<image @click="goBack()" src="/static/customer-service-platform/cs-platform-back.png"
					class="header-icon-image"></image>
			</view>
			<view class="title">智能客服中台</view>
			<view class="notification-icon">
				<image src="/static/customer-service-platform/message.png" class="header-icon-image"></image>
			</view>
		</view>
		<!-- 内容区域 - 使用滚动视图 -->
		<scroll-view scroll-y class="content-container">
			<view class="list-wrapper" v-if="historyList.length > 0">
				<view class="content-header">
					<text class="content-title">历史反馈内容</text>
				</view>
				<view class="card-line"></view>
				<view v-for="(item, idx) in historyList" :key="item.id" class="history-item card">
					<view class="item-line" v-if="idx != 0"></view>
					<view class="item-head">
						<view class="dot-outer">
							<view class="dot-inner"></view>
						</view>

						<text class="feedback-time">{{ formatTime(item.createdAt) }}</text>
						<text class="feedback-status">
							{{ statusText }}
							<image class="smile-icon" src="/static/customer-service-platform/smile-icon.png"></image>
						</text>
					</view>

					<view class="content-box">
						<text class="content-text">{{ item.content }}</text>
						<text class="count">{{ item.content.length }}/200</text>
					</view>
					<view v-if="item.images && item.images.length" class="thumb-row">
						<view v-for="(img, i) in item.images" :key="i" class="thumb-slot"
							@click="previewImage(item.images, i)">
							<image :src="img" mode="scaleToFill" class="thumb-img" />
						</view>
					</view>
				</view>
			</view>

			<!-- 如果没有历史，显示空态 -->
			<view v-if="historyList.length === 0" class="empty">
				<image mode="aspectFit" class="empty-img" src="/static/customer-service-platform/empty-content.png">
				</image>
				<text class="empty-tip">暂无内容~</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getFeedbackRecordsApi,
	} from "../../api/customerServicePlatform/customerServicePlatform";
	export default {
		data() {
			return {
				iSMT: 0,
				statusText: '反馈成功',
				historyList: []
			};
		},
		mounted() {
			this.iSMT = uni.getSystemInfoSync().statusBarHeight;
			this.loadHistoryList()
		},
		methods: {
			formatTime(str) {
			  if (!str) return '';
			  const d = new Date(str);
			  const yyyy = d.getFullYear();
			  const mm = String(d.getMonth() + 1).padStart(2, '0');
			  const dd = String(d.getDate()).padStart(2, '0');
			  const hh = String(d.getHours()).padStart(2, '0');
			  const mi = String(d.getMinutes()).padStart(2, '0');
			  return `${yyyy}-${mm}-${dd} ${hh}:${mi}`;
			},
			goBack() {
				if (typeof uni !== 'undefined' && uni.navigateBack) {
					uni.navigateBack();
				} else {
					window.history.back();
				}
			},
			async loadHistoryList() {
				const res = await getFeedbackRecordsApi({
					token: 'a1bef735d336831ccb0cc3f532093b60'
				})
				console.log(res)
				if (res.code == 200) {
					this.historyList = res.data.map(item => {
						const images = [item.image1, item.image2, item.image3].filter(img => !!img)
						return {
							id: item.id,
							createdAt: item.createdAt,
							content: item.content,
							images,
							dccode: item.dccode
						}
					})
				}
			},
			previewImage(list, index) {
				if (typeof uni !== 'undefined' && uni.previewImage) {
					uni.previewImage({
						current: list[index],
						urls: list
					});
				} else {
					window.open(list[index], '_blank');
				}
			}
		}
	};
</script>

<style scoped>
	.main {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #ffffff;
	}

	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx 30rpx;
		background-color: #ffffff;
	}

	.title {
		color: #000000;
		text-align: center;
		font-size: 32rpx;
		font-style: normal;
		font-weight: 400;
	}

	.back-icon,
	.notification-icon {
		width: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.header-icon-image {
		width: 40rpx;
		height: 40rpx;
		object-fit: contain;
	}

	.content-container {
		padding: 20rpx;
		padding-top: 0;
		width: 100%;
		box-sizing: border-box;
		overflow-x: hidden;
	}

	/* 列表包装器，居中卡片 */
	.list-wrapper {
		width: 90%;
		margin: 0 auto;
		padding: 20rpx 40rpx;
		flex-direction: column;
		align-items: center;
		gap: 20rpx;
		box-sizing: border-box;
		border-radius: 12rpx;
		border: 4rpx solid #FCC8D4;
		background: linear-gradient(180deg, #FCC8D3 0%, #FEF0F3 30%, #FFF 100%);
	}

	.content-header {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.content-title {
		color: #000000;
		font-size: 32rpx;
		font-style: normal;
		font-weight: 400;
		line-height: normal;
	}

	.card-line {
		margin-top: 20rpx;
		width: 100%;
		height: 2rpx;
		border-radius: 2rpx;
		background: #FFF;
	}

	/* 每一条历史卡片 */
	.history-item {
		border-radius: 10rpx;
		padding: 20rpx;
		margin-bottom: 20rpx;
		box-sizing: border-box;
		box-shadow: 0 4rpx 12rpx rgba(255, 77, 128, 0.06);
	}
	.item-line{
		margin-bottom: 20rpx;
		width: 100%;
		height: 2rpx;
		border-radius: 2rpx;
		background: #D9D9D9;
	}
	.item-head {
		display: flex;
		align-items: center;
		gap: 12rpx;
		margin-bottom: 12rpx;
	}

	.dot-outer {
		width: 24rpx;
		height: 24rpx;
		border-radius: 50%;
		background: rgba(255, 214, 230, 0.5);
		/*粉色外圈*/
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 0 0 4rpx #ffffff;
		/* 最外层白色  */
	}

	.dot-inner {
		width: 14rpx;
		height: 14rpx;
		border-radius: 50%;
		background: #ff4150;
		/* 中心红色 */
	}


	.feedback-time {
		color: #000000;
		flex: 1;
		font-size: 22rpx;
		font-style: normal;
		font-weight: 400;
		line-height: normal;
		padding-left: 26rpx;
	}

	.feedback-status {
		color: #ff4150;
		font-size: 12rpx;
		font-style: normal;
		font-weight: 400;
		line-height: normal;
		display: flex;
		align-items: center;
	}

	.smile-icon {
		width: 32rpx;
		height: 32rpx;
	}

	/* 内容框 */
	.content-box {
		border: 2rpx solid #f0e6ea;
		background: #fff;
		border-radius: 8rpx;
		padding: 18rpx;
		position: relative;
		box-sizing: border-box;
		min-height: 160rpx;
	}

	.content-text {
		display: block;
		white-space: pre-wrap;
		word-break: break-word;
		color: #8a8a8a;
		font-size: 24rpx;
		font-style: normal;
		font-weight: 700;
		line-height: normal;
		padding-bottom: 26rpx;
	}

	.count {
		position: absolute;
		right: 14rpx;
		bottom: 10rpx;
		color: #000000;
		font-size: 24rpx;
		font-style: normal;
		font-weight: 400;
		line-height: normal;
	}

	.thumb-row {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: flex-start;
		align-content: flex-start;
		width: 100%;
		box-sizing: border-box;
		gap: 20rpx;
		margin-top: 14rpx;
		background: #F9FAFE;
		padding: 20rpx;
	}

	.thumb-slot {
		width: calc((100% - 2 * 25rpx) / 3);
		aspect-ratio: 1 / 1;
		border-radius: 7rpx;
		border: 1.2rpx solid #F0F1F1;
		display: flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
	}

	.thumb-img {
		width: 100%;
		height: 100%;
	}

	.empty {
		padding: 50rpx 0;
		text-align: center;
		color: #afafaf;
		font-size: 32rpx;
		font-style: normal;
		font-weight: 500;
		line-height: 48rpx;
	}

	.empty-img {
		width: 100%;
	}
</style>