<template>
  <el-button :disabled="disabled"  @click.stop="similarAddClickHandler" class="table-operate-icon" :priv="`com.zving.cms.Site.AddTopLevelCatalog.${siteID}||com.zving.cms.Catalog.Edit.${parentId}`">
    <i class="fa fa-plus f16"></i>类似新建
    <el-dialog title="类似新建栏目" :append-to-body="true" :visible.sync="isShowModal" @open="dialogOpen" class="similar-catalog-dlg">
       <catalog-add-form @callback="addCallback" ref="catalogSimilarAdd" :catalog-id="catalogId" :dimension-id="dimensionId"></catalog-add-form>
    <div slot="footer">
      <el-button @click="isShowModal = false">取 消</el-button>
      <el-button type="primary" v-loading="submitLoading" @click="confirm">确 定</el-button>
    </div>
    </el-dialog>
  </el-button>
</template>
<script>
import catalogAddForm from './CatalogAddForm.vue'
export default {
  props: {
    catalogId: {
      type: Number,
      default: 0,
      required: true
    },
    parentId: {
      type: [Number, String],
      default: 0,
      required: true
    },
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    dimensionId: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      isShowModal: false,
      submitLoading: false,
      siteID: this.$root.siteID
    }
  },
  components: {
    'catalog-add-form': catalogAddForm
  },
  methods: {
    dialogOpen() {
      this.$nextTick(async () => {
        this.$refs.catalogSimilarAdd.init()
      })
    },
    similarAddClickHandler() {
      this.isShowModal = true
      this.submitLoading = false
    },
    async confirm() {
      let result = await this.$refs.catalogSimilarAdd.confirmClickHandler()
      if (result) {
        this.isShowModal = false
      }
    },
    addCallback(catalog) {
      this.$emit('callback', catalog)
    }
  }
}
</script>

<style scoped>

</style>
<style>
.similar-catalog-dlg .el-dialog{
  width:500px;
}
@media (max-width:480px){
  .similar-catalog-dlg .el-dialog{
    width:96%;
  }
}
</style>
