feedback.vue
8.75 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<template>
<view class="feedback-page">
<view style="overflow-y: scroll;overflow: hidden;height: 1500rpx;">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<view class="form-page">
<u--form labelPosition="left" :model="feedbackData" :rules="rules" ref="myfeedBackFormRef">
<u-form-item required label="主题" prop="feedbackInfo.title" borderBottom ref="item1">
<u--input placeholder="请输入主题" v-model="feedbackData.feedbackInfo.title" border="none"></u--input>
</u-form-item>
<u-form-item required label="姓名" prop="feedbackInfo.name" borderBottom ref="item1">
<u--input placeholder="请输入姓名" v-model="feedbackData.feedbackInfo.name" border="none"></u--input>
</u-form-item>
<u-form-item label="手机" prop="feedbackInfo.phone" borderBottom ref="item1">
<u--input placeholder="请输入手机" v-model="feedbackData.feedbackInfo.phone" border="none"></u--input>
</u-form-item>
<u-form-item label="QQ" prop="feedbackInfo.qq" borderBottom ref="item1">
<u--input placeholder="请输入QQ" v-model="feedbackData.feedbackInfo.qq" border="none"></u--input>
</u-form-item>
<u-form-item label="邮箱" prop="feedbackInfo.email" borderBottom ref="item1">
<u--input placeholder="请输入邮箱" v-model="feedbackData.feedbackInfo.email" border="none"></u--input>
</u-form-item>
<view class="info">
<view class="info-contain">
<u-form-item label="反馈" prop="feedbackInfo.message" borderBottom ref="item1">
<u--textarea placeholder="请输入反馈信息" v-model="feedbackData.feedbackInfo.message" count></u--textarea>
</u-form-item>
</view>
</view>
<view class="feed-back-text" style="margin: 15px 0px 0px -16rpx;">上传图片(最多6张)</view>
<view class="info" style="margin-top: 15rpx;background: rgba(1, 1, 1, 0);">
<view class="info-contain">
<u-form-item label="图片" prop="feedbackInfo.images" borderBottom ref="item1">
<u-upload :sizeType="compressed" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="6"></u-upload>
</u-form-item>
</view>
</view>
</u--form>
<view style="width:427rpx;margin:0 auto;">
<u-button class="buttonSty button-sty" shape="circle" type="primary" text="提交" customStyle="margin-top: 129rpx" @click="submit"></u-button>
</view>
</view>
<!-- #ifdef MP -->
<view style="height: 18rpx;"></view>
<!-- #endif -->
<!-- #ifndef MP -->
<view style="height: 52rpx;"></view>
<!-- #endif -->
</view>
<view style="height: 20rpx;"></view>
<f-tabbar></f-tabbar>
</view>
</view>
</template>
<script>
import fTabbar from '@/components/module/f-tabbar/f-tabbar';
import baseUrl from '@/config/baseUrl.js';
import { mapState } from 'vuex';
export default {
components: {
fTabbar
},
data() {
return {
feedbackData: {
feedbackInfo: {
title: '',
name: '',
phone: '',
qq: '',
email: '',
images: [],
message: ''
}
},
fileList1: [],
rules: {
'feedbackInfo.title': [
{
type: 'string',
required: true,
message: '请填写主题',
trigger: ['blur', 'change']
},
{
validator: (rule, value, callback) => {
return uni.$u.test.chinese(value);
},
message: '主题必须为中文',
trigger: ['change', 'blur']
}
],
'feedbackInfo.name': [
{
type: 'string',
required: true,
message: '请填写姓名',
trigger: ['blur', 'change']
},
{
validator: (rule, value, callback) => {
return uni.$u.test.chinese(value);
},
message: '姓名必须为中文',
trigger: ['change', 'blur']
}
],
'feedbackInfo.phone': [
{
type: 'number',
required: true,
message: '请填写手机号码',
trigger: ['blur', 'change']
},
{
validator: (rule, value, callback) => {
return uni.$u.test.mobile(value);
},
message: '手机号码不正确',
trigger: ['change', 'blur']
}
],
'feedbackInfo.email': [
{
type: 'string',
required: true,
message: '请填写邮箱',
trigger: ['blur', 'change']
},
{
validator: (rule, value, callback) => {
return uni.$u.test.email(value);
},
message: '邮箱不正确',
trigger: ['change', 'blur']
}
],
'feedbackInfo.message': [
{
type: 'string',
required: true,
message: '请填写意见反馈',
trigger: ['blur', 'change']
},
{
validator: (rule, value, callback) => {
return uni.$u.test.chinese(value);
},
message: '意见反馈必须为中文',
trigger: ['change', 'blur']
}
]
}
};
},
onReady() {
// 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
this.$refs.myfeedBackFormRef.setRules(this.rules);
},
onLoad() {
// 隐藏原生的tabbar
uni.hideTabBar();
},
computed: {
...mapState(['userInfo'])
},
methods: {
// 删除图片
deletePic(event) {
this[`fileList${event.name}`].splice(event.index, 1);
},
// 新增图片
async afterRead(event) {
let lists = [].concat(event.file);
let fileListLen = this[`fileList${event.name}`].length;
lists.map(item => {
this[`fileList${event.name}`].push({
...item,
status: 'uploading',
message: '上传中'
});
});
for (let i = 0; i < lists.length; i++) {
const result = await this.uploadFilePromise(lists[i].url);
let item = this[`fileList${event.name}`][fileListLen];
this[`fileList${event.name}`].splice(
fileListLen,
1,
Object.assign(item, {
status: 'success',
message: '',
url: result
})
);
fileListLen++;
}
},
uploadFilePromise(url) {
let token;
token = this.userInfo.isToken || uni.getStorageSync('userInfo').isToken || undefined;
// #ifdef H5
token = window.sessionStorage.getItem('userInfo').isToken;
// #endif
if (!token) return uni.$u.toast('请登录后上传图片');
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: `${baseUrl.baseUrl}/yt/oss/upload`,
filePath: url,
name: 'file',
header: {
'content-type': 'multipart/form-data',
Authorization: 'Bearer ' + token
},
formData: {},
success: res => {
setTimeout(() => {
if (res) {
let objImage = JSON.parse(res.data);
if (this.feedbackData.feedbackInfo.images.length < 6) {
this.feedbackData.feedbackInfo.images.push(objImage.fileStaticUri);
}
resolve(res.data?.fileStaticUri);
}
}, 1000);
}
});
});
},
submit() {
this.$refs.myfeedBackFormRef
.validate()
.then(res => {
let contactInfo = {
qq: this.feedbackData.feedbackInfo?.qq,
email: this.feedbackData.feedbackInfo?.email,
phone: this.feedbackData.feedbackInfo?.phone
};
let httpData = {
title: this.feedbackData.feedbackInfo.title,
name: this.feedbackData.feedbackInfo.name,
contact: JSON.stringify(contactInfo),
images: this.feedbackData.feedbackInfo.images.length == 0 ? '' : JSON.stringify(this.feedbackData.feedbackInfo.images),
message: this.feedbackData.feedbackInfo.message
};
uni.$u.http
.post('/yt/opinion', httpData)
.then(res => {
if (res) {
uni.showToast({
title: '意见反馈提交成功~',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack();
}, 500);
}
})
.catch(e => {
uni.$u.toast(e.data?.message);
});
})
.catch(errors => {
uni.$u.toast('校验失败');
});
}
}
};
</script>
<style lang="scss" scoped>
.feedback-page {
min-height: 100vh;
background-color: #f8f9fa;
padding-top: 9rpx;
padding-left: 27rpx;
overflow-y: scroll;
overflow: hidden;
}
.form-page {
width: 700rpx;
background-color: #ffffff;
border-radius: 10px;
margin-top: 20rpx;
padding-left: 15rpx;
padding: 0 20rpx;
height: 500rpx;
.info {
width: 700rpx;
background-color: #ffffff;
border-radius: 10px;
margin-top: 80rpx;
height: 256rpx;
margin-left: -20rpx;
.info-contain {
margin: 0rpx 27rpx;
/deep/ .u-line {
display: none !important;
}
/deep/ .u-form-item__body__left__content__label {
display: none !important;
}
/deep/.u-form-item__body__right {
margin-left: -106rpx;
}
/deep/.u-textarea--radius {
border: none !important;
}
}
}
/deep/.u-button--primary{
background-color: #377DFF!important;
border-color: #377DFF!important;
}
}
//#ifndef MP
.buttonSty {
margin-top: 30rpx !important;
}
//#endif
</style>