index.vue 4.06 KB
<template>
  <div>
    <template v-if="count">
      <div class="proxy-list proxy-header">
        <div class="proxy-item">访客</div>
        <div class="proxy-item">联系电话</div>
        <div class="proxy-item">最后访问日期</div>
        <div class="proxy-item">操作</div>
      </div>
      <div class="proxy-body">
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
          <van-list v-model="loading" :finished="finished" finished-text="已经到底啦" @load="onLoad">
            <div class="proxy-list" v-for="item in dataList" :key="item.id">
              <div class="proxy-item proxy-nickname">
                <div class="label">{{ item.nickName }}</div>
                <div>{{ item.type == 1 ? '@微信' : '' }}</div>
              </div>
              <div class="proxy-item">{{ item.phone }}</div>
              <div class="proxy-item">{{ item.lastTime }}</div>
              <div class="proxy-item" @click="popupShow(item)">访问记录</div>
            </div>
          </van-list>
        </van-pull-refresh>
      </div>
      <popup-comp :show.sync="show" :list="detailList"></popup-comp>
    </template>
    <van-empty description="暂无数据" v-else />
  </div>
</template>
<script>
import { businessApi } from '@/api'
import popupComp from './popupComp.vue'
export default {
  components: {
    popupComp
  },
  name: 'index',
  data() {
    return {
      dataList: [],
      detailList: [],
      loading: false,
      finished: false,
      refreshing: false,
      show: false,
      count: 1,
      pageNum: 0,
      pageSize: 20
    }
  },
  methods: {
    cardRecordPage() {
      this.loading = true
      const { pageNum, pageSize } = this
      businessApi.cardRecordPage({ pageNum, pageSize }).then(res => {
        if (res) {
          const dataList = res.data
          this.dataList = this.dataList.concat(dataList)
          this.count = res.count
          if (this.dataList.length <= this.count) {
            if (this.count === 0) {
              this.finished = true
            } else {
              this.finished = false
            }
          }
          this.loading = false
        }
      })
    },
    popupShow(item) {
      this.show = true
      this.detailList = item.recordRelationList
    },
    onLoad() {
      this.pageNum++
      this.loading = true
      const num = this.count / this.pageSize
      if (Number.isInteger(num)) {
        this.number = num
      } else {
        this.number = parseInt(num) + 1
      }
      if (this.dataList.length < this.count) {
        if (this.pageNum <= this.number) {
          this.cardRecordPage()
          this.loading = false
        }
      } else {
        this.loading = false
        this.finished = true
      }
    },
    onRefresh() {
      this.dataList = []
      this.pageNum = 1
      this.cardRecordPage()
      if (this.refreshing) {
        this.content = this.dataList
        this.dataList = this.content
        this.refreshing = false
      }
      this.loading = false
    }
  }
}
</script>
<style lang="scss" scoped>
.proxy-body {
  height: calc(100% - 90px);
  width: 100%;
  left: 0px;
  ::v-deep {
    .van-pull-refresh__track {
      overflow: auto;
    }
  }
}
.proxy-list {
  height: 56px;
  background: #ffffff;
  box-shadow: inset 0 -1px 0 0 #f2f2f2;
  display: flex;
  align-items: center;
  padding: 12px;
  box-sizing: border-box;
  &.proxy-header {
    height: 40px;
    background: #f2f2f2;
    .proxy-item {
      &:last-child {
        color: #414141;
      }
    }
  }

  .proxy-item {
    font-size: 14px;
    color: #414141;
    text-align: left;
    &.proxy-nickname {
      color: #2cca74;
      font-size: 11px;
      .label {
        display: inline-block;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        color: #414141;
        max-width: 70px;
        font-size: 14px;
      }
    }
    &:first-child {
      width: 84px;
    }
    &:last-child {
      width: 56px;
      white-space: nowrap;
    }
    &:nth-child(2),
    &:nth-child(3) {
      flex: 1;
    }
    &:last-child {
      color: #3975c6;
    }
  }
}

</style>