<template>
  <vxe-modal v-model="value" id="setQuest" width="400" v-loading="load" @hide="hide" height="300" 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 { setQuestions } from '@/api/omsOrder'
@Component({components:{}})
export default class SetQuesModal extends Vue {
  value = false;
  load = false;
  billValue:Array<any>=[]
  config:any={
    attr:{
      rules:{
        questionType: [
          { required: true, message: '请选择类型', trigger: 'change' }
        ]
      }
    },
    columns:[
      [{
        label:'类型',
        prop:'questionType',
        labelWidth:'80px',
        component:'by-select',
        compConfig:{
          attr:{
            data:[],
            label:'type',
            value:'id'
          }
        }
      }],
      [{
        label:'描述',
        prop:'questionDesc',
        labelWidth:'80px',
        component:'by-input',
        compConfig:{
          attr:{
            type:'textarea',
            rows:3
          }
        }
      }]
    ]
  }
  show(){
    
  }
  setQuestTypeData(data:Array<any>){
    let c = this.config.columns[0][0].compConfig;
    c.attr.data = data;
    if(this.$refs.form){
      (this.$refs.form as any).setCompConfig('questionType',c)
    }
  }
  setBillValue(data:Array<any>){
    this.billValue = data;
  }
  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();
      data.idList = this.billValue;
      this.load = true
      setQuestions(data).then(()=>{
        this.load = false;
        (this.$message({
          message:'操作成功！',
          type:'success'
        }));
        this.$emit('handleSuccess');
        this.value = false;
      }).catch(()=>{
        this.load = false;
      })
    })
  }
}
</script>