<template>
  <div>
    <el-button size="small" type="primary" icon="el-icon-plus" @click="onShow" >新 建</el-button>
    <el-dialog
        :visible.sync="drawer"
        width="450px"
        @close="onClose"
        >
      <div>
        <el-row :gutter="50">
          <el-form :model="form" :rules="rules"  ref="form"  size="mini" label-position="left" label-width="80px">
            <el-col :span="20">
              <el-form-item prop="brandName" label="品牌名称">
                <el-input v-model="form.brandName" placeholder="输入品牌名称"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit"  class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  data(){
    return {
      drawer:false,
      url:null,
      rules:{
        brandName: [
          { required: true, message: '品牌名称不可为空', trigger: 'blur' },
        ],
      },
      form:{
        brandName:''
      },
    }
  },
  components:{
  },
  methods:{
    onShow (){
      this.drawer = true
    },
    onClose () {
      this.form = {
         brandName:''
      }
    },
    onSubmit () {
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": "20220922085003",
          "version": 1,
          "content": {
            "sa_brandid": 0,     //sa_brandid<=0时 为新增
            "brandname": this.form.brandName
          }
        })
        this.tool.showMessage(res, () => {
          this.ownerid = res.data
          this.drawer = false
          this.$emit('onSuccess')
        })
      })
    }
  }
}
</script>

<style scoped>

</style>