<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="文件名称"
        prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>

      <el-form-item
        label="任务状态"
        prop="status">
        <el-select
          v-model="form.status"
          clearable
          filterable>
          <el-option
            value=""
            label="全部"></el-option>
          <el-option
            :value="1"
            label="成功"></el-option>
          <el-option
            :value="2"
            label="进行中"></el-option>
          <el-option
            :value="0"
            label="失败"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="类型"
        prop="type">
        <el-select
          v-model="form.status"
          clearable
          filterable>
          <el-option
            value=""
            label="全部"></el-option>
          <el-option
            :value="1"
            label="导入"></el-option>
          <el-option
            :value="0"
            label="导出"></el-option>
        </el-select>
      </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
          label="创建时间"
          prop="createTime"
        >
        </el-table-column>
        <el-table-column
          label="文件名称"
          prop="fileName"
        >
        </el-table-column>
        <el-table-column
          label="类型"
          prop="type"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.type === '1' ? '导入' : '导出' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="任务状态"
          prop="status"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.status | filterStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="adminName"
          label="操作人"
        >
        </el-table-column>
        <el-table-column
          prop="reportTime"
          label="制表时间"
        >
        </el-table-column>
        <el-table-column
          prop="filterTime"
          label="筛选时间"
        >
        </el-table-column>
        <el-table-column
          prop="reportUser"
          label="制表人"
        >
        </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="deleteRecord(scope.row.id)">
              删除
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="queryList()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getReportList, deleteReport } from '@/api/order'
import { orderStatusDic, channelList } from '@/assets/staticData'
import { getPayStatus } from '@/utils/index'
// 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 {
      channelList,
      orderStatusDic,
      form: {
        name: '',
        status: '',
        type: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      deviceList: []
    }
  },
  created () {
    this.queryList()
  },
  filters: {
    filterStatus (val) {
      const status = Number(val)

      const statusMap = {
        1: '成功',
        2: '进行中'
      }
      return statusMap[status] || '失败'
    }
  },
  methods: {
    getPayStatus,
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.queryList()
    },
    queryList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)
      getReportList(this.form).then(res => {
        this.tableData = res.data.records || []
        this.total = res.data.total || 0
      }).finally(() => {
        this.loading = false
      })
    },
    deleteRecord (id) {
      this.$confirm('确定删除该记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteReport([id]).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
