<template>
  <div class="form-wrap">
    <div class="searchBox">
      <el-form
        ref="form"
        :model="form"
        :inline="true"
        label-width="70px">
        <el-form-item
          label="导出时间"
          prop="startDate">
          <el-date-picker
            v-model="form.startDate"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label-width="30px"
          label="至"
          prop="endDate">
          <el-date-picker
            v-model="form.endDate"
            default-time="23:59:59"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="导出人"
          prop="keyWords1">
          <el-input
            v-model="form.keyWords1"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="导出类型"
          prop="keyWords2">
          <el-select v-model="form.keyWords2">
            <el-option
              value=""
              label="全部">
            </el-option>
            <el-option
              value="订单列表"
              label="订单列表">
            </el-option>
            <el-option
              value="检票报表"
              label="检票报表">
            </el-option>
            <el-option
              value="游客查询"
              label="游客查询">
            </el-option>
            <el-option
              value="营业汇总"
              label="营业汇总">
            </el-option>
            <el-option
              value="检票员检票"
              label="检票员检票">
            </el-option>
            <el-option
              value="改签报表"
              label="改签报表">
            </el-option>
            <el-option
              value="游客信息"
              label="游客信息">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="btn-wrap">
        <el-button @click="reset">重置</el-button>
        <el-button
          type="primary"
          @click="getExportMissionList($event,true)">搜索</el-button>
      </div>
    </div>

    <div class="tableBox">
      <div class="block-title">
        导出记录
      </div>

      <el-table
        :data="tableData"
        v-loading="loading">
        <el-table-column
          width="120"
          prop="type"
          label="导出类型">
        </el-table-column>
        <el-table-column
          prop="search_condition"
          label="导出条件">
        </el-table-column>
        <el-table-column
          width="160"
          prop="createtime"
          label="创建时间">
        </el-table-column>
        <el-table-column
          width="120"
          prop="operator"
          label="导出人">
        </el-table-column>
        <el-table-column
          width="120"
          label="状态">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status===3?'danger':scope.row.status===2?'success':''">{{ statusFormat(scope.row.status) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          width="120"
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="downloadExport(scope.row)"
            >下载</el-button>
            <el-button
              type="text"
              @click="deleteExport(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        @current-change="getExportMissionList"
        layout="total, prev, pager, next"
        :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getExportMissionList, deleteExportMission } from '@/api/queryReport.js'
import moment from 'moment'
export default {
  name: 'reportExport',
  data () {
    return {
      form: {
        startDate: '',
        endDate: '',
        keyWords1: '', // 导出人
        keyWords2: '', // 导出类型
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      currentItem: {},
      orderDialogVisible: false,
      guestDialogVisible: false
    }
  },
  created () {
    this.getExportMissionList()
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    getExportMissionList (e, goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)
      getExportMissionList(this.form).then(res => {
        this.total = res.total
        res.list.forEach(element => {
          element.createtime = moment(element.createtime).format('YYYY-MM-DD HH:mm:ss')
        })
        this.tableData = res.list
        this.loading = false
      })
    },
    downloadExport (data) {
      window.location.href = data.download_url
    },
    statusFormat (e) {
      switch (e) {
        case 0:
        case 1:
          return '处理中'
        case 2:
          return '成功'
        case 3:
          return '失败'
      }
    },
    deleteExport (data) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteExportMission({id: data.id}).then(res => {
          this.$message.success('删除成功')
          this.getExportMissionList()
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
