vue 添加弹窗组件封装包含接口请求

js yekong

使用

<add @getdata="getlist"></add>

代码

/**
* @Author: 858834013@qq.com
* @Name: add
* @Date: 2022-05-17
* @Desc:
*/
<template>
  <div>
    <el-button type="primary" @click="dialogVisible = true">
      <i class="iconfont icon-tianjia"></i>添加设备
    </el-button>
    <el-dialog :visible.sync="dialogVisible" width="700px" custom-class="custom-dialog">
      <div slot="title">
        <div class="dialog-title">
          <img src="../../assets/image/icon2.png" alt="">
          设备号录入
        </div>
      </div>
      <div class="dialog-body">
        <el-form ref="form" :model="form" class="bs-form" label-width="170px">
          <el-form-item label="设备号:">
            <el-input v-model="form.devsn" placeholder="请输入设备号(24位)"></el-input>
          </el-form-item>
          <el-form-item label="公司名称:">
            <el-input v-model="form.company" type="password" placeholder="请输入公司名称"></el-input>
          </el-form-item>
          <el-form-item label="型号:">
            <el-select v-model="form.version" placeholder="请选择" style="width: 100%;">
              <el-option label="一代" :value="1"></el-option>
              <el-option label="二代" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="form-group">
              <el-button type="primary" @click="addBut">确定录入</el-button>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addDev} from "@/api/user";

export default {
  name: "add",
  components: {},
  props: {
    id: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      form: {
        devsn: '',
        company: '',
        version: 1,
      }
    }
  },
  watch: {},
  mounted() {
  },
  methods: {
    addBut() {
      var that = this
      if (!this.form.devsn) {
        this.$message.error('请输入设备序列号');
        return
      }
      if (!this.form.company) {
        this.$message.error('请输入公司名称');
        return
      }
      addDev(this.form).then((res) => {
            that.$message({
              message: res.msg,
              type: 'success'
            })
            that.form = {
              devsn: '',
              company: '',
              version: 1,
            }
            that.$emit('getdata', true)
            that.dialogVisible = false
          }
      )
    }
  }
}
</script>

<style lang="scss" scoped>

</style>

喜欢