<template>
  <el-select v-model="userSelected" clearable filterable >
    <el-option v-for="user in userList" :key="user.id" :label="user.cusName" :value="user.id" />
  </el-select>
</template>

<script>

import {getCustomerList} from "@/api/base/customer";

export default {
  name: "UserChoose",
  data() {
    return {
      userList: [],
      userSelected: undefined,
    }
  },
  watch:{
    userSelected(val){
      const user = this.userList.find(item => item.id === val)
      this.$emit("selected", user)
    }
  },
  mounted() {
    this.listCustomer()
  },
  methods: {
    async listCustomer(){
      const res = await getCustomerList()
      this.userList = res.data
    }
  }
}
</script>

<style scoped lang="scss">

</style>
