yangys
2024-02-18 7ec1f23e861d34826ef6a31c065679bd011119b4
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
    <div class="add-devicetype">
        <el-dialog top="94px" :close-on-click-modal="false" width="400px" @close="cancel" :visible.sync="addVisible">
            <!-- 添加内容-->
            <el-form :model="dataForm" label-width="100px" ref="dataForm">
                <el-row :gutter="24">
 
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-form-item label="名称" prop="name">
                            <el-input v-model="dataForm.name" placeholder="名称" maxlength="80" clearable></el-input>
                        </el-form-item>
                    </el-col>
 
                </el-row>
 
            </el-form>
            <!-- 按钮 -->
            <span slot="footer" class="dialog-footer">
                <!-- <el-button type="ghost" size="mini" style="width: 150px" @click="cancel">取消</el-button> -->
                <el-button class="active" size="mini" type="primary" @click="dataFormSubmit()">保存</el-button>
            </span>
        </el-dialog>
    </div>
</template>
 
<script>
import { deviceTypeUpdate, deviceTypeCreate } from '@/api/Api'
export default {
    props: ['addVisible', 'row'],
    data() {
        return {
            visible: false,
            dataForm: {
                id: 0, // title显示新增还是修改
                name: ''
            }
 
        }
    },
    watch: {
        addVisible: {
            handler(val) {
                if (val) {
                    this.init()
                }
            },
            immediate: true
        }
    },
    created() {
        //console.log('add create');
        this.init(this.row)
    },
    methods: {
        init(row) {
            if (this.$refs['dataForm']) {
                this.$refs['dataForm'].resetFields()
            }
            if (row !== undefined) {
                this.dataForm.id = row.id
                this.dataForm.name = row.name
 
            } else {
                this.dataForm.id = ''
            }
        },
        /* 查询使用部门*/
        cancel() {
            this.$emit('close')
        },
        /* 提交*/
        dataFormSubmit() {
            if (this.dataForm.id === '') { // 新增
                deviceTypeCreate(this.dataForm).then(res => {
                    this.$message({
                        message: '新增成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                            this.$emit('confirm')
                            this.visible = false
                        }
                    })
                })
            } else {
                deviceTypeUpdate(this.dataForm).then(res => {
                    this.$message({
                        message: '修改成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                            this.$emit('confirm')
                            this.visible = false
                        }
                    })
                })
            }
        }
    }
}
</script>
 
<style lang="scss">
#app .add-devicetype .el-dialog {
    height: 300px;
}
.el-form-item__content {
 
    .el-select,
    .el-input {
        width: 100%;
    }
}
 
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
 
.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}
 
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}
 
.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>