ad.vue
3.5 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
<template>
<view>
<p style=" color: #0d1013e6;
font-size: 28rpx;
font-weight: 500;margin: 24rpx;">请选择反馈类型</p>
<view class="flexBox" style="margin: 24rpx;" v-for="(item,index) in category">
<u-button :text="item.name" shape="circle" :type="active==index ? 'primary' : 'info'" style="margin-right: 12rpx;" @click="check(item,index)"></u-button>
</view>
<view style="margin: 24rpx;">
<u-textarea v-model="info.content" placeholder="请输入详细内容"></u-textarea>
</view>
<view style="margin: 24rpx;">
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic"
name="1" multiple :maxCount="1"></u-upload>
</view>
<!-- <view class="flexBox" style="justify-content: space-between; margin: 24rpx; background-color: white;padding: 30rpx 12rpx;">
<text>联系电话</text>
<input type="text" :value="phone" />
</view> -->
<view class="flexBox" style="width: 90%;justify-content: center;margin: 30rpx;">
<u-button text="提交" type="primary" shape="circle" @click="submit"></u-button>
</view>
</view>
</template>
<script>
import config from '@/common/config'
export default {
data() {
return {
action: config.baseUrl + '/api/common/upload',
category:[],
active:null,
fileList1:[],
info:{
feedtype_id:'',
content:'',
images:''
}
}
},
methods: {
check(item,index){
this.info.feedtype_id = item.id
this.active = index
},
submit(){
this.info.images = this.fileList
uni.$u.http.post('/api/user/feedback',this.info).then(res => {
uni.showToast({
title: res.msg,
icon:'none'
})
if(res.code == 1){
setTimeout(() => {
uni.reLaunch({
url:'/pages/index/my'
})
},1000)
}
}).catch(err => {
console.log(err);
uni.showToast({
title: err.msg
})
})
},
deletePic(event) {
this[`fileList${event.name}`].splice(event.index, 1)
},
// 新增图片
async afterRead(event) {
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
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) {
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: this.action, // 仅为示例,非真实的接口地址
filePath: url,
name: 'file',
formData: {
user: 'test'
},
header:{
token: uni.getStorageSync('token')
},
success: (res) => {
setTimeout(() => {
resolve(res.data.data)
}, 1000)
}
});
})
},
},
onLoad() {
uni.$u.http.get('/api/user/feedtype').then(res => {
console.log(res);
this.category = res.data
}).catch(err => {
console.log(err);
})
}
}
</script>
<style scoped>
.flexBox{
display: flex;
align-items: center;
}
.hv{
background:#3375D8
}
</style>