<template>
  <el-dialog :visible="visible" width="500px" @close="handleClose" center :close-on-click-modal="false" title="设置供应商等级">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
      <el-form-item label="等级" prop="level">
        <el-select placeholder="供应商等级" v-model="ruleForm.level" style="width:100%">
          <el-option v-for="level in supplierLevelList.filter(({label}) => label !== '未设置')" :key="level.value" :value="level.value" :label="level.label" />
        </el-select>
      </el-form-item>

      <el-form-item class="flex-end">
        <el-button size="mini" type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { supplierLevelList } from "./../columns"
export default {
  props:['visible'],
  computed:{
    _visible:{
      get(){
        return this.visible
      },
      set(newVal){
        this.$emit("update:visible", newVal)
      }
    }
  },
  data(){
    return {
      supplierLevelList,
      ruleForm:{
        level:"",
      },
      rules:{
        level:[
          {
            required:true,
            trigger:'change',
            message:'请选择供应商等级'
          }
        ]
      }
    }
  },
  methods:{
    handleClose(){
      this._visible = false
      this.ruleForm = {
        bankName:"",
        bankNumber:""
      }
    },
    async onSubmit(){
      try{
        await this.$refs.ruleForm.validate()

        this.handleClose()
        this.$emit('refresh')
      }catch(e){
        console.log(e)
      }
    }
  }
}
</script>
