liveSaveDialog.vue
2.37 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
<template>
<div>
<el-dialog
:title="title"
:visible.sync="dialogVisible"
:before-close="handleCloseDialog">
<el-form :model="liveForm" ref="liveForm" :rules="liveRules" label-width="130px">
<el-form-item label="时间:" prop="liveTime">
<el-date-picker
v-model="liveForm.liveTime"
type="datetime"
value-format="timestamp"
placeholder="选择日期时间">
</el-date-picker>
</el-form-item>
<el-form-item label="内容:" prop="liveContent">
<el-input type="textarea" v-model="liveForm.liveContent" maxlength="500" show-word-limit></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm('liveForm')">提交</el-button>
<el-button @click="handleCloseDialog">取消</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import { request } from '@/api/fetch-api'
let urls = {
liveSaveUrl: '/tianbao_edu_api/admin/live/save',
}
export default {
props: ['dialogVisible', 'title', 'liveTemp'],
data() {
return {
title: '',
liveForm:{},
liveRules:{
liveTime: [
{required: true, message: '请选择时间', trigger: 'blur'}
],
liveContent: [
{required: true, message: '请输入内容', trigger: 'blur'}
],
}
}
},
methods: {
handleCloseDialog() {
this.$emit('closedialog', false)
},
init(){
if (JSON.parse(JSON.stringify(this.liveTemp)) == null) {
this.title='创建'
} else {
this.title="修改"
this.liveForm = JSON.parse(JSON.stringify(this.liveTemp))
}
},
submitForm(formName){
this.$refs[formName].validate((valid) => {
if (valid) {
request.post(urls.liveSaveUrl, this.liveForm).then(response => {
this.$emit('initLive')
this.$emit('closedialog', false)
this.$message.success("保存成功")
}).catch(() => {
})
} else {
console.log('error submit!!')
return false
}
})
}
},
created() {
this.init()
}
}
</script>
<style scoped>
</style>