<template>
  <el-dialog
    title="作废门票"
    :visible.sync="visible"
    width="640px"
    @close="handleClose">
    <el-form
      inline
      :model="form"
      ref="form"
      class="form-wrap"
      label-width="100px">
      <div class="dialog-info">
        <el-form-item
          style="width:100%"
          verify
          label="数量"
          prop="number">
          <el-input-number
            v-model="form.number"
            :min="1"
          ></el-input-number>
        </el-form-item>
        <el-form-item
          style="width:100%"
          verify
          label="票的税印起始"
          prop="ticketpaper_num_begin">
          <el-input v-model="form.ticketpaper_num_begin"></el-input>
        </el-form-item>
        <el-form-item
          style="width:100%"
          verify
          label="票的税印结束"
          prop="ticketpaper_num_end">
          <el-input v-model="form.ticketpaper_num_end"></el-input>
        </el-form-item>
      </div>
    </el-form>

    <div slot="footer">
      <el-button @click="handleClose">
        取 消
      </el-button>
      <el-button
        type="primary"
        :loading="loading"
        @click="handleSubmit">
        确 定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { invalidInventory } from '@/api/ticketInventory'

const defaultForm = {
  number: 1,
  ticketpaper_num_begin: '',
  ticketpaper_num_end: ''
}

export default {
  computed: {

  },
  data () {
    return {
      visible: false,
      loading: false,
      id: '',
      form: {
        ...defaultForm
      }
    }
  },
  methods: {
    show (data) {
      this.visible = true
      this.id = data.id
      this.$nextTick(() => {
        this.reset()
      })
    },
    reset () {
      this.$refs.form.resetFields()
    },
    handleClose () {
      this.visible = false
    },
    handleSubmit () {
      this.invalidInventory()
    },
    invalidInventory () {
      this.$refs.form.validate(valid => {
        if (valid) {
          let params = {
            from_warehouse_id: 0,
            number: this.form.number,
            remark: 'string',
            to_managerId: this.id,
            to_warehouse_id: 0,
            type: 'string',
            ticketpaper_num_begin: this.form.ticketpaper_num_begin,
            ticketpaper_num_end: this.form.ticketpaper_num_end
          }
          invalidInventory(params).then(res => {
            this.$message.success('作废成功')
          }).finally(() => {
            this.$emit('update')
            this.visible = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.periodItem {
  display: flex;  margin: 0 10px 10px 0; align-items: center;
}
.form-wrap {
  ::v-deep .el-form-item__label{
  width: 200px!important;
}
  .priceInput {
     margin: 0 10px;
    .el-input-number{
        width: 160px;
    }
    ::v-deep .el-input {
      width: 100%;
    }
  }
}

</style>
