<template>
  <div class="list">
    <!-- <div class="tab">
      <span @click="changeTab(0)" :class="[currIndex === 0 ? 'active' : '']">高返贫风险人员</span>
      <span @click="changeTab(1)" :class="[currIndex === 1 ? 'active' : '']">监测对象风险解除</span>
    </div> -->
    <div class="list-wrapper">
      <div class="item" v-for="(item, index) in list" :key="index" hover-class="bg-hover" @click="toDetail(item.id)">
        <div class="item-top">
          <h2>{{ item.name || item.phone }}</h2>
          <span :style="{color: item.riskEliminationMethod ? '#2EA222' : '#FF4466'}">{{
              item.riskEliminationMethod ? '已解除' : '未解除'
            }}</span>
        </div>
        <p>{{ item.addressArea }} {{ item.address }}</p>
        <div class="item-bottom">家庭收入</div>
      </div>
      <AiEmpty v-if="!list.length && isMore" style="padding-bottom: 20px;"></AiEmpty>
    </div>
  </div>
</template>

<script>

export default {
  name: 'list',

  data() {
    return {
      list: [],
      isMore: false,
      current: 1,
      currIndex: 0
    }
  },

  created() {
    uni.showLoading()
    this.$nextTick(() => {
      this.getList()
    })
    uni.$on('reload', () => {
      this.reload()
    })
  },

  methods: {
    changeTab(index) {
      this.currIndex = index
    },

    toDetail(id) {
      uni.navigateTo({
        url: `./MonitorDetail?id=${id}&isFrom=1`
      })
    },

    reload() {
      this.isMore = false
      this.current = 1

      this.getList()
      uni.showLoading()
    },

    getList() {
      if (this.isMore) return

      this.$http.post(`/app/apppreventionreturntopoverty/list`, null, {
        params: {
          current: this.current,
          size: 15,
          status: 2
        }
      }).then(res => {
        if (res.code == 0) {
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records]
          } else {
            this.list = res.data.records
          }

          uni.hideLoading()

          if (res.data.records.length < 10) {
            this.isMore = true

            return false
          }

          this.current = this.current + 1
        } else {
          uni.hideLoading()
        }
      }).catch(() => {
        uni.hideLoading()
      })
    }
  }
}
</script>

<style lang="scss">
.list {
  padding: 30px 0 120px;

  .tab {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    align-items: center;
    width: 100%;
    height: 96px;
    padding: 0 60px;
    background: #FFFFFF;
    border-bottom: 1px solid #D4D4D4;
    box-sizing: border-box;

    * {
      box-sizing: border-box;
    }

    span {
      position: relative;
      flex: 1;
      height: 96px;
      line-height: 96px;
      color: #000000;
      text-align: center;
      font-size: 32px;

      &::after {
        position: absolute;
        bottom: 0;
        left: 50%;
        width: 192px;
        height: 6px;
        background: transparent;
        transform: translateX(-50%);
        content: ' ';
      }

      &.active {
        color: #1365DD;

        &::after {
          background: #1365DD;
        }
      }
    }
  }

  .list-wrapper {
    .item {
      margin: 0 32px 32px;
      padding-bottom: 10px;
      background: #FFFFFF;
      border-radius: 16px;

      .item-bottom {
        height: 94px;
        line-height: 94px;
        padding: 0 32px;
        border-top: 1px solid #DDDDDD;
        color: #3975C6;
        font-size: 26px;
      }

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

        h2 {
          color: #333333;
          font-size: 32px;
          font-weight: 700;
        }

        span {
          color: #FFBB00;

          &.status0 {
            color: #FF4466;
          }

          &.status1 {
            color: #3975C6;
          }
        }
      }

      p {
        line-height: 1.4;
        margin-bottom: 32px;
        padding: 0 32px;
        color: #999999;
        font-size: 26px;
      }
    }
  }
}
</style>
