<template>
  <DispatchDimensionSearch
    ref="dispatchDimensionSearch"
    :showCheckbox="showCheckbox"
    :queryOpts="queryOpts"
    @select="select"
  ></DispatchDimensionSearch>
</template>
<script>
import DispatchDimensionSearch from '../DispatchDimensionTree/DispatchDimensionSearch.vue';
export default {
  components: {
    DispatchDimensionSearch
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    valid: {
      type: String,
      default: '请选择一项数据！'
    },
    showCheckbox: {
      type: Boolean,
      default: false
    },
    queryOpts: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      resourceData: null
    };
  },
  created() {
    this.select(null);
    this.$emit('SetTitle', this.title);
    this.$emit('SetPageActions', [{
      text: '确定',
      type: 'warning',
      action: 'save',
      handle: () => {
        this.save();
      }
    },{
      text: '取消',
      ghost: true,
      action: 'close',
      handle: () => this.$emit('Close')
    }]);
  },
  methods: {
    select(data) {
      this.resourceData = data;
    },
    save() {
      if (!this.resourceData) {
        this.$Message.error(this.valid);
      } else {
        this.$emit('Close', this.resourceData);
      }
    }
  }
};

</script>
<style>
</style>
