<template>
  <section class="helpedResidentList">
    <div v-if="list.length">
      <div class="card" v-for="(item,index) in list" :key="index" @click="toDetail(item.id)">
        <p class="user">
          <span class="name">{{ item.name }}</span>
          <span :style="{color: item.houseType==1? '#FF6300': '#00D25D'}">{{ $dict.getLabel('fpHouseType', item.houseType) }}</span>
        </p>
        <div class="idCard">{{ item.idNumber.replace(/(.{6}).*(.{4})/, '$1********$2') }}</div>
        <div class="tel"><img src="./images/dh@2x.png" alt="">{{ item.phone }}</div>
        <div class="address"><img src="./images/dz@2x.png" alt="">
          {{ item.countyName + item.townName + item.villageName }}{{ item.currentAddress || '' }}
        </div>
      </div>
    </div>
    <AiEmpty v-else description="暂无数据"/>
  </section>
</template>

<script>
export default {
  name: "helpedResidentList",
  props: {
    current: {default: 1},
    search: {default: () => ({})}
  },
  data() {
    return {
      list: [],
      total: 0
    }
  },
  methods: {
    getList(must) {
      if (must || this.total == 0 || this.list.length < this.total) {
        const {current, search} = this.$props
        this.$http.post('/app/apppreventionreturntopoverty/list', null, {
          params: {...search, current},
        }).then((res) => {
          if (res?.data) {
            this.list = [current == 1 ? [] : this.list, res.data.records].flat().filter(Boolean)
            this.total = res.data.total
          }
        })
      }
    },
    toDetail(id) {
      uni.navigateTo({url: `./helpDetail?id=${id}`})
    },
  },
  watch: {
    current: {
      handler() {
        this.$u.throttle(this.getList)
      },
      immediate: true
    }
  }
}
</script>

<style lang="scss" scoped>
.helpedResidentList {
}
</style>
