<template>
  <PickerSearch 
    :columns="showEmployeeList"
    placeholder="搜索归属人"
    @confirm="onEmployeeConfirm"
    @search="searchEmployee" />
</template>

<script setup>
import { getChargeListAPI } from '@/api'

const emits = defineEmits(['confirm'])

const showEmployeeList = ref([])

// 归属人
const allEmpolyeeList = ref([])
const getEmployeeList = async () => {
  const res = await getChargeListAPI()
  allEmpolyeeList.value = res.data.map(item => {
    return {
      text: item.name,
      value: item.id,
      employeeNo: item.employeeNo,
      deptQcName: item.deptQcName,
      deptQcId: item.deptQcId
    }
  })
  showEmployeeList.value = allEmpolyeeList.value
}
getEmployeeList()


// 确定归属人
const onEmployeeConfirm = (val) => {
  emits('confirm', val)
}

// 搜索归属人
const searchEmployee = (searchName) => {
  showEmployeeList.value = allEmpolyeeList.value.filter(item => {
    return item.text.includes(searchName)
  })
}
</script>

<style scoped></style>