<template>
  <div v-loading="loading">
    <el-upload
      :action="action"
      :show-file-list="false"
      :on-success="onUpload"
      style="margin-bottom: 20px"
    >
      <el-button type="primary">导入租户</el-button>
    </el-upload>
    <el-table :data="tableData" stripe border>
      <el-table-column type="index" label="#" />
      <el-table-column prop="tenantId" label="租户id" />
      <el-table-column prop="tenantName" label="租户名称" />
      <el-table-column prop="domainName" label="租户域名" />
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { useTenantStore } from '@/stores/modules/tenant'

const tenantStore = useTenantStore()

const tableData = ref()
const loading = ref(true)
const action = '/admin/api/lic/info/file/import'

const onUpload = async (res: any) => {
  try {
    if (res.code === 200) ElMessage.success('导入成功')
    else ElMessage.error(res.msg)
  } finally {
    await tenantStore.initTenantList()
    await init()
  }
}

const init = () => {
  loading.value = true
  tableData.value = tenantStore.getTenantList
  loading.value = false
}

init()
</script>

<style setup></style>
