Newer
Older
GDT_FRONT / src / views / visitor / visitList.vue
wangxitong on 17 Mar 2023 7 KB 0314修改
<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData(false)" @clear="clearInput">
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.keywords" size="small" placeholder="访客姓名" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.visitReason" size="small" placeholder="访问目的" clearable>
          <el-option
            v-for="item in reasonList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.position" size="small" placeholder="访问区域" clearable>
          <el-option
            v-for="item in areaList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="timeRange"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="起始日期"
          end-placeholder="终止日期"
          size="small"
        />
      </search-item>
    </search-area>
    <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :color-row="colorRow" :tools-option="tableOption.toolsOption" size="small" @change="changePage">
      <template slot="columns">
        <el-table-column label="访客照片" align="center" width="120">
          <template slot-scope="scope">
            <el-image :src="scope.row.picUri ? `${scope.row.picUri}`: defaultPhoto" :preview-src-list="srcList" width="50" height="50" style="width: 50px; height: 50px;margin-top: 10px" @error="errorImg"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="80">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="trail(scope.row)">
              轨迹追踪
            </el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <trail-dialog v-show="dialogFormVisible1" ref="trailDialog" @watchChild="fetchData" />
  </app-container>
</template>

<script>
import NormalTable from '@/components/NormalTable'
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import { getVisitListPage } from '@/api/visitor'
import { getDictByCode } from '@/api/system/dict'
import TrailDialog from '@/views/common/trailDialog';

export default {
  name: 'VisitList',
  components: { TrailDialog, SearchItem, SearchArea, AppContainer, NormalTable },
  data() {
    return {
      defaultPhoto: require('@/assets/global_images/photo.png'),
      errorImg: require('@/assets/global_images/photo_error.png'),
      srcList: [],
      listQuery: {
        keywords: '',
        visitReason: '',
        position: '',
        startTime: '',
        endTime: '',
        offset: 1,
        limit: 10
      }, // 筛选条件
      columns: [
        {
          text: '访客姓名',
          value: 'visitorName',
          align: 'center'
        },
        {
          text: '身份证号',
          value: 'IDcardm',
          align: 'center'
        },
        {
          text: '联系方式',
          value: 'visitorPhone',
          align: 'center'
        },
        {
          text: '进入时间',
          value: 'inTime',
          align: 'center'
        },
        {
          text: '离开时间',
          value: 'outTime',
          align: 'center'
        },
        {
          text: '进入方式',
          value: 'inType',
          align: 'center'
        },
        {
          text: '访问目的',
          value: 'visitReason',
          align: 'center'
        },
        {
          text: '访问区域',
          value: 'visitPosition',
          align: 'center'
        },
        {
          text: '累计访问次数(次)',
          value: 'frequency',
          align: 'center'
        }
      ], // 显示列
      dialogFormVisible: false, // 是否显示编辑框
      dialogFormVisible1: false, // 是否显示编辑框
      timeRange: [], // 时间范围
      multipleSelection: [], // 多选选中项
      list: [], // 列表数据
      reasonList: [],
      areaList: [],
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      colorRow: {
        isColor: true,
        param: 'checkPass'
      },
      tableOption: {
        head: {
          show: true, // 是否需要标题栏,
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: true // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false, // 是否需要刷新按钮
          needCheckBox: false
        }
      } // 表格属性
    }
  },
  watch: {
    timeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  created() {
    this.fetchOptions()
    this.fetchData()
  },
  methods: {
    fetchOptions() {
      getDictByCode('visitReason').then(response => {
        if (response.code === 200) {
          this.reasonList = response.data
        }
      })
      getDictByCode('devicePosition').then(response => {
        if (response.code === 200) {
          this.areaList = response.data
        }
      })
    },
    trail(row) {
      this.dialogFormVisible1 = true
      this.$refs.trailDialog.initDialog(row.picUri, row.visitorName)
    },
    encrypIdCardNo(idCard) {
      if (idCard.length > 6) {
        return idCard.substr(0, 6) + '********' + idCard.substr(14)
      } else if (idCard) {
        return idCard
      } else {
        return ''
      }
    },
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      getVisitListPage(this.listQuery).then(response => {
        if (response.code === 200) {
          this.list = response.data.rows.map(item => {
            item.IDcardm = this.encrypIdCardNo(item.idCard)
            return item
          })
          this.srcList = response.data.rows.map(item => item.picUri)
          this.total = parseInt(response.data.total)
          this.listLoading = false
        }
      })
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    clearInput() {
      this.listQuery = {
        keywords: '',
        visitReason: '',
        area: '',
        startTime: '',
        endTime: '',
        offset: 1,
        limit: 10
      }
      this.timeRange = []
      this.fetchData()
    }
  }
}
</script>

<style scoped>

</style>