<template>
  <div class="school-set-data">
    <el-button type="primary" :loading="loading" @click="confirm"
      >清除基础数据</el-button
    >
    <p class="tips-info tips-error">
      注意：执行该操作，会将该单位下配置的基础数据全部清除，进入初始状态，请谨慎操作，该操作不可恢复！
    </p>
  </div>
</template>

<script>
import { schoolSetDataBackup } from "../../api";

export default {
  name: "school-set-data",
  props: {
    school: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      loading: false
    };
  },
  methods: {
    async confirm() {
      let confirm = await this.$confirm(
        `确定要清除当前学校的基础数据集吗?`,
        "提示",
        {
          type: "warning"
        }
      ).catch(() => {});
      if (confirm !== "confirm") return;

      confirm = await this.$confirm(
        `确定要清除当前学校的基础数据集吗?`,
        "提示",
        {
          type: "warning"
        }
      ).catch(() => {});
      if (confirm !== "confirm") return;

      if (this.loading) return;
      this.loading = true;

      const res = await schoolSetDataBackup(this.school.id).catch(() => {});
      this.loading = false;

      if (!res) return;

      this.$message.success("操作成功！");
    }
  }
};
</script>
