<template>
  <el-select v-model="props.patInfo.inpatientNo"
             title="快速搜索患者，可以根据床号快速搜索，仅针对患者同病房有用。"
             filterable
             @change="change"
             ref="selectRef">
    <el-option :value="item.inpatientNo" v-for="item in list"
               :label="item.name+'_'+item.bedNo">
      <span>
        {{ item.inpatientNo }}
      </span>
      <el-divider direction="vertical"/>
      <span>
        {{ item.name }}
      </span>
      <el-divider direction="vertical"/>
      <span>
        {{ item.bedNo }}
      </span>
    </el-option>
  </el-select>
</template>

<script setup name='EmrSelectPat' lang="ts">
import {getOverView} from "@/api/inpatient/patient";
import {defineProps, Ref, ref, watch} from 'vue'

const props = defineProps({
  patInfo: {
    type: Object
  }
})

const emits = defineEmits(['selected'])

const list: Ref<Array<any>> = ref([])
const change = (val) => {
  for (let i = 0, len = list.value.length; i < len; i++) {
    let item = list.value[i]
    if (item.inpatientNo === val) {
      emits('selected', item)
      return
    }
  }
}

watch(() => props.patInfo.ward, () => {
  if (props.patInfo.ward) {
    getOverView(props.patInfo.ward).then((res) => {
      list.value = res as any
    })
  }
})

</script>

<style scoped lang="scss">

</style>
