<template>
  <div class="single-ticket">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="票号"
        prop="ticketPrepareNo"
      >
        <QRReader v-model="form.ticketPrepareNo"></QRReader>
      </el-form-item>
      <el-form-item
        label="批次号"
        prop="prepareBatchId"
      >
        <el-input v-model="form.prepareBatchId"></el-input>
      </el-form-item>
      <el-form-item
        label="票种"
        prop="ticketTypeId"
      >
        <el-select v-model="form.ticketTypeId">
          <el-option
            value=""
            label="全部"
          ></el-option>
          <el-option
            v-for="item in ticketTypeList"
            :key="item.id"
            :value="item.id"
            :label="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="状态"
        prop="status"
      >
        <el-select v-model="form.status">
          <el-option
            value=""
            label="全部"
          ></el-option>
          <el-option
            value="WAIT_ACTIVE"
            label="待激活"
          ></el-option>
          <el-option
            value="WAIT_USE"
            label="已出票（已激活）"
          ></el-option>
          <el-option
            value="USED"
            label="已使用"
          ></el-option>
          <el-option
            value="CANCELED"
            label="已取消"
          ></el-option>
        </el-select>
      </el-form-item>
      <div class="btn-wrap">
        <el-button
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          type="primary"
          @click="getData"
        >
          搜索
        </el-button>
        <!-- <el-button
          type="primary"
          @click="activateTicket()"
        >
          门票激活
        </el-button> -->
      </div>
    </el-form>
    <div class="table-box">
      <el-table
        stripe
        border
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          prop="prepareBatchId"
          label="预制批次号"
        ></el-table-column>
        <el-table-column
          prop="ticketTypeName"
          label="票种名称"
        >
        </el-table-column>
        <el-table-column
          prop="ticketPrepareNo"
          label="预制票号"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="状态"
        >
          <template slot-scope="scope">
            {{ scope.row.status | ticketStatus }}
          </template>
        </el-table-column>
        <el-table-column
          prop="playDateBegin"
          label="激活时选定的使用日期">
          <template slot-scope="scope">
            {{ scope.row.playDateBegin | formatTime }} - {{ scope.row.playDateEnd | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="prepareBatchDate"
          label="批次生成日期">
          <template slot-scope="scope">
            {{ scope.row.prepareBatchDate | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="activeTime"
          label="激活时间(出票时间)">
          <template slot-scope="scope">
            {{ scope.row.activeTime | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="activeType"
          label="激活方式">
          <template slot-scope="scope">
            {{ scope.row.activeType === 1 ? '管理后台免费门票激活' : '票务窗口付费门票激活' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="checkTime"
          label="使用时间">
          <template slot-scope="scope">
            {{ scope.row.checkTime | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="cancelTime"
          label="取消时间">
          <template slot-scope="scope">
            {{ scope.row.cancelTime | formatTime }}
          </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"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="getData()"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { ticketInStockDetail } from '@/api/ticketType'

export default {
  props: {
    ticketTypeList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      form: {
        ticketPrepareNo: '',
        prepareBatchId: '',
        ticketTypeId: '',
        pageNum: 1,
        pageSize: 10,
        status: ''
      },
      loading: false,
      total: 0,
      tableData: []
    }
  },
  filters: {
    ticketStatus (val) {
      switch (val) {
        case 'WAIT_ACTIVE':
          return '待激活'
        case 'WAIT_USE':
          return '已出票（已激活）'
        case 'USED':
          return '已使用'
        case 'CANCELED':
          return '已取消'
        default:
          return ''
      }
    },
    yesOrNo (val) {
      return val ? '是' : '否'
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getData()
    },
    getData () {
      this.loading = true
      ticketInStockDetail(this.form).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>
