quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
  <!--
        作者:4948286@qq.com
        时间:2019-11-36
        描述:添加图片类型
    -->
  <el-dialog
    title="添加分类"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose" :append-to-body="true">
    <el-form size="small" :model="form" ref="form" label-width="100px" class="demo-ruleForm">
      <el-form-item
        label="分类名称"
        prop="categoryname"
        :rules="[
          { required: true, message: '名字不能为空'}
        ]"
      >
        <el-input type="age" v-model="form.categoryname" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="handleClose">取消</el-button>
        <el-button size="small" type="primary" @click="submitForm('form')">提交</el-button>
      </el-form-item>
    </el-form>
 
  </el-dialog>
</template>
 
<script>
import FileApi from '@/api/file.js';
export default {
  data(){
    return {
      /*是否显示*/
      dialogVisible:true,
      /*from表单模型*/
      form:{
        categoryname:''
      },
      /*分类名称*/
      categoryName:''
    }
  },
  props:['category','file_type'],
  created() {
    console.log(this.category);
    if(this.category!=null){
      this.form.categoryname=this.category.group_name;
      this.form.group_id=this.category.group_id
    }
  },
  methods:{
 
    /*添加图片类别*/
    addCategory: function(categoryname) {
      let self = this;
      FileApi.addCategory({
          group_name: categoryname,
          group_type: self.file_type
        },).then(data => {
          self.$message({
            message: '添加成功',
            type: 'success'
          });
          self.handleClose({status:'success'});
        })
        .catch(error => {
          self.$message.error('添加失败');
        });
    },
 
    /*修改图片类别*/
    editCategory: function(model) {
      let self = this;
      let param={
        group_name: model.categoryname,
        group_id:model.group_id
      };
      FileApi.editCategory(param,).then(data => {
          self.$message({
            message: '修改成功',
            type: 'success'
          });
          self.handleClose({status:'success'});
        })
        .catch(error => {
          self.$message.error('修改失败');
        });
    },
 
    /*提交*/
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(this.category&&this.category.group_id!=null){
            this.editCategory(this.form);
          }else{
            this.addCategory(this.form.categoryname);
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
 
 
    /*关闭弹窗*/
    handleClose(param){
      this.dialogVisible=false;
      this.$emit('closeCategory',param);
    }
  }
 
}
 
</script>
 
<style>
</style>