<template>
  <el-dialog :visible.sync="visible" title="通知" width="50%">
    <el-form ref="form" :model="noticeListData" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="公告标题：" prop="noticeTitle">
            <span>{{ noticeListData.noticeTitle }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公告类型" prop="noticeType">
            <el-select v-model="noticeListData.noticeType" placeholder="请选择公告类型" disabled>
              <el-option
                v-for="dict in dict.type.sys_notice_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="内容">
            <ReadOnlyEditor v-model="noticeListData.noticeContent" :min-height="192"/>
            <DownloadFile v-model="noticeListData.attachPath" @file-clicked="handleFileClick"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import ReadOnlyEditor from "@/components/ReadOnlyEditor/index.vue";
import DownloadFile from "@/components/DownloadFile/index.vue";
import {updateUserNotice} from "@/api/system/notice";
import {parseTime} from "@/utils/ruoyi";

export default {
  dicts: ['sys_notice_status', 'sys_notice_type'],
  components: {
    ReadOnlyEditor,
    DownloadFile
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    noticeListData: {
      type: Object,
      default: () => [],
    },
  },
  methods: {
    handleFileClick(fileUrl) {
      console.log('已下载文件:', fileUrl);
      let userNotice = this.noticeListData.sysUserNoticeList[0];
      userNotice.downloadStatus = '1'
      userNotice.downloadTime = parseTime(new Date());
      userNotice.checkTime = null;
      updateUserNotice(userNotice).then(res => {
      })
    }
  }
};
</script>
