<template>
|
<el-dialog
|
:title="title"
|
:visible.sync="dialogVisible"
|
width="70%"
|
:before-close="handleClose"
|
custom-class="add-group-dialog"
|
>
|
<el-form
|
ref="form"
|
:model="form"
|
:rules="rules"
|
label-width="80px"
|
label-position="top"
|
>
|
<el-form-item label="组别名称" prop="groupName">
|
<el-input
|
v-model="form.groupName"
|
placeholder="请输入"
|
class="custom-input"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="备注" prop="remark">
|
<el-input
|
type="textarea"
|
v-model="form.remark"
|
placeholder="请输入"
|
:rows="4"
|
class="custom-textarea"
|
></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="handleClose" class="cancel-btn">取消</el-button>
|
<el-button type="primary" @click="handleSubmit" class="submit-btn"
|
>保存</el-button
|
>
|
</div>
|
</el-dialog>
|
</template>
|
|
<script>
|
export default {
|
name: "AddGroupDialog",
|
data() {
|
return {
|
dialogVisible: false,
|
title: "添加组别",
|
form: {
|
groupName: "",
|
remark: "",
|
id: null
|
},
|
rules: {
|
groupName: [
|
{ required: true, message: "请输入组别名称", trigger: "blur" },
|
],
|
},
|
isEdit: false,
|
};
|
},
|
computed: {
|
dialogWidth() {
|
return window.innerWidth < 768 ? "90%" : "500px";
|
},
|
labelPosition() {
|
return window.innerWidth < 768 ? "top" : "right";
|
},
|
},
|
methods: {
|
open(row) {
|
this.dialogVisible = true;
|
this.isEdit = !!row;
|
|
if (row) {
|
this.title = "编辑组别";
|
this.form = JSON.parse(JSON.stringify({
|
groupName: row.groupName || '',
|
remark: row.remark || '',
|
id: row.id
|
}));
|
} else {
|
this.title = "添加组别";
|
this.resetForm();
|
}
|
},
|
handleClose() {
|
this.dialogVisible = false;
|
this.resetForm();
|
},
|
resetForm() {
|
this.form = {
|
groupName: "",
|
remark: "",
|
id: null
|
};
|
this.$nextTick(() => {
|
this.$refs.form && this.$refs.form.resetFields();
|
});
|
},
|
handleSubmit() {
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
const eventName = this.isEdit ? "update" : "submit";
|
this.$emit(eventName, {...this.form});
|
this.handleClose();
|
}
|
});
|
},
|
},
|
};
|
</script>
|
|
<style lang="less" scoped>
|
.add-group-dialog {
|
::v-deep .el-dialog__header {
|
padding: 20px;
|
border-bottom: 1px solid #eee;
|
|
.el-dialog__title {
|
font-size: 16px;
|
font-weight: 500;
|
color: #333;
|
}
|
|
.el-dialog__headerbtn {
|
top: 20px;
|
}
|
}
|
|
.el-form {
|
padding-left: 54px;
|
padding-right: 54px;
|
.el-form-item {
|
margin-bottom: 20px;
|
|
::v-deep .el-form-item__label {
|
font-size: 14px;
|
color: #333;
|
}
|
|
.custom-input,
|
.custom-textarea {
|
::v-deep .el-input__inner,
|
::v-deep .el-textarea__inner {
|
border-radius: 4px;
|
border-color: #dcdfe6;
|
|
&:focus {
|
border-color: #409eff;
|
}
|
|
&::placeholder {
|
color: #999;
|
}
|
}
|
}
|
}
|
}
|
|
.dialog-footer {
|
padding: 20px;
|
border-top: 1px solid #eee;
|
|
.cancel-btn {
|
margin-right: 12px;
|
}
|
|
.submit-btn {
|
min-width: 80px;
|
}
|
}
|
}
|
::v-deep .el-dialog__body {
|
padding: 15px 24px 0px 14px !important;
|
}
|
::v-deep .el-dialog__footer {
|
text-align: center !important;
|
button {
|
width: 150px;
|
}
|
}
|
|
@media screen and (max-width: 768px) {
|
.add-group-dialog {
|
::v-deep .el-dialog__body {
|
padding: 20px 15px;
|
}
|
|
.el-form {
|
.el-form-item {
|
margin-bottom: 15px;
|
}
|
}
|
|
.dialog-footer {
|
padding: 15px;
|
|
.el-button {
|
width: 100%;
|
margin: 5px 0;
|
}
|
}
|
}
|
}
|
</style>
|