<template>
  <el-dropdown @command="handleCommand">
    <el-button @click="exportClickHandler" :disabled="!catalogId">
        <i class="fa fa-refresh"></i>导出/导入<i class="fa fa-caret-down"></i>
    </el-button>
    <el-dropdown-menu slot="dropdown" :style="{'font-size':'14px'}">
        <el-dropdown-item command="import" ><i class="fa fa-file-archive-o"></i>导入</el-dropdown-item>
        <el-dropdown-item command="export" ><i class="fa fa-arrow-right"></i>导出</el-dropdown-item>
    </el-dropdown-menu>
    <!-- 导出文件 -->
    <catalog-content-export-dialog
      :show.sync="exportCatalog.isShowModal"
      :title="exportCatalog.title"
      :catalog-id="catalogId"
      :content-type="contentType">
    </catalog-content-export-dialog>
    <!-- 导入文件 -->
    <catalog-content-import-dialog
      :show.sync="importCatalog.isShowModal"
      :title="importCatalog.title"
      :catalog-id="catalogId"
      :content-type="contentType"
      @dialog="dialog">
    </catalog-content-import-dialog>
  </el-dropdown>
</template>
<script>
import CatalogContentImportDialog from './CatalogContentImportDialog.vue'
import CatalogContentExportDialog from './CatalogContentExportDialog.vue'
export default {
  components: {
    'catalog-content-import-dialog': CatalogContentImportDialog,
    'catalog-content-export-dialog': CatalogContentExportDialog
  },
  props: {
    catalogId: {
      type: Number,
      default: 0,
      required: true
    },
    catalogName: {
      type: String,
      default: '',
      required: true
    },
    contentType: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      exportCatalog: { title: '', isShowModal: false }, //   导出选项
      importCatalog: { title: '', isShowModal: false } //   导人选项
    }
  },
  methods: {
    handleCommand(command) {
      switch (command) {
        case 'export':
          this.exportClickHandler()
          break
        case 'import':
          this.importClickHandler()
          break
      }
    },
    exportClickHandler() {
      this.exportCatalog.isShowModal = true
      this.exportCatalog.title = '导出[' + this.catalogName + ']'
    },
    importClickHandler() {
      this.importCatalog.isShowModal = true
      this.importCatalog.title = '导入到[' + this.catalogName + ']'
    },
    dialog(msg) {
      this.$confirm(msg, '系统提示', {
        confirmButtonText: '确定',
        showCancelButton: false,
        type: 'warning'
      })
    }
  }
}
</script>
