<template>
  <div>
    <el-button style="width:100%" :type="!disabled ?'':'primary'" size="mini" block  @click="onshow" :disabled="!disabled">作废</el-button>
    <el-dialog title="" :visible.sync="dialogForm" width="25%" append-to-body>
      <div slot="title" style="font-size: 15px">
        作废
      </div>
      <div>
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules"  ref="form"  size="mini" label-position="top" label-width="90px">
            <el-col :span="24">
              <el-form-item  label="作废原因:" prop="deletereason">
                <el-input type="textarea" v-model="form.deletereason"  placeholder="输入作废原因"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogForm = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "toVoid",
  props:["id","disabled"],
  data(){
    return {
      dialogForm:false,
      form:{
        deletereason:""
      },
      rules:{
        deletereason: [
          { required: true, message: '未填写作废原因', trigger: 'change' },
        ],
      }
    }
  },
  methods:{
    onshow(){
      this.dialogForm = true
      this.$emit("onshow")
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221012164002,
          "content": {
            "sa_customersids": [this.id],
            "datastatus": 1,//（0:正常；1:作废；2:锁定）,
            "deletereason":this.form.deletereason//作废时传，可选
          },
        })
        this.tool.showMessage(res,()=>{
          this.dialogForm = false
          this.$emit("toVoidSuccess")
          this.$store.dispatch('changeDetailDrawer',false)
        })
      })
    }
  }
}
</script>

<style scoped>

</style>