<template>
  <div class="record" v-if="pageShow">
    <div class="record-item" v-for="(item, index) in list" :key="index" @click="$linkTo('./Detail?id=' + item.id)"
         hover-class="bg-hover">
      <div class="left">{{ item.createTime.split(' ')[0] }}的健康上报</div>
      <div class="right">
        <i v-if="item.status === '0'">健康数据异常</i>
        <u-icon name="arrow-right" color="#ddd"/>
      </div>
    </div>
    <AiEmpty v-if="!list.length && isMore"/>
  </div>
</template>

<script>
export default {
  appName: "上报记录",
  data() {
    return {
      list: [],
      pageShow: false,
      current: 1,
      total: 0,
      isMore: false
    }
  },

  onLoad(query) {
    this.$loading()
    this.getList(query)
  },

  methods: {
    getList(query) {
      if (this.isMore) return

      this.$instance.post(`/app/appepidemichealthreport/list?memberId=${query.id}`, null, {
        params: {
          current: this.current,
          size: 15
        }
      }).then(res => {
        if (res.code == 0) {
          this.total = res.data.total
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records]
          } else {
            this.list = res.data.records
          }
          uni.hideLoading()
          this.pageShow = true
          if (res.data.records.length < 15) {
            this.isMore = true

            return false
          }

          this.current = this.current + 1
        } else {
          uni.hideLoading()
        }
      }).catch(() => {
        uni.hideLoading()
      })
    }
  },

  onReachBottom() {
    this.getList()
  }
}
</script>

<style lang="scss">
.record {
  padding: 32px 0;

  .record-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 686px;
    height: 112px;
    margin: 0 auto 24px;
    padding: 0 28px 0 32px;
    background: #FFFFFF;
    box-sizing: border-box;
    box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.02);
    border-radius: 16px;

    .left {
      color: #333333;
      font-size: 32px;
      font-weight: 600;
    }

    .right {
      i {
        width: 158px;
        height: 36px;
        line-height: 36px;
        margin-right: 8px;
        text-align: center;
        font-size: 26px;
        color: #FF4466;
        background: #FFF5F7;
      }
    }

    & > div {
      display: flex;
      align-items: center;
    }
  }
}
</style>
