<template>
  <div class="content">
    <div class="search-box">
      <div class="search-item">
        <span style="margin-right: 10px">人员姓名</span>
        <el-input
          v-model="personName"
          size="medium"
          style="width: 200px; margin-right: 50px"
        ></el-input>
        <span style="margin-right: 10px">时间段</span>
        <el-date-picker
          size="medium"
          v-model="valueTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </div>
      <el-button type="primary" plain size="medium" @click="quertData"
        >查询</el-button
      >
      <el-button type="warning" plain size="medium" @click="refresh"
        >刷新</el-button
      >
    </div>
    <div class="table-box">
      <el-table
        :data="tableData"
        class="tables"
        height="560"
        style="width: 100%"
      >
        <el-table-column align="center" label="标签类型" prop="cardType">
          <template
            slot-scope="scoped"
            >{{ scoped.row.cardType==1510?'人员': scoped.row.cardType==1520?'车辆':'无'}}</template
          >
        </el-table-column>
        <el-table-column align="center" label="标签号" prop="cardno">
        </el-table-column>
        <el-table-column align="center" label="人员姓名" prop="personName">
        </el-table-column>
        <el-table-column align="center" label="Y值随机值(px)" prop="py">
        </el-table-column>
        <el-table-column align="center" label="距离洞口（米）" prop="inlX">
        </el-table-column>
        <el-table-column align="center" label="上传时间" prop="createTime">
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagerBox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="$store.state.PAGESIZRS"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="Number(total)"
        background
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getLocationDataPageApi
} from "@/assets/js/api/tunnelPositioning";
export default {
  data() {
    return {
      personName: '',
      projectSn: '',
      tableData: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      valueTime: ''
    }
  },
  created() {
    this.projectSn = this.$store.state.projectSn
    // this.selectNowDate()
    this.getTunnrlData()
  },

  methods: {
    // 获取当前时间 返回YYYY-MM-DD HH:mm:ss
    selectNowDate() {
      var date = new Date(),
        year = date.getFullYear(),
        month = date.getMonth() + 1,
        day = date.getDate(),
        hours = date.getHours(), //获取当前小时数(0-23)
        minutes = date.getMinutes(), //获取当前分钟数(0-59)
        seconds = date.getSeconds()
      month >= 1 && month <= 9 ? (month = '0' + month) : ''
      day >= 0 && day <= 9 ? (day = '0' + day) : ''
      hours >= 0 && hours <= 9 ? (hours = '0' + hours) : ''
      minutes >= 0 && minutes <= 9 ? (minutes = '0' + minutes) : ''
      seconds >= 0 && seconds <= 9 ? (seconds = '0' + seconds) : ''
      var timer = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
      // var timer = year + '-' + month + '-' + day
      this.valueTime = [timer, timer]
      console.log(timer)
      // return timer;
    },

    quertData() {
      this.pageNo = 1
      this.pageSize = 10
      this.getTunnrlData()
    },
    refresh() {
      this.pageNo = 1
      this.pageSize = 10
      this.total = 0
      this.personName = ''
      this.valueTime = ''
      this.getTunnrlData()
    },
    getTunnrlData() {
      let data = {
        personName: this.personName,
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        projectSn: this.projectSn,
        createTime_begin: this.valueTime ? this.valueTime[0] : '',
        createTime_end: this.valueTime ? this.valueTime[1] : ''
      }
      getLocationDataPageApi(data).then((res) => {
        console.log(res)
        if (res.code == 200 && res.result) {
          this.tableData = res.result.records
          console.log(this.tableData)
          this.total = res.result.total
        }
      })
    },
    handleSizeChange(value) {
      this.pageSize = value
      this.getTunnrlData()
    },
    handleCurrentChange(value) {
      this.pageNo = value
      this.getTunnrlData()
    },
  }
}
</script>

<style lang="less" scoped>
.content {
  display: flex;
  flex-direction: column;
  height: 100%;

  .search-box {
    background: #fff;
    padding: 25px;
    margin-bottom: 14px;

    .search-item {
      display: inline-block;
      margin-right: 26px;
    }
  }

  .table-box {
    flex: 1;
    background: #fff;

    /deep/.el-table {
      td {
        vertical-align: top;
      }

      .cell {
        padding-left: 44px;
      }
    }

    .f-2 {
      display: flex;
      flex-wrap: wrap;

      .table-item {
        width: 50%;
      }
    }
  }
}
</style>
