<template>
  <div>
    <el-button size="mini" style="margin-left: -70px" @click="dialogVisible = true">作 废</el-button>
    <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="900px"
        center>
      <span>是否确定作废该竞争对手</span>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onshow"  class="normal-btn-width btn-primary">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
        :visible.sync="dialogToVoidVisible"
        width="900px"
        @close="dialogToVoidVisible = false"
    >
      <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="right" label-width="90px">
            <el-col :span="20">
              <el-form-item  label="作废原因:" prop="deletereason">
                <el-input type="textarea"  autosize 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="dialogToVoidVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit"   class="normal-btn-width btn-primary">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "toVoid",
  props:["data"],
  data(){
    return {
      dialogVisible:false,
      dialogToVoidVisible:false,
      form:{
        sa_competitorid:"",
        deletereason:""
      },
      rules:{
        deletereason:[
          { required: true, message: '作废原因不能为空', trigger: 'blur' },
        ]
      }
    }
  },
  methods:{
    onshow(){
      this.dialogVisible = false
      this.dialogToVoidVisible = true
      this.form.sa_competitorid = this.data.sa_competitorid
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221018164202,
          "content": {
            "sa_competitorids":[this.form.sa_competitorid],
            "deletereason":this.form.deletereason
          },
        })
        this.tool.showMessage(res,() => {
          this.$emit('onSuccess')
          this.$refs['form'].resetFields()
          this.dialogToVoidVisible = false
          this.$router.go(-1)
        })
      })
    }
  }
}
</script>

<style scoped>

</style>