<template>
  <div>
    <el-dialog title="生成栏目索引" :visible.sync="isShow" @open="beforeDialogOpen" class="index-basic-dlg">
      <div class="mt-20 ml-128" :style="{'margin':'20px 0px 0px 128px'}">
        <el-checkbox v-model="createChild">包含子栏目</el-checkbox>
      </div>
      <div slot="footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" v-loading="confirmLoading" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import util from '@src/common/util.js'
export default {
  computed: {
    isShow: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    }
  },
  props: { catalogId: [Number, String], show: Boolean },
  data() {
    return {
      confirmLoading: false,
      createChild: false //  是否包含子栏目
    }
  },
  methods: {
    beforeDialogOpen() {
      this.createChild = false
    },
    async confirm() {
      this.confirmLoading = true
      let params = { catalogID: this.catalogId, createChild: this.createChild }
      try {
        let res = await axios.get('/ui/indexlist/createindex', {
          params: params
        })
        this.confirmLoading = false
        if (res.data.status === 1) {
          this.$emit('update:show', false)
          this.$emit('callback', res.data.data.taskID)
        } else {
          util.showMessage(res)
        }
      } catch (e) {
        this.confirmLoading = false
        util.showErrorNotification(e)
      }
    }
  }
}
</script>
<style>
.index-basic-dlg .el-dialog {
 width:400px;
}
@media (max-width:480px){
  .index-basic-dlg .el-dialog {
  width:96%;
  }
}
</style>
