<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue'
import { useMessage } from 'naive-ui'
import { format } from 'date-fns'
import { useRoute } from 'vue-router'
import { msgOne, readMsg } from '@/api/message/message'

const props = defineProps({
  id: {
    type: String,
    default: '',
  },
})

const route = useRoute()

const message = useMessage()
const state: any = reactive({
  detail: null,
})
const { detail } = toRefs(state)

async function getDetail() {
  const res = await msgOne({ id: route.query.id })
  if (res.code === 'OK')
    state.detail = res.data
  if (!state.detail.readFlag)
    clearMsg()
  else
    message.error(res.message)
}

async function clearMsg() {
  const res = await readMsg({ msgid: route.query.id })
}

getDetail()
</script>

<template>
  <div v-if="detail" class="wrapper-message">
    <div class="left-card">
      <div class="title">
        {{ detail.titile }}
      </div>
      <div class="content" v-html="detail.msgContent" />
    </div>
    <div class="right-card">
      <img class="icon-set" src="@/assets/images/message/set.png" alt="">
      <div class="title">
        系统消息
      </div>
      <div class="form">
        <div class="form-item flex">
          <img class="icon" src="@/assets/images/message/user.png" alt="">
          <div class="label">
            创建人：
          </div>
          <div class="value">
            {{ detail.userNcame }}
          </div>
        </div>
        <div class="form-item flex">
          <img class="icon" src="@/assets/images/message/time.png" alt="">
          <div class="label">
            发布时间：
          </div>
          <div class="value time">
            {{ format(detail.sendTime, 'yyyy-MM-dd HH:mm:ss') }}
          </div>
        </div>
        <div class="form-item flex margin-no">
          <img class="icon" src="@/assets/images/message/time.png" alt="">
          <div class="label">
            消息类型：
          </div>
          <div class="value">
            <div class="tag">
              {{ detail.msgCategory === 1 ? '审批通知' : '系统通知' }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.wrapper-message {
  display: flex;
  flex: 1;
  box-sizing: border-box;
  border-radius: 3px;
  height: calc(100vh - 88px);
  overflow-y: auto;

  .left-card{
    height: 100%;
    background: #ffffff;
    border-radius: 4px;
    flex: 1;
    padding-top: 32px;
    box-sizing: border-box;

    .title{
      font-size: 28px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: Medium;
      text-align: center;
      color: #333333;
      line-height: 40px;
      margin-bottom: 32px;
    }

    .content{
      padding: 0 32px;
    }

  }

  .right-card{
    width: 280px;
    height: 100%;
    box-sizing: border-box;
    background: #ffffff;
    border-radius: 4px;
    margin-left: 16px;
    padding-top: 48px;

    .title{
      font-size: 20px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: Medium;
      text-align: center;
      color: #333333;
      line-height: 22px;
    }

    .form{
      margin: 0 auto;
      margin-top: 32px;
      width: 235px;
      padding: 24px 0;
      border-top: 1px solid #eeeeee;
      border-bottom: 1px solid #eeeeee;
    }

    .form-item{
      align-items: center;
      margin-bottom: 16px;
    }

    .margin-no{
      margin: 0;
    }

    .icon{
      width: 16px;
      height: 16px;
      margin-right: 8px;
    }

    .label{
      width: 70px;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: Regular;
      text-align: left;
      color: #666666;
    }

    .value{
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: Regular;
      text-align: left;
      color: #333333;
    }

    .time{
      color: #1d2129;
    }
  }

  .icon-set{
    width: 80px;
    height: 80px;
    margin: 0 auto;
    margin-bottom: 24px;
  }
}
</style>
