import { queryListByTreeLevel } from '@/api/allocateType'
const AllocateTypeByLevel = {
  template: `
      <a-select
        :placeholder="placeholder"
        :id="id"
        allowClear
        :value="defaultVal"
        :showSearch="true"
        @change="handleChange"
        option-filter-prop="children"
        :filter-option="filterOption">
        <a-select-option v-for="item in list" :key="item.allocateTypeSn" :value="item.allocateTypeSn">{{ item.name }}</a-select-option>
      </a-select>
    `,
  props: {
    value: {
      type: [String,Number],
      defatut: ''
    },
    id: {
      type: String,
      default: ''
    },
    level: {
      type: [String,Number],
      default: '3'
    },
    placeholder:{
      type: String,
      default: '请选择'
    }
  },
  data() {
    return {
      defaultVal: this.value,
      list: []
    };
  },
  mounted() {
    this.getProductBrand()
  },
  watch: {
    value(newValue, oldValue) {
      this.defaultVal = newValue
    }
  },
  methods: {
    filterOption (input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      )
    },
    handleChange(value) {
      this.defaultVal = value;
      this.$emit('input', value);
      this.$emit('change', value);
    },
    //  调拨类型
    getProductBrand () {
      queryListByTreeLevel({"treeLevel":this.level}).then(res => {
        if (res.status == 200) {
          this.list = res.data
        } else {
          this.list = []
        }
      })
    },
  },
};

export default AllocateTypeByLevel