<template>
  <el-dialog
      v-model="props.visible"
      title="消息详情"

      width="750"
      :close-on-click-modal="false"
      :before-close="dialogClose"
  >
  <el-descriptions  column="2" border>
    <el-descriptions-item label="消息标题:" label-class-name="des-width">{{formData.title}}</el-descriptions-item>
    <el-descriptions-item label="消息类型:" label-class-name="des-width">{{getTyepText(formData.type)}}</el-descriptions-item>
    <el-descriptions-item label="业务类型:">{{formData.bizType==1?'订单':'其他'}}</el-descriptions-item>
    <el-descriptions-item label="消息状态:">{{formData.status==1?'已读':'未读'}}</el-descriptions-item>
    <el-descriptions-item label="消息内容:">{{formData.content}}</el-descriptions-item>
</el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogClose">关闭</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
import type {FormInstance} from "element-plus";
import {getMessageDetail} from "@/api/data/message";
import {onMounted, reactive, shallowRef} from "vue";

const emit = defineEmits(["success", "update:visible"]);
const formRef = shallowRef<FormInstance>();
const formData = reactive({
  id: "",
  title: "",
  type:'',
  bizType:'',
  status:'',
  content:''
});

const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
    default: false
  },
  messageId: {
    type: Number,
    required: true,
    default: 0
  }
});


const dialogClose = () => {
  emit("update:visible", false);
};

const setFormData = async () => {
  const data = await getMessageDetail(props.messageId);
  for (const key in formData) {
    if (data[key] != null && data[key] != undefined) {
      //@ts-ignore
      formData[key] = data[key];
    }
  }
};
const getBizType =(type)=>{
  let typeText = ''
    switch (type) {
      case 1:
        typeText='系统用户'
        break;
      case 2:
        typeText='会员用户'
        break;
      case 3:
        typeText='其他'
        break;
      default:
        break
    }
    return typeText 
}
const getTyepText =(type)=>{
  let typeText = ''
    switch (type) {
      case 1:
          typeText='系统通知'
          break;
        case 2:
          typeText='用户私信 '
          break;
        case 3:
          typeText='代办事项'
          break;
        default:
          break;
    }
    return typeText 
}

onMounted(() => {
  if (props.messageId) {
    setFormData();
  }
});

</script>
<style lang="scss" scoped>
:deep(.des-width) {
  width:120px;
}
:deep(.el-descriptions__body .el-descriptions__table .el-descriptions__cell)  {
  word-break: break-all;
}
</style>