import { queryPage } from '@/api/bizuser'
const BizUser = {
  template: `
      <a-select
        :placeholder="placeholder"
        :id="id"
        allowClear
        :value="defaultVal"
        :showSearch="true"
        :disabled="disabledFlag"
        @change="handleChange"
        option-filter-prop="children"
        :filter-option="filterOption">
        <a-select-option v-for="item in list" :key="item.bizUserSn" :value="item.bizUserSn">
        {{ item.userName }}
        </a-select-option>
      </a-select>
    `,
  props: {
    value: {
      type: String,
      defatut: ''
    },
    id: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: '请选择负责人'
    },
    disabledFlag: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      defaultVal: this.value,
      list: []
    }
  },
  mounted () {
    this.getList()
  },
  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
      const item = this.list.find(item => item.bizUserSn == value)
      this.$emit('input', value)
      this.$emit('change', value, item)
    },
    getList () {
      queryPage({bizUserType:'qy',pageNo:1,pageSize:100}).then(res => {
        if (res.status == 200) {
          this.list = res.data.list
        } else {
          this.list = []
        }
      })
    }
  }
}

export default BizUser
