<template>
  <el-upload
    :action="url"
    :multiple="false"
    :on-success="handleSuccess"
    :show-file-list="false"
  >
    <el-button v-preReClick icon="upload" type="primary">导入</el-button>
  </el-upload>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { defineProps, defineEmits } from 'vue'

const baseUrl = import.meta.env.VITE_BASE_API

const props = defineProps({
  templateId: {
    type: String,
    required: true
  }
})

const emit = defineEmits(['on-success'])

const url = `${baseUrl}/sysExportTemplate/importExcel?templateID=${props.templateId}`

const handleSuccess = res => {
  if (res.code === 100000) {
    ElMessage.success('导入成功')
    emit('on-success')
  } else {
    ElMessage.error(res.msg)
  }
}
</script>
