<template>
  <ResourceSearch
    ref="resourceSearch"
    :onSelectInput="onSelectInput"
    :isMenuMange="isMenuMange"
    @select="select"
  ></ResourceSearch>
</template>
<script>
import ResourceSearch from '../resourceSearch/ResourceSearch.vue';
export default {
  components: {
    ResourceSearch
  },
  props: {
    title: {
      type: String,
      default: ''
    },
    valid: {
      type: String,
      default: '请选择一项数据！'
    },
    onSelectInput: {
      type: Boolean,
      default: false
    },
    isMenuMange: { // 是否菜单中使用
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      resourceData: null
    };
  },
  created() {
    this.select(null);
    this.$emit('SetTitle', this.title);
    this.$emit('SetPageActions', [
      {
      text: '确定',
      type: 'warning',
      ghost: true,
      size: 'small',
      icon: 'md-checkmark',
      action: 'save',
      handle: () => {
        this.save();
      }
    },{
      text: '返回',
      type: 'warning',
      ghost: true,
      size: 'small',
      action: 'close',
      icon: 'md-undo',
      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>
