<template>
  <el-select v-model="mValue" v-bind="$attrs" style="width: 100%;" v-on="$listeners">
    <el-option v-for="item in mOptions" :key="item.id" :label="item.name" :value="item.id" />
  </el-select>
</template>

<script>
import { mapGetters } from 'vuex'
import { getSerialList } from '@/api/serial.js'

export default {
  name: 'SerialSelect',
  props: {
    value: {
      type: [String, Array],
      default: ''
    },
    deptId: {
      type: [String, Number],
      default: undefined
    },
    advisorId: {
      type: [String, Number],
      default: undefined
    }
  },
  data() {
    return {
      options: []
    }
  },
  computed: {
    ...mapGetters(['user']),
    mValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('update:value', val)
      }
    },
    mOptions() {
      if (this.advisorId) {
        return this.options.filter(item => item.advisorId === this.advisorId)
      }
      return this.options
    }
  },
  mounted() {
    getSerialList({
      current: 1,
      size: 9999,
      status: 3,
      userType: this.user.user.userType === 1 ? 1 : 2,
      deptId: this.deptId
    }).then(res => {
      this.options = res.data.list
    })
  }
}
</script>
