<template>
  <van-list
    v-model="options.isLoading"
    :finished="options.finished"
    finished-text="没有更多了"
    @load="onLoad"
    :offset="5"
    :immediate-check="false"
  >
    <div class="attention-wrap">
      <div
        class="attention-item"
        v-for="(item,index) in attentionList"
        :key="index"
      >
        <div class="doctor-info" @click="goDoctorDetail(item.ID)">
          <div class="doctor-info-left">
            <img
              :src="item.HeadImg?item.HeadImg:require('../../static/imgs/avatar3.jpg')"
              alt=""
              class="user-avatar"
            >
          </div>
          <div class="doctor-info-right">
            <div>
              <span class="doctor-name">{{item.DoctorName}}</span>
              <span class="doctor-level">{{item.PositionalTitles | filterDoctorTitles}}</span>
            </div>

            <p class="hospital">{{item.HospitalName}}</p>
            <p>{{item.HospitalDepartments}}</p>
          </div>
        </div>
      </div>
    </div>

  </van-list>
</template>

<script>

// 引入封转好的API接口
import { getMyFollowList } from '../../api/ShortVideo/ShortVideo'
export default {
  props: {
    attentionData: {
      type: Array,
      required: true
    },
    options: {
      type: Object,
      default: {
        finished: false,
        isLoading: false
      },
      required: true
    },
    finishedText: {
      type: String,
      default: "没有更多了~"
    }

  },
  data() {
    return {
      attentionList: [],   // 医生列表
      loading: false,
      finished: true
    }
  },
  methods: {
    // 跳转医生主页
    goDoctorDetail(id){
      this.$router.push({name: "doctorDetail", query:{id}})
    },

    onLoad() {
      // this.getList();
      this.$emit('load')
    }
  },


  /* 生命周期钩子函数 */
  mounted() {
  },
  watch: {
    attentionData: {
      handler: function(newValue, oldValue){
      console.log("Attention Doctor watch list: ", newValue);

      this.attentionList = JSON.parse(JSON.stringify(newValue));
      this.attentionList = this.attentionList.map(item=>{
        if(item.HospitalDepartments&&item.HospitalName) {
          item.HospitalDepartments = item.HospitalDepartments.slice(0, -1);
          return item;
        }else {
          item.HospitalName = '医院(暂无)'
          item.HospitalDepartments = '科室(暂无)'
          return item;
        }
      })
    },
    deep: true,
    immediate: true
    }
  }
}
</script>

<style lang="less" scoped>
.attention-wrap {
  padding-top: 0.2rem;
  height: 100%;
  background-color: #f5f5f7;
  .attention-item {
    display: flex;
    align-items: center;
    margin: 0.2rem auto;
    padding: 0.36rem 0.18rem;
    width: 7.1rem;
    background-color: #fff;

    .doctor-info {
      display: flex;
      .doctor-info-left {
        width: 1.28rem;
        img {
          display: block;
          width: 1.02rem;
          height: 1.02rem;
          border-radius: 50%;
        }
      }
      .doctor-info-right {
        text-align: left;
        color: #000;
        width: 4.2rem;
        .doctor-name {
          font-size: 0.36rem;
        }
        .doctor-level {
          margin-left: 0.18rem;
          font-size: 0.3rem;
        }
        p {
          margin-top: 0.12rem;
          font-size: 0.3rem;
        }
      }
    }

    .attention-btn {
      // margin-left: 1rem;
      button {
        display: block;
        outline: none;
        border: none;
        width: 1.34rem;
        height: 0.5rem;
        line-height: 0.5rem;
        text-align: center;
        border-radius: 0.3rem;
        background-color: rgba(255, 177, 12);
        font-size: 0.2rem;
        color: #fff;
      }
    }
  }
}
</style>