<template>
  <vxe-modal v-model="value" id="addQuest" width="400" v-loading="load" @show="show" @hide="hide" height="200" show-footer title="新增异常类型">
    <by-form :propConfig="config" ref="form"></by-form>
    <template #footer>
      <div class="btn">
        <el-button plain size="small" @click="value = false">取消</el-button>
        <el-button type="primary" size="small" @click="btn">确定</el-button>
      </div>
    </template>
  </vxe-modal>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { save } from '@/api/question'
@Component({components:{}})
export default class AddQuestModel extends Vue {
  value = false;
  load = false;
  config:any={
    attr:{
      rules:{
        type: [
          { required: true, message: '请输入类型', trigger: 'blur' }
        ]
      }
    },
    columns:[
      [{
        label:'类型',
        prop:'type',
        labelWidth:'80px',
        component:'by-input'
      }]
    ]
  }
  show(){
    
  }
  hide(){
    (this.$refs.form as any).clearValidate();
    (this.$refs.form as any).clearValue();
  }
  setShow(v:boolean){
    this.value = v;
  }
  btn(){
    (this.$refs.form as any).validate().then(()=>{
      let data = (this.$refs.form as any).getValue();
      this.load = true
      save(data).then(()=>{
        this.load = false;
        this.$emit('handleSuccess');
        this.value = false;
      }).catch(()=>{
        this.load = false;
      })
    })
  }
}
</script>

<style lang="scss" scoped>

</style>