<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
      label-width="70px"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        style="width:100%"
        label="售票员"
        prop="keyWords1">
        <el-select
          v-model="form.keyWords1"
          placeholder="请选择">
          <el-option
            label="全部"
            value="">
          </el-option>
          <el-option
            v-for="item in accoutList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <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="截止时间"
        prop="endDate"
      >
        <el-date-picker
          default-time="23:59:59"
          v-model="form.endDate"
          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="getList()"
        >
          搜索
        </el-button>
      </div>
    </el-form>

    <div class="table-box">
      <div class="block-title">
        补打信息
      </div>
      <el-table
        border
        stripe
        ref="table"
        :data="tableData"
        v-loading="loading"
      >
        <el-table-column
          prop="id"
          width="60"
          label="序号"
        >
        </el-table-column>
        <el-table-column
          width="160"
          prop="ticketNo"
          label="票号"
        >
        </el-table-column>
        <el-table-column
          width="160"
          prop="orderNo"
          label="订单号"
        >
        </el-table-column>
        <el-table-column
          width="160"
          prop="ticketTypeName"
          label="票种"
        >
        </el-table-column>
        <el-table-column
          width="160"
          prop="ticket_price"
          label="票价"
        >
        </el-table-column>
        <el-table-column
          width="160"
          prop="manager_name"
          label="操作员"
        >
        </el-table-column>
        <el-table-column
          label="打印时间"
        >
          <template slot-scope="scope">
            {{ scope.row.print_time | 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"
        @current-change="getList()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getAccountList } from '@/api/systemSetting/account'

import { getTicketSecondPrintLog } from '@/api/order'
import moment from 'moment'

export default {
  name: 'printQuery',
  components: {
  },
  computed: {
  },
  data () {
    return {
      accoutList: [],
      form: {
        pageNum: 1,
        pageSize: 10,
        keyWords1: '',
        startDate: new Date(moment().startOf('day').valueOf()),
        endDate: new Date(moment().endOf('day').valueOf())
      },
      tableData: [],
      total: 0,
      loading: false
    }
  },
  filters: {
  },
  mounted () {
    const searchParams = JSON.parse(sessionStorage.getItem('统计表-补打记录-查询条件'))
    if (searchParams) {
    // 如果存在查询条件，则设置到组件的数据中
      this.form = searchParams // 记住上次搜索条件
    }
    this.getAccountList()
    this.getList()
  },
  methods: {
    getAccountList () {
      this.loading = true
      getAccountList(this.params).then(res => {
        this.accoutList = res.list
      }).finally(() => {
        this.loading = false
      })
    },
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getList()
    },
    getList () {
      this.loading = true
      getTicketSecondPrintLog(this.form).then(res => {
        this.total = res.total
        this.tableData = res.list
      }).finally(() => {
        this.loading = false
        sessionStorage.setItem('统计表-补打记录-查询条件', JSON.stringify(this.form)) // 下次记住
      })
    }
  }
}
</script>
