<template>
  <div class="BackUserList">
    <div class="header">
      <div class="tab-item">
        <h2 style="color:#2C51CE;">{{totalInfo.total}}</h2>
        <p>返乡人员</p>
      </div>
      <div class="tab-item">
        <h2 style="color:#5AAD6A;">{{totalInfo.today}}</h2>
        <p>今日返乡</p>
      </div>
      <div class="tab-item">
        <h2 style="color:#F5A319;">{{totalInfo.todayUnusual}}</h2>
        <p>今日异常</p>
      </div>
      <div class="tab-item">
        <h2 style="color:#CD413A;border-right:0;">{{totalInfo.release}}</h2>
        <p>异常处理</p>
      </div>
    </div>
    <div class="search">
      <div class="left">
        <AiAreaPicker v-model="areaId" :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="name" :clearabled="true" placeholder="请输入姓名" :show-action="false" bg-color="#F5F5F5" search-icon-color="#999" color="#999" height="58" @search="getListInit" @clear="name='',getListInit"></u-search>
    </div>
    <div class="tab-select">
      <div class="item" :class="!tabIndex ? 'active' : ''" @click="tabClick(0)">返乡人员<span></span></div>
      <div class="item" :class="tabIndex ? 'active' : ''" @click="tabClick(1)">异常人员<span></span></div>
    </div>
    <div class="user-list">
      <div class="item" @click="toUser(item)" v-for="(item,index) in list" :key="index">
        <h2 class="name">{{item.name}}<span class="status" v-if="item.status == 0">有异常</span></h2>
        <p class="color-999">{{item.idNumber}}</p>
        <p><img src="./components/img/org-icon.png" alt="">{{item.startAreaName}}</p>
        <p><img src="./components/img/blue-icon.png" alt="">{{item.arriveAreaName}}</p>
        <p><img src="./components/img/time-icon.png" alt="">{{item.createTime}}</p>
      </div>
      <AiEmpty v-if="!list.length"></AiEmpty>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  data() {
    return {
      areaId: '',
      areaName: '',
      tabIndex: 0,
      current: 1,
      list: [],
      name: '',
      totalInfo: {}
    }
  },
  computed: { ...mapState(['user']) },
  onShow() {
    this.areaId = this.user.areaId
    this.areaName = this.user.areaName
    document.title = '返乡登记'
    this.getList()
    this.getTotal()
    uni.$on('updateList', () => {
      this.getListInit()
    })
  },
  methods: {
    areaSelect(e) {
      this.areaId =e
      this.$nextTick(() => {
        this.getListInit()
      })
      this.getTotal()
    },
    tabClick(index) {
      this.tabIndex = index
      this.getListInit()
    },
    getListInit() {
      this.current = 1
      this.list = []
      this.getList()
    },
    getList() {
      var status = ''
      if(this.tabIndex == 1) {
        status = 0
      }
      this.$http.post(`/app/appepidemicbackhomerecord/list?current=${this.current}&size=10&status=${status}&name=${this.name}&arriveAreaId=${this.areaId}`)
      .then((res) => {
        if (res.code == 0) {
          res.data.records.map((item) => {
            item.idNumber = item.idNumber.replace(/(.{6}).*(.{4})/,"$1********$2")
          })
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
    getTotal() {
      this.$http.post(`/app/appepidemicbackhomerecord/statistic?areaId=${this.areaId}`).then((res) => {
        if (res.code == 0) {
          this.totalInfo = res.data
        }
      })
    },
    toUser(row) {
      uni.navigateTo({url: `./UserInfo?id=${row.id}`})
    }
  },
  onReachBottom() {
    this.current ++
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.BackUserList {
  .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;
    }
  }
  .search{
    width: 100%;
    height: 112px;
    padding: 32px;
    box-sizing: border-box;
    background: #FFF;
    display: flex;
    margin-bottom: 8px;
    .left{
      width: calc(100% - 402px);
    }
  }
  .tab-select{
    width: 100%;
    height: 96px;
    background: #FFF;
    display: flex;
    margin-bottom: 4px;
    .item{
      flex: 1;
      font-size: 32px;
      line-height: 96px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #333;
      text-align: center;
    }
    .active{
      color: #135AB8;
      position: relative;
      span{
        position: absolute;
        bottom: 0;
        left: 50%;
        width: 192px;
        margin-left: -96px;
        border-bottom: 4px solid #135AB8;
      }
    }
  }
  .user-list{
    .item{
      padding: 32px 64px 24px;
      background-color: #fff;
      margin-bottom: 8px;
      .name{
        font-size: 36px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333;
        line-height: 50px;
        margin-bottom: 8px;
        .status{
          float: right;
          font-size: 28px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #FF4466;
          line-height: 40px;
        }
      }
      p{
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #333;
        line-height: 40px;
        margin-bottom: 8px;
        img{
          width: 32px;
          height: 32px;
          margin-right: 18px;
          vertical-align: middle;
        }
      }
      .color-999{
        margin-bottom: 24px;
        color: #999;
      }
    }
  }
}
</style>
