<template>
  <div>
    <el-button size="mini" @click="dialog=true" type="primary">作 废</el-button>
    <el-dialog append-to-body width="600px" title="作废" :visible.sync="dialog">
      <el-row :gutter="20">
        <el-form label-position="right" ref="form" :rules="rules" inline label-width="100px" :model="form" size="small">
          <el-col :span="24">
            <el-form-item label="作废原因" prop="deletereason">
              <el-input v-model="form.deletereason" style="width: 400px" placeholder="请输入作废原因名称"></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialog = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: '',
  data() {
    return {
      dialog:false,
      deletereason:'',
      form: {
        "deletereason": ""
      },
      rules:{
        deletereason: [
          { required: true, message: '请填写作废原因', trigger: 'blur' },
        ],
      }
    };
  },
  props:['idName','idKey','id'],
  computed:{
  },
  watch:{
  },
  methods: {
    onSubmit () {
      this.$refs.form.validate(async(valid)=>{
        if (!valid) return false
        let res = await this.$api.requested({
          "id": this.idName,
          "content": {
            [this.idKey]: [this.id],
            "deletereason":this.form.deletereason
          },
        })
        this.tool.showMessage(res,() => {
          this.dialog = false
          this.$store.dispatch('changeDetailDrawer',false)
          this.$emit('onSuccess')
        })
      })

    }
  },
};
</script>

<style scoped>

</style>
