<template>
  <scroll-view class="message-scroll" scroll-y>
    <view class="message-container">
      <view class="message-item" v-for="message in messages" :key="message.id" @click="handleMessageClick(message)">
        <view class="message-avatar">
          <image :src="message.avatar" mode="aspectFill" v-if="message.avatar" />
          <text class="avatar-text" v-else>{{ message.name.charAt(0) }}</text>
        </view>
        <view class="message-content">
          <view class="message-header">
            <text class="message-name">{{ message.name }}</text>
            <text class="message-time">{{ message.time }}</text>
          </view>
          <text class="message-text">{{ message.content }}</text>
          <view class="message-tags" v-if="message.tags && message.tags.length > 0">
            <text class="tag" v-for="tag in message.tags" :key="tag">{{ tag }}</text>
          </view>
        </view>
        <view class="message-badge" v-if="!message.read">
          <text class="badge-dot"></text>
        </view>
      </view>
    </view>
  </scroll-view>
</template>

<script setup>
import { ref } from 'vue';

const messages = ref([
  {
    id: 1,
    name: '系统通知',
    content: '您有一条新的任务待处理',
    time: '10分钟前',
    read: false,
    tags: ['任务', '待处理']
  },
  {
    id: 2,
    name: '张经理',
    content: '请查看最新的项目进度报告',
    time: '1小时前',
    read: false,
    tags: ['项目']
  },
  {
    id: 3,
    name: '李助理',
    content: '明天的会议时间已更新，请查看',
    time: '2小时前',
    read: true,
    tags: ['会议']
  },
  {
    id: 4,
    name: '系统通知',
    content: '您的日程提醒：下午3点有重要会议',
    time: '3小时前',
    read: true,
    tags: ['日程']
  }
]);

const handleMessageClick = (message) => {
  console.log('点击消息:', message);
  message.read = true;
  uni.showToast({
    title: '查看消息详情',
    icon: 'none'
  });
};
</script>

<style lang="scss" scoped>
.message-scroll {
  height: calc(100vh - var(--status-bar-height, 0) - 100px);
}

.message-container {
  padding: 16px;
  padding-bottom: 100px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-item {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  position: relative;
}

.message-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.message-avatar image {
  width: 100%;
  height: 100%;
}

.avatar-text {
  font-size: 18px;
  color: #666;
  font-weight: 500;
}

.message-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.message-name {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.message-time {
  font-size: 12px;
  color: #999;
}

.message-text {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
}

.message-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  font-size: 12px;
  color: #2885ff;
  background: #e8f4ff;
  padding: 2px 8px;
  border-radius: 4px;
}

.message-badge {
  position: absolute;
  top: 16px;
  right: 16px;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff4444;
  display: block;
}
</style>

