<template>
  <view class="container">
    
    <view class="detail-card">
      <view class="card-header">
        <view class="header-icon">
          <uni-icons type="notification" size="20" color="#ffffff"></uni-icons>
        </view>
        <view class="header-info">
          <text class="card-name">{{ noticeData?.noticeTitle }}</text>
        </view>
        <view class="status-tag" :class="noticeData?.status === '0' ? 'status-normal' : 'status-disabled'">
          {{ dictStr(noticeData?.status, statusList) }}
        </view>
      </view>
      
      <view class="card-body">
        <view class="info-section">
          <view class="section-title">
            <view class="title-icon"></view>
            <text>基本信息</text>
          </view>
          <view class="info-list">
            <view class="list-item">
              <text class="item-label">公告类型</text>
              <text class="item-value">{{ dictStr(noticeData?.noticeType, noticeTypeList) }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">创建者</text>
              <text class="item-value">{{ noticeData?.createBy }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">创建时间</text>
              <text class="item-value">{{ noticeData?.createTime }}</text>
            </view>
            <view class="list-item" v-if="noticeData?.updateTime && noticeData?.updateTime !== noticeData?.createTime">
              <text class="item-label">更新时间</text>
              <text class="item-value">{{ noticeData?.updateTime }}</text>
            </view>
          </view>
        </view>
        
        <view class="info-section" v-if="noticeData?.noticeContent">
          <view class="section-title">
            <view class="title-icon"></view>
            <text>公告内容</text>
          </view>
          <view class="content-display">
            <rich-text :nodes="noticeData?.noticeContent"></rich-text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { getNotice } from '@/api/system/notice'
import { getDicts } from "@/api/system/dict/data"
import { onLoad } from "@dcloudio/uni-app"

const noticeId = ref(undefined)
const noticeData = ref(null)
const noticeTypeList = ref([])
const statusList = ref([])

onLoad((options) => {
  if (options.id) {
    noticeId.value = options.id
    getNotice(noticeId.value).then(response => {
      noticeData.value = response.data
    })
  }
  
  // 获取字典数据
  getDicts('sys_notice_type').then(res => {
    noticeTypeList.value = res.data
  })
  getDicts('sys_notice_status').then(res => {
    statusList.value = res.data
  })
})

// 返回
function goBack() {
  uni.navigateBack()
}

// 编辑
function handleEdit() {
  uni.navigateTo({
    url: `/pages_mine/pages/system/notice/addEdit?id=${noticeId.value}`
  })
}

// 字典翻译
function dictStr(value, list) {
  const item = list.find(v => v.dictValue === value)
  return item ? item.dictLabel : value
}
</script>

<style lang="scss" scoped>
.container {
  background: #f5f7fa;
  padding-bottom: 24rpx;
}

.detail-card {
  margin: 24rpx;
  background: #ffffff;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16rpx 20rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  
  .header-icon {
    width: 48rpx;
    height: 48rpx;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12rpx;
    backdrop-filter: blur(10rpx);
  }
  
  .header-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    
    .card-name {
      color: #ffffff;
      font-size: 28rpx;
      font-weight: 600;
      line-height: 1.2;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  
  .status-tag {
    padding: 8rpx 20rpx;
    border-radius: 20rpx;
    font-size: 22rpx;
    font-weight: 500;
    white-space: nowrap;

    &.status-normal {
      background-color: rgba(82, 196, 26, 0.2);
      color: #ffffff;
    }

    &.status-disabled {
      background-color: rgba(255, 77, 79, 0.2);
      color: #ffffff;
    }
  }
}

.card-body {
  padding: 24rpx;
}

.info-section {
  margin-bottom: 32rpx;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  .section-title {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    
    .title-icon {
      width: 6rpx;
      height: 28rpx;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border-radius: 3rpx;
      margin-right: 12rpx;
    }
    
    text {
      color: #2c3e50;
      font-size: 28rpx;
      font-weight: 600;
    }
  }
  
  .info-list {
    .list-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20rpx;
      background: #f8f9fa;
      border-radius: 8rpx;
      margin-bottom: 12rpx;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      .item-label {
        color: #7f8c8d;
        font-size: 26rpx;
      }
      
      .item-value {
        color: #2c3e50;
        font-size: 28rpx;
        font-weight: 500;
        text-align: right;
        
        &.status-normal {
          color: #52c41a;
        }
        
        &.status-disabled {
          color: #ff4d4f;
        }
        
        &.status-default {
          color: #666666;
        }
      }
    }
  }
  
  .content-display {
    padding: 20rpx;
    background: #f8f9fa;
    border-radius: 8rpx;
    
    ::v-deep rich-text {
      font-size: 28rpx;
      line-height: 1.6;
      color: #333333;
      
      // 处理常见的HTML标签样式
      p {
        margin: 0 0 20rpx 0;
      }
      
      h1, h2, h3, h4, h5, h6 {
        margin: 20rpx 0;
        font-weight: 600;
      }
      
      strong, b {
        font-weight: 600;
      }
      
      em, i {
        font-style: italic;
      }
      
      u {
        text-decoration: underline;
      }
      
      img {
        max-width: 100%;
        height: auto;
        border-radius: 8rpx;
        margin: 10rpx 0;
      }
      
      ul, ol {
        padding-left: 40rpx;
        margin: 20rpx 0;
      }
      
      li {
        margin: 10rpx 0;
      }
    }
  }
}
</style>