detail.vue
6.34 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<template>
<div class="editPage">
<el-form
:model="editForm"
:loading="loading"
ref="editForm"
label-position="right"
label-width="auto"
style="padding-right: 30px"
v-loading="loading"
element-loading-text="操作中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.9)"
>
<el-form-item
label="所属分类"
prop="classifyCode"
:rules="{ required: true, message: '所属分类不能为空', trigger: 'change' }"
>
<el-select class="maxItem" v-model="editForm.classifyCode" placeholder="请选择所属分类">
<el-option
v-for="item in classifyList"
:key="item.classifyCode"
:label="item.classifyName"
:value="item.classifyCode"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="标题"
prop="articleTitle"
:rules="{ required: true, message: '标题不能为空', trigger: 'blur' }"
>
<el-input v-model="editForm.articleTitle" placeholder="请输入标题"></el-input>
</el-form-item>
<el-form-item
label="内容"
prop="content"
:rules="{ required: true, message: '内容不能为空', trigger: 'blur' }"
>
<WangEditor v-model="editForm.content" :subPath="subPath" />
</el-form-item>
<el-form-item label="附件">
<el-upload
class="upload-demo"
:onSuccess="successFile"
:onRemove="removeFile"
:file-list="editForm.attachments"
drag
action="https://api.k.wxpai.cn/bizproxy/tianbaoServiceApi/common/upload"
multiple
:data="extraData"
accept="application/pdf"
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">
将文件拖到此处,或
<em>点击上传</em>
</div>
<div class="el-upload__tip" slot="tip">*只能上传pdf文件</div>
</el-upload>
</el-form-item>
<el-form-item label="排序值">
<el-input-number v-model="editForm.orderId" :min="0"></el-input-number>
</el-form-item>
<el-form-item label="是否在线" prop="onlineStatus">
<el-switch
v-model="editForm.onlineStatus"
inactive-color="rgb(234,236,240)"
></el-switch>
</el-form-item>
<el-form-item label="是否置顶" prop="inTop">
<el-switch
v-model="editForm.inTop"
inactive-color="rgb(234,236,240)"
></el-switch>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer" style="padding-right:30px">
<el-button @click="componentClose">取 消</el-button>
<el-button type="primary" @click="componentSubmit" :disabled="loading" :loading="loading">确定</el-button>
</div>
</div>
</template>
<script>
import UploadImg from "@/components/UploadImg/index.vue";
import WangEditor from "@/components/WangEditor/index.vue";
export default {
props: [],
components: {
UploadImg,
WangEditor
},
data() {
return {
loading: false,
subPath: "article",
editForm: {
articleCode: null,
classifyCode: null,
articleTitle: null,
articleThumb: 0,
author: null,
content: "",
createTime: 0,
orderId: 0,
onlineStatus: true,
inTop: false,
attachments: []
},
classifyList: [],
extraData: {
subPath: "articleFile"
}
};
},
mounted() {
this.initData();
},
methods: {
async initData() {
this.editForm.articleCode = this.$route.query.articleCode;
if (this.editForm.articleCode != null) {
this.getDetail();
}
this.getClassifyList();
},
getDetail() {
app
.get({
url: app.api.getArticleDetail,
data: {
articleCode: this.editForm.articleCode
}
})
.then(res => {
res.inTop = res.inTop == 1 ? true : false;
res.onlineStatus = res.onlineStatus == 1 ? true : false;
if (res.attachments) {
res.attachments = JSON.parse(res.attachments);
} else {
res.attachments = [];
}
this.editForm = res;
});
},
getClassifyList() {
app
.get({ url: app.api.getArticleClassify, data: null })
.then(res => {
this.classifyList = res.list;
})
.catch(e => {});
},
componentSubmit() {
this.$refs["editForm"].validate(valid => {
if (valid) {
if (this.loading) {
return;
}
this.loading = true;
let editForm = JSON.parse(JSON.stringify(this.editForm));
editForm.inTop = this.editForm.inTop ? 1 : 0;
editForm.onlineStatus = this.editForm.onlineStatus ? 1 : 0;
editForm.createTime = new Date(this.editForm.createTime).getTime();
if (this.editForm.attachments.length > 0) {
editForm.attachments = JSON.stringify(this.editForm.attachments);
} else {
editForm.attachments = "";
}
console.log("this.editForm", editForm);
app
.post({ url: app.api.setArticle, data: editForm })
.then(res => {
this.loading = false;
this.$notify({
title: "成功",
message: "操作成功",
type: "success"
});
this.$router.go(-1);
})
.catch(e => {
this.loading = false;
});
}
});
},
componentClose() {
this.$router.go(-1);
},
successFile(res, file) {
if (res.code == 200) {
this.editForm.attachments.push({
name: file.name,
path: res.content
});
} else {
this.$notify.error({
title: "错误",
message: res.errMsg
});
}
},
removeFile(file, fileList) {
this.editForm.attachments.forEach((item, index) => {
if (item.name == file.name) {
this.attachments.attachments.splice(index, 1);
}
});
}
}
};
</script>
<style lang="scss" scoped>
.tablePage {
margin: 0 auto;
}
.el-upload__tip {
color: rgb(190, 190, 190);
}
</style>