<template>
  <vxe-modal v-model="value" id="addLabel" width="400" v-loading="load" @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/omsLabel'
@Component({components:{}})
export default class AddQuestModel extends Vue {
  value = false;
  load = false;
  config:any={
    attr:{
      rules:{
        name: [
          { required: true, message: '名称不能为空！', trigger: 'blur' }
        ]
      }
    },
    columns:[
      [{
        label:'名称',
        prop:'name',
        labelWidth:'80px',
        component:'by-input'
      }]
    ]
  }

  @Prop({
    type:Number,
    default:1
  })
  isSystem?:number
  
  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({noMsg:true}).then(()=>{
      let data = (this.$refs.form as any).getValue();
      data.isSystem = this.isSystem;
      this.load = true;
      save(data).then(()=>{
        this.load = false;
        this.$emit('handleSuccess');
        this.value = false;
      }).catch(()=>{
        this.load = false;
      })
    }).catch(() => {})
  }
}
</script>

<style lang="scss" scoped>

</style>