<template>
  <div>
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
      label-width="140px"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="门票预制票号"
        prop="ticketPrepareNo"
      >
        <el-input v-model="form.ticketPrepareNo"></el-input>
        <el-tag type="info" style="margin: 5px">连续票号可以用'-'分隔输入 比如HH001-HH005 单次不超过500张</el-tag>
      </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="logReturnStorage({})"
        >
          退库
        </el-button> -->
      </div>
    </el-form>
    <el-table
      stripe
      border
      v-loading="loading"
      :data="tableData"
    >
      <el-table-column
        prop="manager_name"
        label="操作员"
      >
      </el-table-column>
      <el-table-column
        prop="ticketNoStartIndex"
        label="起始序号"
      >
      </el-table-column>
      <el-table-column
        prop="ticketNoEndIndex"
        label="截止序号"
      >
      </el-table-column>
      <el-table-column
        width="80"
        label="数量"
      >
        <template slot-scope="scope">
          {{ scope.row.ticketNoEndIndex - scope.row.ticketNoStartIndex + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
      >
        <template slot-scope="scope">
          {{ scope.row.createTime | formatTime }}
        </template>
      </el-table-column>
      <el-table-column
        label="完成时间"
      >
        <template slot-scope="scope">
          {{ scope.row.finish_time | formatTime }}
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
      >
        <template slot-scope="scope">
          {{ statusDic[scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="logReturnStorage(scope.row)">
            退库
          </el-button>
        </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>
    <ElDialog
      title="门票退库"
      width="700px"
      v-model="returnStorageVisible">
      <ReturnStorage
        :current-log="currentLog"
        @update="getData"
      ></ReturnStorage>
    </ElDialog>
  </div>
</template>
<script>
import { getMission } from '@/api/ticketType'
import ElDialog from '@/components/Dialog'
import ReturnStorage from './returnStorage'
export default {
  components: {
    ElDialog,
    ReturnStorage
  },
  data () {
    return {
      form: {
        ticketPrepareNo: '',
        pageNum: 1,
        pageSize: 10,
        startDate: '',
        endDate: ''
      },
      loading: false,
      total: 0,
      tableData: [],
      returnStorageVisible: false,
      currentLog: {},
      typeDic: {
        'ADD': '入库',
        'EXPORT': '导出',
        'ACTIVATE': '激活',
        'RETURN': '退库'
      },
      statusDic: {
        'WAITING': '未开始',
        'PROCESSING': '处理中',
        'FINISH': '成功',
        'FAIL': '失败'
      }
    }
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getData()
    },
    getData () {
      this.loading = true
      getMission(this.form).then(res => {
        this.tableData = res.list
        this.total = res.total
      }).finally(() => {
        this.loading = false
      })
    },
    // 按入库记录来退库
    logReturnStorage (item) {
      if (item.ticketNoStartIndex && item.ticketNoEndIndex) {
        this.currentLog = item
      } else {
        this.currentLog = {}
      }
      this.returnStorageVisible = true
    }
  }
}
</script>
