<template>
  <el-select v-model="supplierSelected" clearable filterable>
    <el-option v-for="supplier in supplierList" :key="supplier.id" :label="supplier.name"
               :value="supplier.id"/>
  </el-select>
</template>

<script>

import {getBaseSupplierList} from "@/api/repair/supplier";

export default {
  name: "SupplierChoose",
  data() {
    return {
      supplierSelected: undefined,
      supplierList: null
    }
  },
  watch:{
    supplierSelected(val) {
      const supplier = this.supplierList.find(item => item.id === val);
      this.$emit("selected", supplier);
    }
  },
  mounted() {
    this.listSupplier()
  },
  methods: {
    async listSupplier() {
      const res = await getBaseSupplierList();
      this.supplierList = res.data
    }
  }
}
</script>

<style scoped lang="scss">

</style>
