activityAdd.vue
7.09 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
<template>
<view class="page">
<u-form :model="form" ref="uForm" label-position="left" :label-width="180">
<view class="add-list" style="padding-bottom: 0;">
<u-form-item label="*封面图片" borderBottom labelPosition="top">
<!-- <u-upload :action="$upload" :auto-upload="true" ref="uUpload" :max-count="1" ></u-upload> -->
<u-upload :action="$upload" :auto-upload="false" ref="coverImage" :max-count="1" :file-list="fist"
@on-choose-complete="(response, file, fileList) => onsuccess1(response, file, fileList, 'coverImage')"></u-upload>
</u-form-item>
</view>
<view class="add-list" style="padding-bottom: 0;">
<u-form-item label="*活动名称" borderBottom>
<u-input v-model="form.activityName" />
</u-form-item>
<u-form-item label="*开始时间" borderBottom>
<u-input v-model="form.startTime" type="select" @click="startShow = true" placeholder="请选择"/>
<u-picker mode="time" v-model="startShow" :params="params" @confirm="startTimeChange"></u-picker>
</u-form-item>
<u-form-item label="*结束时间" borderBottom>
<u-input v-model="form.endTime" type="select" @click="endShow = true" placeholder="请选择"/>
<u-picker mode="time" v-model="endShow" :params="params" @confirm="endTimeChange"></u-picker>
</u-form-item>
<u-form-item label="*活动类型" borderBottom>
<u-input v-model="form.activityType" type="select" @click="typeShow = true" placeholder="请选择"/>
<u-select v-model="typeShow" :list="typeList" @confirm="typeChange"></u-select>
</u-form-item>
<u-form-item label="*可参与人数" borderBottom>
<u-number-box v-model="form.maxParticipants" :input-width="'100%'" :min="0"></u-number-box>
</u-form-item>
<u-form-item label="*举办区域" borderBottom>
<u-input v-model="form.region" />
</u-form-item>
<u-form-item label="*活动内容" type = 'textarea' borderBottom auto-height="100">
<u-input v-model="form.content" />
</u-form-item>
</view>
</u-form>
<u-toast ref="uToast" />
<!-- 保存按钮 -->
<view style="height: 120rpx;"></view>
<view class="page-footer">
<u-button type="success" @click="submit">提交</u-button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
fileList: [],
form: {
activityName: '',
startTime:'',
endTime:'',
activityType:'',
maxParticipants:0,
region:'',
content:'',
auditStatus:'1',
createUser:'',
createDate:'',
coverImage:'',
},
active: '', // 文件上传地址
startShow: false,
endShow: false,
params: {
year: true,
month: true,
day: true,
},
typeShow: false,
typeList: [{ value: '1', label: '类型1' }, { value: '2', label: '类型2' }],
readOnly: false,
formats: {}
};
},
methods:{
startTimeChange(val) {
this.form.startTime = this.timeChange(val);
this.form.endTime = '';
},
endTimeChange(val) {
const time = this.timeChange(val);
if(new Date(time).getTime() > new Date(this.form.startTime).getTime()) {
this.form.endTime = time
} else {
this.$refs.uToast.show({
title: '结束时间不能小于开始时间',
type: 'error',
})
}
},
timeChange(val) {
const { year, month, day, hour, minute, second } = val;
return `${year}-${month}-${day}`;
},
typeChange(val) {
this.form.activityType = val[0].label;
},
check(){
if (!this.form.activityName) {
uni.showToast({
icon: 'none',
title: '请输入活动名称'
});
return false;
}
if (!this.form.startTime) {
uni.showToast({
icon: 'none',
title: '请选择开始时间'
});
return false;
}
if (!this.form.endTime) {
uni.showToast({
icon: 'none',
title: '请选择结束时间'
});
return false;
}
if (!this.form.activityType) {
uni.showToast({
icon: 'none',
title: '请选择活动类型'
});
return false;
}
if (!this.form.maxParticipants) {
uni.showToast({
icon: 'none',
title: '请输入可参与人数'
});
return false;
}
if (!this.form.region) {
uni.showToast({
icon: 'none',
title: '请输入举办区域'
});
return false;
}
if (!this.form.content) {
uni.showToast({
icon: 'none',
title: '请输入活动内容'
});
return false;
}
if (!this.form.coverImage) {
uni.showToast({
icon: 'none',
title: '请上传封面图片'
});
return false;
}
return true;
},
submit() {
let show = this.check()
if(show == false){
return
}
this.form.createUser = uni.getStorageSync('user').phone
this.form.createDate = this.currentTime()
let info = {
...this.form,
coverImage:this.form.coverImage.replace(this.$img,'')
}
this.$http.sendRequest('/cereActivityApplication/add', 'POST',info,1).then(res => {
uni.navigateTo({
url: '/pages/mycreated/mycreated'
})
}).catch(err => {
console.log(err)
//请求失败
})
},
// 获取时间
currentTime() {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1; // 月份从0~11,所以加一
let day = date.getDate();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
// 为月、日、时、分、秒添加前导零(如果需要)
month = month < 10 ? '0' + month : month;
day = day < 10 ? '0' + day : day;
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
// 拼接日期和时间字符串
let strDate = `${year}-${month}-${day} ${hours}:${minutes}`;
return strDate;
},
onsuccess1(e, file, fileList, ziduan) {
uni.uploadFile({
url: this.$upload, // 仅为示例,请替换为您的服务器上传接口
filePath: e[0].url,
name: 'file', // 后端接收的文件参数名
formData: {
filePath: 'xcx', // 其他表单数据
},
success: (uploadFileRes) => {
this.form.coverImage = this.$img + JSON.parse(uploadFileRes.data).data
// let obj ={
// url:this.$img + JSON.parse(uploadFileRes.data).data
// }
// this.fist.push(obj)
uni.showToast({
title: '上传成功',
icon: 'success',
});
},
fail: (err) => {
console.error('上传失败', err);
uni.showToast({
title: '上传失败',
icon: 'none',
});
},
});
},
}
}
</script>
<style scoped lang="scss">
@import 'activityAdd.scss';
</style>