<template>
  <el-form
    inline
    label-width="100px"
    :model="form"
    class="form-wrap"
    ref="form">
    <div class="dialog-info">
      <el-form-item
        label="票种名称"
        v-if="currentLog.ticketTypeName">
        {{ currentLog.ticketTypeName }}
      </el-form-item>
      <el-form-item
        label="创建时间"
        v-if="currentLog.createTime">
        {{ currentLog.createTime | formatTime }}
      </el-form-item>
      <div
        class="clearfix"
        style="width:100%"></div>
      <el-form-item
        verify
        label="序号"
        prop="minId">
        <el-input-number
          v-model="form.minId"
          :max="form.maxId"
          :step="1"
          :precision="0"></el-input-number>
      </el-form-item>
      <el-form-item
        verify
        label-width="40px"
        label="至"
        prop="maxId">
        <el-input-number
          v-model="form.maxId"
          :min="form.minId"
          :step="1"
          :precision="0"></el-input-number>
      </el-form-item>
    </div>
    <div class="dialog-btn-wrap">
      <el-button
        type="primary"
        @click="submit">
        确定
      </el-button>
    </div>
  </el-form>
</template>
<script>
import { ticketBackToStock } from '@/api/ticketType'
export default {
  props: {
    currentLog: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      visible: false,
      form: {
        minId: 0,
        maxId: 0
      }
    }
  },
  watch: {
    visible (val) {
      if (val) {
        this.reset()
        console.log(this.currentLog)
        this.form.minId = this.currentLog.ticketNoStartIndex
        this.form.maxId = this.currentLog.ticketNoEndIndex
      }
    }
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    handleClose () {
      this.$parent.handleClose()
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          ticketBackToStock(this.form).then(res => {
            this.$message.success('退库成功')
            this.handleClose()
            this.$emit('update')
          })
        }
      })
    }
  }
}
</script>
