<template>
  <div class="Health">
    <div class="header">
      <div class="tab-item">
        <h2 style="color: #2c51ce">{{ userList.total }}</h2>
        <p>上报人员</p>
      </div>
      <div class="tab-item">
        <h2 style="color: #5aad6a">{{ userList.today }}</h2>
        <p>今日上报</p>
      </div>
      <div class="tab-item">
        <h2 style="color: #f5a319">{{ userList.unReport }}</h2>
        <p>今日未报</p>
      </div>
      <div class="tab-item">
        <h2 style="color: #cd413a; border-right: 0">{{ userList.unusual }}</h2>
        <p>今日异常</p>
      </div>
    </div>

    <div class="line1"></div>

    <div class="middle">
      <div class="left">
        <AiAreaPicker v-model="areaId" all :areaId="user.areaId" @select="areaSelect" :name.sync="areaName" style="color: #666">
          <u-icon name="map-fill" color="#3192F4" size="20px" style="vertical-align: text-bottom"></u-icon>
          <span style="margin-left: 4px" v-if="areaName">{{ areaName }}</span>
          <span v-else>请选择</span>
          <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" />
        </AiAreaPicker>
      </div>

      <u-search v-model="keyword" :clearabled="true" placeholder="请输入姓名" :show-action="false" bg-color="#F5F5F5" search-icon-color="#999" color="#999" height="58" @search="handerSearch" @clear="handerClear"></u-search>
    </div>

    <div class="line2"></div>

    <div class="bottoms">
      <u-tabs :list="tabList" :is-scroll="false" :current="currentTabs" height="96" bg-color="#fff" inactive-color="#333" bar-width="192" active-color="#135AB8 " @change="change"></u-tabs>

      <div class="line3"></div>

      <template v-if="data.length">
        <div class="templates" v-for="(item, i) in data" :key="i" @click="goDetail(item)">
          <img :src="item.avatar" alt="" v-if="item.avatar" />
          <img src="./components/img/user-img.png" alt="" v-else />

          <div class="rightCont">
            <div class="rightContLeft">
              <div class="nameLeft">
                <div class="nameTop">
                  <div class="names">{{ item.name }}</div>
                  <div class="types" v-if="item.status == '0'">异常</div>
                </div>

                <div class="nameBottom">
                  <span>上报第</span>
                  <span class="num">{{ item.diffNum }}</span>
                  <span>天</span>
                </div>
              </div>

              <div class="typeRight2" v-if="item.today == '0'">今日未上报</div>
              <div class="typeRight1" v-else>今日已上报</div>
            </div>

            <u-icon name="arrow-right" color="#ccc"></u-icon>
          </div>
        </div>
      </template>

      <AiEmpty description="暂无数据" class="emptyWrap" v-else></AiEmpty>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'Health',
  components: {},
  props: {},
  data() {
    return {
      keyword: '',
      areaId: '',
      areaName: '',

      current: 1,
      size: 10,

      tabList: [
        {
          name: '上报人员',
        },
        {
          name: '异常人员',
        },
      ],
      currentTabs: 0,
      userList: [],
      data: [],
    }
  },
  computed: {
    ...mapState(['user']),
  },
  watch: {},
  onLoad() {
    this.areaId = this.user.areaId
    this.areaName = this.user.areaName
    this.getList()
    this.getUserList()
  },
  onShow() {
    document.title = '健康上报'
  },
  methods: {
    getList() {
      this.$http
        .post('/app/appepidemicreportmember/list', null, {
          params: { size: this.size, current: this.current, status: this.currentTabs == 1 ? '0' : '', areaId: this.areaId, name: this.keyword },
        })
        .then((res) => {
          if (res.code == 0) {
            this.data = this.current > 1 ? [...this.data, ...res.data.records] : res.data.records
          } else {
          }
        })
        .catch(() => {})
    },

    getUserList() {
      uni.showLoading({
        title: '加载数据中',
      })
      this.$http
        .post('/app/appepidemicreportmember/statistic')
        .then((res) => {
          if (res.code == 0) {
            this.userList = res.data
            uni.hideLoading()
          } else {
            uni.hideLoading()
          }
        })
        .catch(() => {
          uni.hideLoading()
        })
    },

    goDetail(item) {
      uni.navigateTo({
        url: `./HealthDetail?id=${item.id}&diffNum=${item.diffNum}&today=${item.today}`,
      })
    },

    areaSelect(e) {
      this.areaId = e
      this.getList()
    },

    change(index) {
      this.data = []
      this.areaId = this.user.areaId
      this.keyword = ''
      this.currentTabs = index
      this.current = 1
      this.getList()
    },

    handerSearch(e) {
      this.keyword = e
      this.current = 1
      this.getList()
    },

    handerClear() {
      this.keyword = ''
      this.current = 1
      this.getList()
    },
  },
  onReachBottom() {
    this.current++
    this.getList()
  },
}
</script>

<style scoped lang="scss">
.Health {
  height: 100%;
  background: #fff;

  .header {
    padding: 54px 32px 48px 32px;
    display: flex;
    background-color: #fff;
    margin-bottom: 4px;
    .tab-item {
      flex: 1;
      text-align: center;

      h2 {
        font-size: 52px;
        font-family: DINAlternate-Bold, DINAlternate;
        font-weight: bold;
        height: 80px;
        margin-bottom: 8px;
        letter-spacing: -4px;
        border-right: 1px solid #ddd;
        line-height: 44px;
      }
      p {
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #999;
        line-height: 40px;
        margin-top: -22px;
      }
    }
    .tab-item:nth-last-of-type(1) {
      border-right: 0;
    }
  }

  .line1 {
    height: 4px;
    background: #f3f6f9;
  }

  .middle {
    display: flex;
    align-items: center;
    padding: 24px 32px;
    .left {
      width: 40%;
      display: flex;
      align-items: center;

      img {
        width: 48px;
        height: 48px;
      }
    }
  }

  .line2 {
    height: 8px;
    background: #f3f6f9;
  }

  .bottoms {
    .u-tabs {
      margin-bottom: -8px;
    }

    .line3 {
      height: 4px;
      background: #f3f6f9;
    }

    .templates {
      display: flex;
      align-items: center;
      padding: 32px;
      box-shadow: inset 0px -1px 0px 0px #dddddd;
      img {
        width: 128px;
        height: 128px;
        // border-radius: 50%;
        // border: 1px solid #cccccc;
      }
      .rightCont {
        display: flex;
        justify-content: space-between;
        margin-left: 32px;
        width: 100%;
        .rightContLeft {
          display: flex;
          justify-content: space-between;
          align-items: center;
          width: 100%;
          .nameLeft {
            .nameTop {
              display: flex;
              .names {
                font-size: 32px;
                font-weight: 500;
                color: #333333;
              }
              .types {
                margin-left: 16px;
                padding: 4px 16px 8px 16px;
                background: #faeceb;
                border-radius: 20px;
                font-size: 24px;
                color: #cd413a;
              }
            }
            .nameBottom {
              margin-top: 12px;
              font-size: 28px;
              color: #999999;
              .num {
                color: #135ab8;
              }
            }
          }
          .typeRight1 {
            font-size: 28px;
            color: #999999;
          }
          .typeRight2 {
            font-size: 28px;
            color: #f5a319;
          }
        }
      }
    }
  }
}
</style>
