<template>
  <el-dialog v-model="visible" title="信息发布与征集" width="600px">
    <el-form :model="form" label-width="100px">
      <el-form-item label="发布类型">
        <el-radio-group v-model="form.type">
          <el-radio label="publicity">文件公示</el-radio>
          <el-radio label="collection">意见征集</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="标题">
        <el-input v-model="form.title" placeholder="请输入标题" />
      </el-form-item>
      <el-form-item label="内容描述">
        <el-input v-model="form.content" type="textarea" rows="4" placeholder="请输入详细内容..." />
      </el-form-item>
      <el-form-item label="附件上传">
        <el-upload action="#" :auto-upload="false" :limit="3">
          <el-button type="primary">点击上传</el-button>
          <template #tip>
            <div class="el-upload__tip">支持 pdf/doc/jpg 等格式，不超过 10MB</div>
          </template>
        </el-upload>
      </el-form-item>
      <el-form-item label="截止时间" v-if="form.type === 'collection'">
        <el-date-picker v-model="form.deadline" type="datetime" placeholder="选择截止时间" style="width: 100%" />
      </el-form-item>
      <el-form-item label="发布范围">
        <el-select v-model="form.scope" style="width: 100%">
          <el-option label="全校可见" value="all" />
          <el-option label="仅宿管可见" value="staff" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handlePublish">确认发布</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'

const visible = ref(false)
const form = reactive({
  type: 'publicity',
  title: '',
  content: '',
  deadline: '',
  scope: 'all'
})

const open = () => {
  form.title = ''
  form.content = ''
  form.type = 'publicity'
  visible.value = true
}

const handlePublish = () => {
  if (!form.title) return ElMessage.warning('请输入标题')
  ElMessage.success('发布成功')
  visible.value = false
}

defineExpose({
  open
})
</script>
