<template>
  <scroll-view
    v-if="doctorDataList.length"
    scroll-y="true"
    @scrolltolower="getListData"
    class="doctor-box scroll-box">
    <!-- 标题 -->
    <div class="header-box clearfix">
      <div class="count-box fr">
        <img src="../../assets/images/icon_doctor.png">
        <span>{{total}}位医生</span>
      </div>
      <div class="title-bg">
        <img src="../../assets/images/title_bg.png" mode="heightFix">
        <span class="text">天然博士宝宝营养关爱行动</span>
      </div>
    </div>

    <!-- 列表 -->
    <doctorList
      v-for="(doctorInfo, key) in doctorDataList"
      :key="key"
      :doctorInfo="doctorInfo"></doctorList>
  </scroll-view>
</template>

<script>
import titleMore from '@/components/titleMore'
import doctorList from '@/components/doctorList'

import { getDoctorList } from '@/utils/api'
export default {
  components: {
    titleMore,
    doctorList
  },
  data () {
    return {
      page: 1,
      limit: 10,
      total: 0,
      nomore: false,
      doctorDataList: []
    }
  },

  mounted () {
    this.getListData()
  },

  methods: {
    async getListData () {
      if (this.nomore) {
        return false
      }
      wx.showLoading({
        title: '加载中'
      })

      let res = await getDoctorList('ALL', this.page, this.limit)
      this.doctorDataList = this.doctorDataList.concat(res.data)
      this.total = res.total
      if (res.total <= this.page * this.limit) {
        this.nomore = true
      } else {
        this.page++
      }

      wx.hideLoading()
    }
  }
}
</script>

<style scoped lang="less">
@import '~@/assets/less/common.less';
.doctor-box{
  .scroll-box();
  .header-box{
    margin: @spacing;
    line-height: 30px;
    .count-box{
      font-size: 12px;
      color: #999999;
      img{
        display: inline-block;
        margin: 10px 6px 0 0;
        width: 12px;
        height: 12px;
        vertical-align: top;
      }
    }
    .title-bg{
      position: relative;
      height: 30px;
      color: @themeColor;
      overflow: hidden;
      img{
        position: absolute;
        left: 0;
        top: 0;
        width: auto;
        height: 100%;
      }
      .text{
        position: absolute;
        left: 0;
        top: 0;
        padding: 0 12px;
      }
    }
  }
}
</style>
