<template>
  <el-button  @click.stop="addClickHandler" class="table-operate-icon" :priv="`com.zving.cms.Site.AddTopLevelCatalog.${siteID}`">
    <i class="fa fa-plus f14"></i>新建栏目
    <el-dialog title="新建栏目" :append-to-body="true" :visible.sync="isShowModal" @open="dialogOpen" class="catalog-dlg">
      <catalog-add-form @callback="addCallback" ref="catalogAdd" :catalog-id="'new'" :parent-catalog="parentCatalog" :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 {
  components: {
    'catalog-add-form': catalogAddForm
  },
  data() {
    return {
      isShowModal: false,
      submitLoading: false,
      cleanChildren: false, //  是否包含子栏目
      siteID: this.$root.siteID
    }
  },
  props: {
    dimensionId: {
      type: Number,
      default: 1
    },
    parentCatalog: {
      type: Object
    }
  },
  watch: {
    isShowModal(val) {
      if (!val) {
        this.$refs.catalogAdd.$refs.cTreeSelect.isOpenTree = false
      }
    }
  },
  methods: {
    dialogOpen() {
      this.$nextTick(async () => {
        this.$refs.catalogAdd.init()
      })
    },
    addClickHandler() {
      this.isShowModal = true
      this.cleanChildren = false
      this.submitLoading = false
    },
    async confirm() {
      let flag = await this.$refs.catalogAdd.confirmClickHandler()
      if (flag) {
        this.isShowModal = false
      }
    },
    addCallback(catalog) {
      this.$emit('callback', catalog)
    }
  }
}
</script>

<style scoped>

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