<template>
  <div class="returnHomeRegister" v-if="pageShow">
    <div class="title">
      <h2>上报人员</h2>
      <div class="right">
        <span>共</span>
        <i>{{ total }}</i>
        <span>名</span>
      </div>
    </div>
    <div class="home-list">
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="item-top">
          <div class="item-top__left">
            <h2>{{ item.name }}</h2>
            <p @click.stop="$linkTo('./UserInfo?id=' + item.id)" hover-class="text-hover">查看个人信息></p>
          </div>
          <span v-if="item.status === '0'">健康数据异常</span>
        </div>
        <div class="item-bottom">
          <div class="item-bottom__left">
            <span>上报第</span>
            <i>{{ item.diffNum || 0 }}</i>
            <span>天</span>
          </div>
          <div class="item-bottom__right" hover-class="text-hover" v-if="item.today === '0'"
               @click.stop="$linkTo('./AddReport?id=' + item.id)">
            <span style="color: #FF883C">今日未上报</span>
            <u-icon name="arrow-right" color="#ddd"/>
          </div>
          <div class="item-bottom__right" hover-class="text-hover" v-else
               @click.stop="$linkTo('./RecordList?id=' + item.id)">
            <span style="color: #999999">今日已上报</span>
            <u-icon name="arrow-right" color="#ddd"/>
          </div>
        </div>
      </div>
      <AiEmpty v-if="list.length==0"/>
    </div>
    <div class="btn-wrapper">
      <div class="btn" @click="toReport" hover-class="text-hover">添加上报人员</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "AppHealthReport",
  appName: "健康上报",
  data() {
    return {
      list: [],
      pageShow: false,
      current: 1,
      total: 0,
    }
  },

  computed: {
    ...mapState(['user'])
  },

  onLoad() {
    this.$loading()
    this.$dict.load(['villageActivityStatus']).then(() => {
      this.getList()
    })

    uni.$on('update', () => {
      this.current = 1
      this.$nextTick(() => {
        this.getList()
      })
    })
  },

  methods: {
    toReport() {
      this.$linkTo('./AddUser')
    },

    getList() {

      this.$instance.post(`/app/appepidemicreportmember/list?openId=${this.user.openId}`, 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) {

            return false
          }

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

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

<style lang="scss" socped>
.returnHomeRegister {
  padding: 0 0 150px 0;

  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    padding: 48px 32px 0 32px;

    & > h2 {
      font-size: 38px;
      color: #333;
      font-weight: 600;
    }

    .right {
      display: flex;
      align-items: center;

      span {
        color: #666666;
        font-size: 28px;
      }

      i {
        color: #4181FF;
        font-style: normal;
        font-size: 28px;
      }
    }
  }

  .item {
    margin: 0 32px 24px;
    border-radius: 16px;
    background: #fff;

    .item-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 152px;
      padding: 0 32px;
      border-bottom: 1px solid #DDDDDD;

      .item-top__left {
        h2 {
          line-height: 44px;
          margin-bottom: 8px;
          color: #333;
          font-size: 32px;
          font-weight: 600;
        }

        p {
          color: #999999;
          font-size: 26px;
        }
      }

      & > span {
        font-size: 26px;
        color: #FF4466;
      }
    }

    .item-bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 104px;
      padding: 0 32px;

      .item-bottom__right {
        span {
          color: #999999;
          font-size: 28px;
        }
      }

      .item-bottom__left {
        span {
          color: #999999;
          font-size: 28px;
        }

        i {
          color: #4181FF;
          font-size: 28px;
        }
      }

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