StoryRelease.vue
5.89 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
<template>
<div id="growUpRelease" >
<input class="title" type="text" v-model="title" placeholder="标题">
<textarea class="content" cols="30" rows="10" v-model="content" placeholder="分享你的游记…"></textarea>
<div class="upload_box">
<van-uploader v-model="fileList" multiple :after-read="afterRead" />
</div>
<van-cell title="选择出行学生" is-link :value="selectedTrip.travelerName" @click="showTripPicker = true" />
<div class="release_btn_box">
<van-button class="release_btn" round color="#3074FF" type="primary" :disabled="content == ''" @click="handleRelease"
>发布</van-button
>
</div>
<van-popup v-model="showTripPicker" round position="bottom">
<van-picker :columns="tripArr" value-key="travelerName" show-toolbar @cancel="showTripPicker = false" @confirm="onTripConfirm" />
</van-popup>
</div>
</template>
<script>
import Axios from 'axios'
export default {
data() {
return {
userInfo: '',
title: '', //发布的标题
content: '', //发布的内容
tripArr: [], //出行人列表
selectedTrip: '', //选中的出行人
showTripPicker: false,
fileList: [
// { url: 'https://img01.yzcdn.cn/vant/leaf.jpg' },
// // Uploader 根据文件后缀来判断是否为图片文件
// // 如果图片 URL 中不包含类型信息,可以添加 isImage 标记来声明
// { url: 'https://cloud-image', isImage: true },
],
}
},
mounted() {
let userInfo = localStorage.getItem('userInfo')
if (userInfo) {
this.userInfo = JSON.parse(userInfo)
this.tripArr = this.userInfo.subUsers
}
},
methods: {
// 读取到文件后
afterRead(file) {
if (Array.isArray(file)) {
this.fileUpload(file, 0)
} else {
this.fileUpload([file], 0)
}
},
fileUpload(files, index) {
for (let i = index; i < files.length; i++) {
files[i].status = 'uploading'
files[i].message = '上传中...'
}
let params = new FormData()
params.append('file', files[index].file, files[index].file.name)
let config = {
headers: {
//添加请求头
'Content-Type': 'multipart/form-data',
},
}
Axios.post('https://proxy.shunzhi.net/prod/api/file/fileUpload', params, config).then((res) => {
if (res?.status == 200 && res.data.code == 200) {
files[index].status = 'succeed'
files[index].url = res.data.message
files[index].message = '上传成功'
} else {
files[index].status = 'failed'
files[index].message = '上传失败'
}
if (index + 1 < files.length) {
this.fileUpload(files, index + 1)
}
})
},
// 点击选择出行人
handleTrip() {
if (this.tripArr.length > 0) {
this.showTripPicker = true
} else {
this.$toast('暂无可选出行学生')
}
},
// 选中出行人
onTripConfirm(item) {
this.showTripPicker = false
this.selectedTrip = item
},
// 发布
handleRelease() {
if (!this.selectedTrip) {
this.$toast('请选择出行人')
return
}
// 计算图片
let photos = []
for (let i in this.fileList) {
if (this.fileList[i].url) {
photos.push({
imgUrl: this.fileList[i].url,
})
}
}
if (photos.length==0) {
this.$toast('请至少上传一张照片')
return
}
this.$toast.loading({
message: '正在发布...',
duration: 0,
forbidClick: true,
})
this.yxAxios
.post(`${this.yanxueUrl}/api/StudiesWap/AddStory`, {
userNum: this.userInfo.centerNo, //中台编号
travelerNum:this.selectedTrip.travelerNum,
title: this.title, //标题
content: this.content, //发布内容
imgList: photos,
state: 1,
})
.then((res) => {
this.$toast.clear()
console.log('发布:', res.data)
this.$toast.clear()
if (res.data.status == 1) {
this.$router.back()
} else {
this.$toast(res.data.message)
}
})
},
},
}
</script>
<style lang="scss">
#growUpRelease {
min-height: 100%;
box-sizing: border-box;
padding-bottom: 300px;
.selected_tag_box {
padding: 24px;
padding-bottom: 0;
font-size: 26px;
color: #5f94ff;
height: 0;
transition: 0.3s ease;
&.open {
height: 40px;
}
}
.title{
font-size: 32px;
width: 100%;
padding: 0 24px;
margin: 20px 0;
margin-top: 50px;
box-sizing: border-box;
border: none;
background: transparent;
}
.content {
font-size: 32px;
width: 100%;
height: 280px;
padding: 0 24px;
margin: 20px 0;
box-sizing: border-box;
border: none;
background: transparent;
}
.upload_box {
padding: 24px;
.van-uploader__preview {
margin: 0 27px 27px 0;
&:nth-of-type(3n) {
margin-right: 0;
}
}
.van-uploader__preview-image {
width: 216px;
height: 216px;
}
.van-uploader__upload {
width: 216px;
height: 216px;
margin: 0 0 27px 0;
}
}
.tag_box {
padding: 24px;
.tag_item {
display: inline-block;
color: #999;
padding: 0 26px;
line-height: 55px;
border-radius: 33px;
font-size: 26px;
margin-right: 12px;
margin-bottom: 20px;
&.active {
background: #5f94ff;
color: #fff;
}
}
}
.van-cell {
font-size: 30px;
}
.release_btn_box {
width: 100%;
height: 260px;
background: #fff;
position: fixed;
bottom: 0;
left: 0;
.release_btn {
width: 662px;
position: absolute;
bottom: 100px;
left: 44px;
font-size: 32px;
}
}
}
</style>