<template>
  <div class="AppResidentFile">
    <div class="currentTabBar1">
      <AiTopFixed>
        <u-search placeholder="请输入昵称、姓名" :show-action="false" search-icon-color="#ccc" v-model="search.name" @search=";(page1.current = 1), getList()" />
        <AiCell>
          <b slot="label" class="title">共<i v-html="page1.total || 0" />个居民</b>
        </AiCell>
      </AiTopFixed>
      <div class="mainPane">
        <AiCell v-for="item in data" :key="item.id" @click.native="showResident(item)">
          <template #label>
            <AiImage :src="item.avatar" preview />
          </template>
          <div class="card wrap start" flex>
            <b>{{ item.name }}</b>
            <div flex class="tag" v-for="(tag, j) in item.tags" :key="j">{{ tag.tagName }}</div>
            <div class="realName" shrink v-html="`真实姓名：${item.realName || '-'}`" />
          </div>
        </AiCell>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'AppResidentFile',
  appName: '居民信息管理',
  data() {
    return {
      areaId: '',
      current: 1,
      data: [],
      search: { name: '' },
      page1: { current: 1, size: 10, total: 0 },
    }
  },
  computed: {
    ...mapState(['user', 'global']),
  },
  onLoad() {
    document.title = '居民信息管理'
    this.getList()
    this.areaId = this.user.areaId
  },
  methods: {
    // 居民列表
    getList() {
      this.$http.post('/app/wxcp/wxcustomer/list', null, {
        params: { ...this.page1, ...this.search, type: 1 },
      })
      .then((res) => {
        if (res?.data) {
          if (this.page1.current > 1) {
            this.data = [...this.data, ...res.data.records]
          } else this.data = res.data.records
          this.page1.total = res.data.total
        }
      })
    },
    showResident({ id }) {
      id &&
        uni.navigateTo({
          url: './resident?id=' + id,
        })
    },
  },
  onReachBottom() {
    this.page1.current++
    this.getList()
  },
}
</script>

<style scoped lang="scss">
.AppResidentFile {
  height: 100%;

  .currentTabBar1 {
    height: 100%;
    background: #fff;
    ::v-deep .AiTopFixed {
      b.title {
        color: #333;
        font-size: 32px;

        & > i {
          color: #267fce;
          font-style: normal;
          margin: 0 4px;
        }
      }
    }

    ::v-deep .mainPane {
      background: #fff;
      padding: 0 32px 0;

      .AiCell {
        flex-shrink: 0;
        justify-content: flex-start;

        .content {
          flex: 1;
          min-width: 0;
          max-width: unset;
          border-bottom: 1px solid rgba(221, 221, 221, 1);
          min-height: 160px;
        }
      }

      .card {
        text-align: left;

        b {
          max-width: 100%;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          font-size: 36px;
        }

        .tag {
          justify-content: center;
          background: #f3f4f7;
          border-radius: 4px;
          padding: 0 16px;
          font-size: 28px;
          font-weight: 400;
          color: #333;
          margin-left: 16px;
          margin-bottom: 16px;
          height: 56px;
        }

        .realName {
          width: 100%;
          margin-top: 8px;
          font-size: 28px;
          font-weight: 400;
          color: #999;
        }
      }

      .AiImage {
        margin-right: 24px;

        image {
          width: 112px;
          height: 112px;
        }
      }
    }
  }
  .tabs {
    width: 100%;
    height: 98px;
    background: #fff;
    border-top: 1px solid #ddd;
    position: fixed;
    bottom: 0;
    left: 0;
    display: flex;
    .item {
      flex: 1;
      text-align: center;
      img {
        width: 56px;
        height: 56px;
        margin-top: 8px;
      }
      p {
        font-size: 22px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #c4cad4;
        line-height: 8px;
      }
      .color-3267F0 {
        color: #3267f0;
      }
    }
  }
}
</style>
