<template>
  <window-size>
    <van-empty v-if="showEmpty" :image="empty" description="暂无数据"></van-empty>
    <div v-for="item in collections" :key="item.doctorCode">
      <van-cell
        center
        :title="'&nbsp;&nbsp;' + item.doctorName"
        :label="'&nbsp;&nbsp;&nbsp;' + item.deptName"
        :value="item.doctorTitle"
        is-link
        :to="'/doctorArrangement/' + date + '/' + item.deptCode + '/' + item.doctorCode"
      >
        <template #icon>
          <van-image
            round
            fit="cover"
            width="30px"
            height="40px"
            :src="'data:image/png;base64,' + item.portrait"
          ></van-image>
        </template>
      </van-cell>
      <div style="height: 5px"></div>
    </div>
  </window-size>
</template>

<script setup>
import empty from '@/assets/empty.png'
import { getMyCollections } from '@/api/my-collection'
import { computed, onMounted, ref } from 'vue'
import { getDate } from '@/utils/date'
import { genTextPortrait } from '@/utils/portrait'

const collections = ref([])
const showEmpty = computed(() => {
  return collections.value.length === 0
})
const date = getDate()
onMounted(() => {
  getMyCollections().then((res) => {
    res.forEach((item) => {
      if (!item.portrait) {
        item.portrait = genTextPortrait(item.doctorName)
      }
    })
    collections.value = res
  })
})
</script>