<template>
	<view class="container">
		<view class="message-item" v-if="this.hdData!=null">
			<image src="/pagesMine/static/icon_hdxx.png" class="avatar" mode="aspectFill"></image>
			<view class="message-info">
				<view class="info-row">
					<text class="sender">互动消息</text>
					<text class="time">{{hdData.sendTime}}</text>
				</view>
				<view class="content">
					<text>{{hdData.receiveUserName}}对你心动</text>
				</view>
			</view>
		</view>
		<view class="message-list">
			<view v-for="(message, index) in messagesList" :key="index" class="message-item">
				<image :src="isSelf(message.sendUserId)==true?message.receiveUserAvatar:message.sendUserAvatar"
					class="avatar" mode="aspectFill"></image>
				<view class="message-info"
					@click="$wskj.to(`/pagesMine/pages/user_chat?batchNo=${message.batchNo}&receiveUserId=${message.receiveUserId}&title=${message.receiveUserName}`)">
					<view class="info-row">
						<text class="sender">{{ message.receiveUserName }}</text>
						<text class="time">{{ message.sendTime }}</text>
					</view>
					<view class="content">
						<text>{{message.messageContent}}</text>
					</view>
				</view>
			</view>
			<emptydata v-if="messagesList.length == 0"></emptydata>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				messagesList: [],
				hdData: {},
			};
		},
		computed: {

		},
		onShow() {
			this.getHd()
			this.getList()
		},
		methods: {
			isSelf(userId) {
				if (userId == uni.getStorageSync('id')) {
					return true
				} else {
					return false
				}

			},
			getList() {
				const params = {
					url: '/app/message/searchMessageBatchPageList',
					method: "GET",
					data: {}
				}
				this.$request(params).then(res => {
					this.messagesList = res.rows
				})
			},
			getHd() {
				const params = {
					url: '/app/message/searchLastMessageByCondition',
					method: "GET",
					data: {}
				}
				this.$request(params).then(res => {
					this.hdData = res.data
				})
			},
		}
	};
</script>

<style scoped>
	.container {
		width: 100%;
		height: 100%;
		background: #000000;
		display: flex;
		flex-direction: column;
	}

	.message-list {
		flex: 1;
		overflow-y: auto;
	}

	.message-item {
		padding: 0 20rpx;
		height: 218rpx;
		background: white;
		border-radius: 10px;
		display: flex;
		align-items: center;
		margin: 20rpx 24rpx;
		background: #191919;
	}

	.avatar {
		width: 131rpx;
		/* 头像宽度 */
		height: 131rpx;
		/* 头像高度 */
		border-radius: 50%;
		/* 圆形头像 */
		margin-right: 10px;
		/* 头像与信息之间的间距 */
	}

	.message-info {
		flex: 1;
		/* 让信息区域占据剩余空间 */
	}

	.info-row {
		display: flex;
		justify-content: space-between;
		/* 发送者和时间分开 */
	}

	.sender {
		font-weight: bold;
		color: #fff;
		font-size: 32rpx;
	}

	.time {
		color: #878787;
		font-size: 24rpx;
	}

	.content {
		color: #878787;
		margin-top: 30rpx;
		/* 消息内容与时间之间的间距 */
		font-size: 28rpx;
	}
</style>