index.vue
2.96 KB
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
<template>
<div>
<a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-form-model-item label="文档分类标题" prop="title">
<a-input v-model="form.title" />
</a-form-model-item>
<a-form-model-item label="文档分类描述" prop="description">
<a-input v-model="form.description" type="textarea" />
</a-form-model-item>
<a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="onSubmit">{{ isNewAdd ? '创建' : '提交' }}</a-button>
<a-button style="margin-left: 10px" @click="resetForm">重置</a-button>
<a-button style="margin-left: 10px" @click="closeForm">关闭</a-button>
</a-form-model-item>
</a-form-model>
</div>
</template>
<script type="text/ecmascript-6">
export default {
name: '',
data() {
return {
isNewAdd: true,
labelCol: { span: 4 },
wrapperCol: { span: 14 },
form: {
docTitle: '',
docUrl: '',
docDescription: ''
},
rules: {
title: [
{ required: true, message: '请输入文档分类名称', trigger: 'blur' },
{ min: 1, max: 30, message: '请输入字符1~50之间', trigger: 'blur' }
],
description: [{ required: true, message: '请输入文档分类描述', trigger: 'blur' }]
}
}
},
mounted() {
this.editeItemFn()
},
methods: {
onSubmit() {
this.$refs.ruleForm.validate(valid => {
if (valid) {
if (this.isNewAdd) {
//新增
this.api.documentClassify.create(this.form).then(res => {
// console.log(res);
if (res.id) {
this.$message.success('添加成功')
this.closeForm()
this.resetForm()
} else {
this.$message.error('添加失败')
}
})
} else {
//编辑
this.api.documentClassify.update(this.form).then(res => {
console.log(res)
if (res.id) {
this.$message.success('编辑成功')
this.closeForm()
this.resetForm()
} else {
this.$message.error('编辑失败')
}
})
}
} else {
return false
}
})
},
resetForm() {
this.isNewAdd = true
this.$refs.ruleForm.resetFields()
},
closeForm() {
this.to(-1)
},
//编辑项目
editeItemFn() {
const editeItem = this.$route.query
console.log('editeItem: ', editeItem)
if (Object.keys(editeItem).length === 0) return
this.isNewAdd = false
this.form = {
title: editeItem.title,
description: editeItem.description,
id: editeItem.id
}
}
},
// 重置
beforeDestroy() {
this.resetForm()
}
}
</script>
<style scoped lang="scss"></style>