<template>
  <el-select
    v-model="plansId"
    v-select-load-more="loadStaff"
    filterable
    :clearable="clearable"
    :placeholder="placeholder"
    default-first-option
    size="small"
    @change="handleSelect"
  >
    <el-option
      v-for="item in staffList"
      :key="item.id"
      :label="item.planName"
      :value="item.id"
    >
      <div>
        <div class="inline-block item">
          <span class="option">{{ item.planName }}</span>
        </div>
      </div>
    </el-option>
  </el-select>
</template>
<script>
import { listAll } from '@/api/school/salary/commissionPlans'
export default {
  props: {
    clearable: {
      type: Boolean,
      default: false
    },
    teacher: {
      type: String,
      default: undefined
    },
    placeholder: {
      type: String,
      default: '选择方案'
    },
    value: {
      type: String,
      default: undefined
    }
  },
  data() {
    return {
      plansId: this.value,
      staffList: [],
      pageNum: 1,
      hasMoreData: false
    }
  },
  watch: {
    value: {
      handler(newValue, oldValue) {
        this.plansId = newValue
      },
      immediate: true
    }
  },
  created() {
    this.loadStaff()
  },
  methods: {
    loadStaff: function() {

        listAll().then(response => {
          if (response.code === 200) {
            this.staffList = response.data
          } else {
            this.msgError(response.msg)
          }
        })


    },
    handleSelect: function(val) {
      this.$emit('input', val)
      this.$emit('change', val)
    }
  }
}
</script>
<style ref="stylesheet/scss" lang="scss" scoped>
  .option{
    padding-right: 15px;
    color: #333;
    font-weight: normal;
  }
</style>
