addDialog.vue
3.3 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!--
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-07-19 16:04:43
-->
<template>
<dialogBox title="新增法律法规" @submitForm="submitForm" saveButton="保存" :isFullscreen="false" width="50%"
@closeDialog="closeDialog" v-model="value">
<el-form ref="ruleForm" :model="ruleForm" label-width="100px" :rules="rules">
<el-row>
<el-col :span="12">
<el-form-item label="标题:" prop="noticeTitle">
<el-input v-model="ruleForm.noticeTitle"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="附件:" prop="noticeFileUrl">
<el-upload action="" :file-list="fileList" multiple :auto-upload="false" :limit="1"
:on-change="handleChange" :before-upload="beforeUpload">
<el-button icon="el-icon-upload" type="primary">上传</el-button>
<div slot="tip" class="el-upload__tip">支持上传doc、docx、xls、xlsx、pdf文件,大小不超过20MB</div>
</el-upload>
</el-form-item>
</el-col>
</el-row>
</el-form>
</dialogBox>
</template>
<script>
import { addSysNotice } from "@/api/sysNotice.js"
import { upload } from "@/api/file.js"
export default {
props: {
value: { type: Boolean, default: false },
},
data () {
return {
ruleForm: {
noticeTitle: '',
noticeContent: '',
noticeFileUrl: '',
noticeType: '2'
},
rules: {
noticeTitle: [
{ required: true, message: '请输入法律法规标题', trigger: 'blur' }
]
},
}
},
methods: {
/**
* @description: submitForm
* @author: renchao
*/
submitForm () {
let that = this;
that.$refs.ruleForm.validate(valid => {
if (valid) {
addSysNotice(this.ruleForm).then(res => {
if (res.code == 200) {
this.$message.success('保存成功')
this.$emit("input", false);
this.resetRuleForm();
this.$parent.queryClick();
} else {
this.$message.error(res.message)
}
})
} else {
// console.log('error submit!!');
return false;
}
});
},
//关闭窗口
/**
* @description: 关闭窗口
* @author: renchao
*/
closeDialog () {
this.$emit("input", false);
this.resetRuleForm();
},
/**
* @description: resetRuleForm
* @author: renchao
*/
resetRuleForm () {
this.$refs['ruleForm'].resetFields();
this.ruleForm.noticeType = '2'
},
/**
* @description: beforeUpload
* @param {*} file
* @author: renchao
*/
beforeUpload (file) {
return true;
},
/**
* @description: handleChange
* @param {*} file
* @author: renchao
*/
async handleChange (file) {
var formdata = new FormData();
formdata.append("file", file.raw);
upload(formdata).then(res => {
this.ruleForm.noticeFileUrl = res.message
})
},
}
}
</script>
<style scoped lang="scss">
</style>