<template>
  <div>
    <el-button size="mini" type="primary" @click="show" >新增产品信息</el-button>
    <el-dialog
        :visible.sync="dialogFormVisible"
        width="900px"
        @close="dialogFormVisible = false"
    >
      <div slot="title" style="font-size: 15px">
        新增产品信息
      </div>
      <div>
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules"  ref="form"  size="mini" label-position="right" label-width="90px">
            <el-col :span="20">
              <el-form-item  label="产品名称:" prop="itemname">
                <el-input  autosize v-model="form.itemname" placeholder="请输入产品名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item  label="规格尺寸:">
                <el-input  autosize v-model="form.spec" placeholder="请输入规格尺寸"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item  label="型号:">
                <el-input  autosize v-model="form.model" placeholder="请输入型号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item  label="价格:">
                <el-input  autosize v-model="form.price" placeholder="请输入价格"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit"   class="normal-btn-width btn-primary">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:["data"],
  name: "add",
  data(){
    return {
      dialogFormVisible:false,
      form:{
        sa_competitor_itemsid: 0,
        sa_competitorid: "",
        itemname: "",
        model: "",
        spec: "",
        price: ""
      },
      rules:{
        itemname:[
          { required: true, message: '未输入产品名称', trigger: 'blur'},
        ],
      }
    }
  },
  methods:{
    show(){
      this.form.sa_competitorid = this.data
      this.dialogFormVisible = true
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221019154902,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('insertSuccess')
          this.$refs['form'].resetFields()
          this.dialogFormVisible = false
        })
      })
    }
  }
}
</script>

<style scoped>

</style>