<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
      label-position="left"
      label-width="76px"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="开始时间"
        prop="handOverStartTime"
      >
        <el-date-picker
          v-model="form.handOverStartTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="结束时间"
        prop="handOverEndTime"
      >
        <el-date-picker
          v-model="form.handOverEndTime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <div class="btn-wrap">
        <el-button
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="queryList(true)"
        >
          搜索
        </el-button>
      </div>
    </el-form>

    <div class="table-box">
      <!-- <div class="block-title">
        交班记录列表
      </div> -->
      <el-table
        stripe
        border
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="adminName"
          label="交班人"
        >
        </el-table-column>
        <el-table-column
          prop="handOverStartTime"
          label="开始时间"
        >
        </el-table-column>
        <el-table-column
          prop="handOverEndTime"
          label="结束时间"
        >
        </el-table-column>
        <el-table-column
          label="交班统计数据"
          prop="handOverStatistics"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="viewDetail(scope.row)">
              详情
            </el-link>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          width="120"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="downloadExport(scope.row)">
              下载
            </el-link>
            <el-link
              type="primary"
              @click="exportExcel(scope.row)">
              导出
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        @current-change="queryList()"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { apiHandOverList, apiHandOverDetail } from '@/api/handOver'
import { getPayStatus } from '@/utils/index'
import moment from 'moment'
// import ReaderInput from '@/components/ReaderInput'

export default {
  name: 'freeQuery',
  computed: {
    salesList () {
      return this.$store.state.user.salesList
    },
    saleChannel () {
      return this.$store.state.app.saleChannel
    },
    payChannelOptions () {
      return this.$store.getters.payChannelOptions
    },
    ticketTypeList () {
      return this.$store.state.app.ticketTypeList
    },
    scenicList () {
      return this.$store.state.app.scenicList
    }
  },
  components: {
    // ReaderInput
  },
  data () {
    return {
      form: {
        handOverStartTime: new Date(moment().startOf('day').valueOf()),
        handOverEndTime: new Date(moment().endOf('day').valueOf()),
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      deviceList: []
    }
  },
  created () {
    this.queryList()
  },
  methods: {
    getPayStatus,
    reset () {
      this.$refs.form.resetFields()
    },
    queryList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)
      apiHandOverList(this.form).then(res => {
        this.tableData = res.data.records || []
        this.total = res.data.total || 0
      }).finally(() => {
        this.loading = false
      })
    },
    exportExcel (row) {
      const params = {
        id: row.id,
        export: true,
        pageSize: -1,
        pageNum: 1
      }
      apiHandOverDetail(params).then(() => {
        this.$message.success('导出成功。')

        this.goToDownload()
      }, () => {
        this.$message.success('导出失败。')
      })
    },
    viewDetail (row) {
      this.$router.push({
        name: 'handOverReport', params: { id: row.id }
      })
    }
  }
}
</script>

<style scoped>

</style>
