<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      :offset="5"
      :immediate-check="false"
      v-if="attentionList.length!==0"
    >
      <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}}</span>
              </div>

              <p class="hospital">{{item.hospitalName}}</p>
              <p>{{item.hospitalDepartments}}</p>
            </div>
          </div>
          <div
            class="attention-btn"
            @click="cancelAttention(item.id, index)"
          >
            <button>取消关注</button>
          </div>
        </div>
      </div>

    </van-list>

    <img
      class="default-img"
      src="../../static/imgs/no-attention-doctor.png"
      alt=""
      v-show="isShow"
    >
  </div>
</template>

<script>

// 引入封转好的API接口
import { getMyFollowList, cancelFollow } from '../../api/ShortVideo/ShortVideo'
export default {
  data() {
    return {
      isShow: false,    // 是否显示缺省图片
      params: {   // 分页查询参数
        pageIndex: 1,
        pageSize: 1000,
        name: ""
      },
      attentionList: [],   // 关注列表
      loading: false,
      finished: false
    }
  },
  methods: {
    // 跳转医生主页
    goDoctorDetail(id) {
      // this.$router.push({ name: "doctorDetail", query: { id } })
    },
    // 取消关注 方法
    cancelAttention(id, index) {
      this.isRequest();
      cancelFollow({ "id": id }).then(res => {
        this.$toast.clear();
        this.attentionList.splice(index, 1);
        if (this.attentionList.length === 0) {
          this.isShow = true;
        }
      })
    },
    // 获取关注的医生列表数据
    getList() {
      this.isRequest();
      getMyFollowList(this.params).then(res => {
        this.$toast.clear();
        if (res.data.resultObject.length === 0) {
          if (this.params.pageIndex === 1) {
            console.log(132);
            this.isShow = true;
          }
          // 没有更多数据了
          return;
        }
        this.loading = false;
        this.finished = true
        this.attentionList = res.data.resultObject;
        // this.params.pageIndex++;

      }).catch(error => {
        console.log("catch: ", error);
      })
    },
    onLoad() {
      // this.getList();
    }
  },


  /* 生命周期钩子函数 */
  mounted() {
    this.params.pageIndex = 1;
    this.attentionList = [];
    this.loading = false;
    this.finished = false;
    this.getList();
  },
}
</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;
          padding-right: 0.2rem;
        }
      }
    }

    .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;
      }
    }
  }
}

.default-img {
  display: block;
  width: 50%;
  height: 50%;
  margin: 0 auto;
  padding-top: 4rem;
}
</style>