import { expenseTypeList } from '@/api/expenseManagement.js'
const ExpenseType = {
  template: `
      <a-cascader
        :value="defaultVal"
        allowClear
        :change-on-select="changeOnSelect"
        @change="handleChange"
        :options="list"
        expand-trigger="hover"
        :placeholder="placeholder"
        :id="id"
        :fieldNames="{ label: 'name', value: 'expenseTypeSn', children: 'sonList' }"/>
    `,
  props: {
    value: {
      type: Array,
      defatut: function(){
        return []
      }
    },
    id: {
      type: String,
      default: ''
    },
    placeholder:{
      type: String,
      default: '请选择'
    },
    changeOnSelect:{
      type: Boolean,
      default: false
    }
  },
  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,opts) {
      this.defaultVal = value;
      this.$emit('input', value);
      this.$emit('change', value, opts);
    },
    //  调拨类型
    getProductBrand () {
      expenseTypeList({}).then(res => {
        if (res.status == 200) {
          this.list = res.data
        } else {
          this.list = []
        }
      })
    },
  },
};

export default ExpenseType