cellsysArt/components/tag/tagCreateEdit.vue

137 lines
4.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<el-dialog
:title="dialog.mode === 'create' ? '创建标签' : '编辑标签'"
v-model="dialog.visible"
append-to-body
:close-on-click-modal="false"
:close-on-press-escape="false"
@open="open">
<el-form
ref="tagForm"
label-width="120px"
:model="tagForm"
:rules="rules">
<el-form-item
label="标签名称"
prop="name">
<el-input
v-model="tagForm.name"
placeholder="标签名称不能超过5个字"></el-input>
</el-form-item>
<el-form-item
label="描述"
prop="description">
<el-input
:rows="2"
type="textarea"
v-model="tagForm.description" />
</el-form-item>
</el-form>
<div></div>
<template #footer>
<el-button @click="closeTagCreateDiaglog"> </el-button>
<el-button
:loading="dialog.btnLoading"
type="primary"
@click="dialog.mode === 'create' ? confirmCreate() : confirmUpate()">
</el-button>
</template>
</el-dialog>
</template>
<script>
export default {
name: 'tagCreate',
props: {
dialog: Object,
// tagForm: {
// type: Object,
// default: function () {
// return {};
// },
// },
},
inject: ['cellsysOrg'],
data() {
return {
tagForm: {
name: null,
description: null,
},
//dialog: {
// mode: "create",
// visible: false,
// btnLoading: false
//},
rules: {
name: [
{ required: true, message: '请输入标签名称', trigger: 'blur' },
{ min: 1, max: 5, message: '长度在 1 到 5 个字符', trigger: 'blur' },
],
},
};
},
created() {},
methods: {
open() {
//this.tagForm["name"] = null;
//this.tagForm["description"] = null;
},
confirmCreate() {
let { id, name, description } = this.tagForm;
this.$refs['tagForm'].validate((valid) => {
if (valid) {
this.dialog.btnLoading = true;
this.cellsysOrg
.createTag({
name: name,
description: description,
})
.then((res) => {
this.$message.success('创建标签成功!');
this.closeTagCreateDiaglog();
})
.catch((error) => {
console.error(error);
this.$message.error(error.message);
})
.finally(() => {
this.$nextTick(() => {
this.dialog.btnLoading = false;
});
});
}
});
},
confirmUpate() {
this.$refs['tagForm'].validate((valid) => {
if (valid) {
this.dialog.btnLoading = true;
this.cellsysOrg
.updateTag(this.tagForm)
.then((res) => {
this.$message.success('更新标签成功!');
this.closeTagCreateDiaglog();
})
.catch((error) => {
console.error(error);
this.$message.error(error.message);
})
.finally(() => {
this.$nextTick(() => {
this.dialog.btnLoading = false;
});
});
}
});
},
closeTagCreateDiaglog() {
this.dialog.visible = false;
this.$refs.tagForm.resetFields();
this.$emit('closeTagCreateDiaglog');
},
},
};
</script>
<style scoped></style>