<template>
  <!-- 历史数据 -->
  <div class="fullHeight">
    <!-- <vue-scroll> -->
    <div class="searchBox whiteBlock">
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        size="medium"
      >
        <el-form-item :label="$t('message.deviceManage.date')">
          <el-date-picker
            v-model="time"
            type="datetimerange"
            :range-separator="$t('message.deviceManage.to')"
            :start-placeholder="$t('message.deviceManage.startDate')"
            value-format="yyyy-MM-dd HH:mm:ss"
            :end-placeholder="$t('message.deviceManage.endDate')"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="'健康码状态'" v-if="company == 'nanchang'">
          <el-select v-model="codeState" style="width: 120px">
            <el-option :label="$t('message.laborMange.all')" value></el-option>
            <el-option :label="'无码'" value="0"></el-option>
            <el-option :label="'红码'" value="1"></el-option>
            <el-option :label="'黄码'" value="2"></el-option>
            <el-option :label="'绿码'" value="3"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item :label="'报警类型'">
          <el-select
            v-model="formInline.alarmType"
            :placeholder="$t('message.carManage.placeholder_select')"
          >
            <el-option
              v-for="(item, index) in alarmTypeArr"
              :key="index"
              :label="item"
              :value="index + 1"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="人员姓名">
          <el-input
            v-model="formInline.workerName"
            placeholder="请输入人员姓名"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('message.carManage.carNumber')">
          <el-input
            v-model="formInline.carNumber"
            :placeholder="$t('message.deviceManage.placeholder')"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="onSubmit">{{
            $t('message.deviceManage.query')
          }}</el-button>
          <el-button type="warning" size="medium" plain @click="refresh">{{
            $t('message.deviceManage.refresh')
          }}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table_wrap whiteBlock">
      <el-table :data="tableData" class="tables">
        <el-table-column
          prop="carNumber"
          :label="$t('message.carManage.carNumber')"
        >
        </el-table-column>
        <!-- <el-table-column prop="carColour" :label="'车牌颜色'"> </el-table-column>
        <el-table-column prop="vehicleType" :label="'车型'"> </el-table-column>
        <el-table-column prop="alarmType" :label="'报警类型'">
          <template slot-scope="scope">
            {{ alarmTypeArr[scope.row.alarmType-1]}}
          </template>
        </el-table-column> -->
        <el-table-column prop="workerName" :label="'人员姓名'">
        </el-table-column>
        <el-table-column v-if="company == 'nanchang'" label="健康码">
          <template slot-scope="scope">
            <el-tag :type="parseCode(scope.row.codeState)[0]" size="small">{{
              parseCode(scope.row.codeState)[1]
            }}</el-tag>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="captureTime" :label="'抓拍时间'"> </el-table-column> -->
        <el-table-column prop="createTime" :label="'通行时间'">
        </el-table-column>
        <!-- <el-table-column prop="deviceNo" :label="'抓拍设备'"> </el-table-column> -->
        <el-table-column prop="passagewayName" :label="'闸机名称'">
        </el-table-column>
        <!-- <el-table-column prop="photoUrl" :label="'告警照片'">
          <template slot-scope="scope">
            <img :src="scope.row.photoUrl" height="30" :preview="scope.row.photoUrl">
          </template>
        </el-table-column> -->
        <el-table-column prop="photoUrl" :label="'照片'">
          <template slot-scope="scope">
            <img
              :src="$store.state.FILEURL + scope.row.fieldAcquisitionUrl"
              height="30"
              :preview="$store.state.FILEURL + scope.row.fieldAcquisitionUrl"
            />
          </template>
        </el-table-column>
        <el-table-column prop="passType" :label="'进出类型'">
          <template slot-scope="scope">
            <span>{{
              scope.row.passType == 1
                ? '进'
                : scope.row.passType == 2
                ? '出'
                : ''
            }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="vehicleType" :label="'司机'"> 
            <template slot-scope="scope">
              {{scope.row.driverData?JSON.parse(scope.row.driverData):''}}
              <div v-if="scope.row.driverData">
                <div v-for="(item,index) in JSON.parse(scope.row.driverData)" :key="index">
                  {{item.workerName}} - {{item.enterpriseName}}
                </div>
              </div>
              <el-tag size="small" style="margin-left:10px">黄码</el-tag>
            </template>
        </el-table-column> -->
        <!-- <el-table-column prop="vehicleType" :label="'司机电话'"> 
            <template>15878964589</template>
        </el-table-column> -->
        <!-- <el-table-column prop="vedioUrl" :label="'告警声音'">
          <template slot-scope="scope">
            <span @click="playVideo(scope.row.vedioUrl,'audio')">播放</span>
          </template>
        </el-table-column>
        <el-table-column prop="leaveTime" :label="'离开时间'"> </el-table-column>
        <el-table-column prop="leaveVedioUrl" :label="'离开工地视频'">
          <template slot-scope="scope">
            <span @click="playVideo(scope.row.leaveVedioUrl,'video')">播放</span>
          </template>
        </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>
    <!-- </vue-scroll> -->
    <el-dialog
      :modal-append-to-body="false"
      title="媒体播放"
      :visible.sync="dialogVisible"
      width="667px"
    >
      <div class="dialog_content">
        <video
          v-if="mediaType == 'video'"
          :src="mediaUrl"
          autoplay
          controls
        ></video>
        <audio v-else :src="mediaUrl" autoplay controls></audio>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import { getcarWashCurrentDataApi } from "@/assets/js/api/carManage";
import { getPageListApi } from '@/assets/js/api/laborPerson'

export default {
  name: 'historyData',
  data() {
    return {
      projectSn: '',
      alarmTypeArr: ['车辆绕行', '冲洗时间不足', '未冲洗', '其他', '正常冲洗'],
      time: [],
      // formInline: {
      //   endTime: "",
      //   startTime: "",
      //   devSn: "",
      //   carNumber: "",
      //   alarmType: "",
      // },
      formInline: {
        endTime: '',
        startTime: '',
        devSn: '',
        carNumber: '',
        workerName: ''
      },
      tableData: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      time: [],
      dialogVisible: false,
      mediaUrl: '',
      mediaType: '',
      company: '',
      codeState: ''
    }
  },
  created() {
    this.projectSn = this.$store.state.projectSn
    this.company = COMPANY
    let nowTime = this.selectNowDate()
    this.time = [nowTime.split(' ')[0] + ' ' + '00:00:00', nowTime]
    this.onSubmit()
  },
  methods: {
    parseCode(code) {
      if (code == 0) {
        return ['info', '无码']
      } else if (code == 1) {
        return ['danger', '红码']
      } else if (code == 2) {
        return ['warning', '黄码']
      } else if (code == 3) {
        return ['success', '绿码']
      } else {
        return ['info', '无码']
      }
    },
    playVideo(src, type) {
      this.mediaUrl = src
      this.mediaType = type
      this.dialogVisible = true
    },
    refresh() {
      this.time = []
      this.formInline.carNumber = ''
      let nowTime = this.selectNowDate()
      this.time = [nowTime.split(' ')[0] + ' ' + '00:00:00', nowTime]
      this.formInline.alarmType = ''
      this.pageNo = 1 //页数
      this.pageSize = 10 //条数
      this.onSubmit()
    },
    //查询列表
    // onSubmit() {
    //   if (this.time.length == 0 || this.time == null) {
    //     this.formInline.endTime = "";
    //     this.formInline.startTime = "";
    //   } else {
    //     this.formInline.startTime = this.time[0];
    //     this.formInline.endTime = this.time[1];
    //   }
    //   let data = this.formInline;
    //   data.projectSn = this.projectSn;
    //   data.pageNo = this.pageNo;
    //   data.pageSize = this.pageSize;

    //   getcarWashCurrentDataApi(data).then((res) => {
    //     if (res.code == 200) {
    //       this.total = res.result.total;
    //       this.tableData = res.result.records;
    //       setTimeout(() => {
    //         this.$previewRefresh();
    //       }, 100);
    //     }
    //   });
    // },
    // 获取当前时间 返回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
      console.log(timer)
      return timer
    },
    onSubmit() {
      if (this.time.length == 0 || this.time == null) {
        this.formInline.endTime = ''
        this.formInline.startTime = ''
      } else {
        this.formInline.startTime = this.time[0]
        this.formInline.endTime = this.time[1]
      }
      let data = this.formInline
      data.projectSn = this.projectSn
      data.pageNo = this.pageNo
      data.pageSize = this.pageSize
      data.cardType = '8'
      if (this.company == 'nanchang') {
        data.codeState = this.codeState
      }
      getPageListApi(data).then((res) => {
        if (res.code == 200) {
          console.log(res)
          this.total = res.result.total
          this.tableData = res.result.records
          setTimeout(() => {
            this.$previewRefresh()
          }, 100)
        }
      })
    },
    handleSizeChange(value) {
      this.pageSize = value
      this.onSubmit()
    },
    handleCurrentChange(value) {
      this.pageNo = value
      this.onSubmit()
    }
  }
}
</script>
<style lang="less" scoped>
</style>