index.vue 5.63 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">
                <label>{{ item.nickName }}</label>
                {{ item.type == 1 ? '@微信' : '' }}
              </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>
      <van-popup v-model="show" position="bottom" round :style="{ 'min-height': '40%', 'max-height': '80%', 'overflow-y': 'hidden', 'padding-bottom': '30px' }">
        <div class="popup-header">
          <div class="popup-title">访问记录</div>
          <div class="popup-icon"><van-icon name="cross" @click="show = false" /></div>
        </div>
        <div class="popup-content">
          <div class="popup-content-header">
            <div class="popup-item">序号</div>
            <div class="popup-item">访问页面</div>
            <div class="popup-item">访问时间</div>
          </div>
          <div class="popup-content-body" v-for="(item, index) in detailList" :key="item.id">
            <div class="popup-item">{{ index + 1 }}</div>
            <div class="popup-item">{{ item.pageName }}</div>
            <div class="popup-item">{{ item.createdTime }}</div>
          </div>
        </div>
      </van-popup>
    </template>
    <van-empty description="暂无数据" v-else />
  </div>
</template>
<script>
import { businessApi } from '@/api'
export default {
  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 {
  position: absolute;
  top: 48px;
  height: calc(100% - 48px);
  width: 100%;
  left: 0px;
  ::v-deep {
    .van-pull-refresh__track {
      overflow: auto;
    }
  }
}
.proxy-list {
  height: 48px;
  line-height: 48px;
  background: #ffffff;
  box-shadow: inset 0 -1px 0 0 #f2f2f2;
  display: flex;
  &.proxy-header {
    position: fixed;
    width: 100%;
    top: 0px;
    left: 0px;
    background: #f2f2f2;
    .proxy-item {
      &:last-child {
        color: #414141;
      }
    }
  }

  .proxy-item {
    font-size: 13px;
    color: #414141;
    text-align: center;
    &.proxy-nickname {
      color: #2cca74;
      label {
        display: inline-block;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        color: #414141;
        max-width: 70px;
      }
    }
    &:first-child {
      width: 120px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    &:last-child,
    &:nth-child(2),
    &:nth-child(3) {
      flex: 1;
    }
    &:last-child {
      color: #3975c6;
    }
  }
}
.popup-header {
  height: 56px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px 16px;
  .popup-title {
    font-weight: 500;
    font-size: 16px;
    color: #222222;
  }
}
.popup-content {
  max-height: calc(80vh - 50px);
  overflow: auto;
  &-header {
    display: flex;
    height: 40px;
    line-height: 48px;
    background: #f2f2f2;
    text-align: center;
    .popup-item {
      font-weight: 600;
      font-size: 14px;
      color: #333333;
    }
  }
  &-body {
    display: flex;
    height: 48px;
    line-height: 48px;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    text-align: center;
  }
  .popup-item {
    font-size: 14px;
    color: #666666;
    &:first-child {
      width: 60px;
    }
    &:nth-child(2),
    &:nth-child(3) {
      flex: 1;
    }
  }
}
</style>