<template>
  <div>
    <el-dialog
      width="800px"
      title="消息明细"
      :visible="messageVisible"
      @close="$emit('update:messageVisible', false)"
    >
      <el-form label-width="100px">
        <el-form-item label="主题：">
          <div>{{ messageDetail.subject }}</div>
        </el-form-item>

        <el-form-item label="发信人：">
          <div>{{ messageDetail.owner }}</div>
        </el-form-item>

        <el-form-item label="发信时间：">
          <div>{{ messageDetail.createTime }}</div>
        </el-form-item>

        <el-form-item label="内容：">
          <div class="content" v-html="messageDetail.content"></div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import { getMessageDetail } from '@/api/personal'
  export default {
    name: 'MessageDialog',
    props: {
      id: {
        type: String,
        default: '',
      },
      messageVisible: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        messageDetail: {},
      }
    },
    watch: {
      messageVisible(val) {
        if (val) {
          this.getMsgDetailById()
        }
      },
    },
    methods: {
      getMsgDetailById() {
        getMessageDetail(this.id).then((data) => {
          if (data) {
            this.messageDetail = data
            this.$store.dispatch('navHeader/setUnreadMsgCount')
          }
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  ::v-deep .content {
    p {
      margin: 0;
    }
  }
</style>
