quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
  <!--
        作者:luoyiming
        时间:2019-10-25
        描述:插件-类别
    -->
  <el-dialog title="添加类别" :visible.sync="dialogVisible" @close="dialogFormVisible" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form size="small" :model="form" ref="form">
      <el-form-item label="类别名称" :label-width="formLabelWidth"><el-input v-model="form.plus_name" autocomplete="off" placeholder="请输入类别名称"></el-input></el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="addClick()" :loading="loading">确 定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import PlugsApi from '@/api/plugs.js';
export default {
  data() {
    return {
      /*表单数据对象*/
      form: {
        plus_name: ''
      },
      /*左边长度*/
      formLabelWidth: '120px',
      /*是否显示*/
      dialogVisible: false,
      loading: false
    };
  },
  props: ['open_type'],
  created() {
    this.dialogVisible = this.open_type;
  },
  methods: {
    /*添加插件*/
    addClick() {
      let self = this;
      let params = this.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          PlugsApi.addplugs(params, true)
            .then(res => {
              self.loading = false;
              if (res.code == 1) {
                self.$message({
                  message: '恭喜你,添加成功',
                  type: 'success'
                });
                self.dialogFormVisible(true);
              } else {
                self.loading = false;
                self.$message.error('错了哦,这是一条错误消息');
              }
            })
            .catch(error => {
              self.loading = false;
            });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit('closeDialog', {
          type: 'success',
          openDialog: false
        });
      } else {
        this.$emit('closeDialog', {
          type: 'error',
          openDialog: false
        });
      }
    }
  }
};
</script>
 
<style></style>