publicSaveDialog.vue
7.76 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
<template>
<div>
<el-dialog
:title="title2"
:visible.sync="dialogVisible"
:before-close="handleCloseDialog">
<el-form :model="publicForm" ref="publicForm" :rules="publicRules" label-width="130px">
<el-form-item label="标题:" prop="title">
<el-input v-model="publicForm.title" maxlength="50" show-word-limit></el-input>
</el-form-item>
<el-form-item label="开始时间:" prop="startT">
<el-date-picker
v-model="publicForm.startT"
type="datetime"
value-format="timestamp"
placeholder="选择日期时间">
</el-date-picker>
<!-- <el-date-picker
v-model="publicForm.startDate"
type="date"
placeholder="选择日期(必填)"
format="yyyy年MM月dd日"
value-format="yyyy年MM月dd日"
:picker-options="pickerOptionsStart">
</el-date-picker>
<el-time-picker
v-model="publicForm.startTime"
format="HH:mm:ss"
value-format="HH:mm:ss"
placeholder="选择时间">
</el-time-picker>-->
</el-form-item>
<el-form-item label="结束时间:" prop="endT">
<el-date-picker
v-model="publicForm.endT"
type="datetime"
value-format="timestamp"
placeholder="选择日期时间">
</el-date-picker>
<!-- <el-date-picker
v-model="publicForm.endDate"
type="date"
placeholder="选择日期(必填)"
format="yyyy年MM月dd日"
value-format="yyyy年MM月dd日"
:picker-options="pickerOptionsEnd"
>
</el-date-picker>
<el-time-picker
v-model="publicForm.endTime"
format="HH:mm:ss"
value-format="HH:mm:ss"
placeholder="选择时间">
</el-time-picker>-->
</el-form-item>
<el-form-item label="地点:" prop="city">
<el-input v-model="publicForm.city" maxlength="100"
show-word-limit></el-input>
<!-- <el-row :gutter="5">
<el-col :span="7">
<el-select
v-model="publicForm.province"
filterable
placeholder="省"
@change="provinceSelectChangeHandler"
>
<el-option
v-for="(item,index) in provinceList"
:key="index"
:label="item.areaName"
:value="item.areaName"
></el-option>
</el-select>
</el-col>
<el-col :span="7">
<el-select
v-model="publicForm.city"
filterable
placeholder="市"
>
<el-option
v-for="(item,index) in cityList"
:key="index"
:label="item.areaName"
:value="item.areaName"
></el-option>
</el-select>
</el-col>
</el-row>-->
</el-form-item>
<el-form-item label="注册/回放:" prop="enroll">
<el-input v-model="publicForm.enroll" maxlength="200"
show-word-limit></el-input>
</el-form-item>
<el-form-item label="团队:" prop="team">
<el-input v-model="publicForm.team" maxlength="100"
show-word-limit></el-input>
</el-form-item>
<el-form-item label="内容:" prop="content">
<el-input v-model="publicForm.content" type="textarea" maxlength="500"
show-word-limit></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm('publicForm')">提交</el-button>
<el-button @click="handleCloseDialog">取消</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {request} from '@/api/fetch-api'
let urls = {
publicSaveUrl: '/tianbao_edu_api/admin/public/save',
areaUrl: 'https://api.k.wxpai.cn/bizproxy/kdapi/area',
}
export default {
props: ['dialogVisible', 'publicTemp'],
data() {
return {
title2: '',
publicForm: {},
publicRules: {
title: [{required: true, message: '请输入标题', trigger: 'blur'}],
startT: [{required: true, message: '请选择开始时间', trigger: 'blur'}],
endT: [{required: true, message: '请选择结束时间', trigger: 'blur'}],
enroll: [{required: true, message: '请填写报名', trigger: 'blur'}],
city: [{required: true, message: '请选择省市', trigger: 'blur'}],
content: [{required: true, message: '请输入内容', trigger: 'blur'}],
team: [{required: true, message: '请输入团队', trigger: 'blur'}],
},
provinceList: [],
cityList: [],
pickerOptionsStart: {
disabledDate: time => {
let endDateVal = this.publicForm.endDate;
if (endDateVal) {
return time.getTime() >= new Date(endDateVal).getTime();
}
}
},
pickerOptionsEnd: {
disabledDate: time => {
let beginDateVal = this.publicForm.startDate;
if (beginDateVal) {
return (
time.getTime() < new Date(beginDateVal).getTime()-24*60*60*1000
);
}
},
},
}
},
methods: {
handleCloseDialog() {
this.$emit('closedialog', false)
},
init() {
if (JSON.parse(JSON.stringify(this.publicTemp)) == null) {
this.title2 = '创建'
} else {
this.title2 = "修改"
this.publicForm = JSON.parse(JSON.stringify(this.publicTemp))
}
},
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
request.post(urls.publicSaveUrl, this.publicForm).then(response => {
this.$emit('initPublic')
this.$emit('closedialog', false)
this.$message.success("保存成功")
}).catch(() => {
})
} else {
console.log('error submit!!')
return false
}
})
},
getProvince() {
request.post(urls.areaUrl, {}).then(res => {
this.provinceList = res.content
})
},
provinceSelectChangeHandler(province) {
this.cityList = null
let areaId = this.findAreaId(
this.provinceList,
province
)
request.post(urls.areaUrl, {parentId: areaId}).then(res => {
this.cityList = res.content
})
},
findAreaId(areaList, name) {
let areaId = ''
areaList.forEach(element => {
if (element.areaName == name) {
areaId = element.areaId
}
})
return areaId
},
changeStart() {
this.pickerOptionsStart = Object.assign({}, this.pickerOptionsStart, {
// 可通过箭头函数的方式访问到this
disabledDate: (time) => {
var times = '';
times = this.publicForm.endDate < time.getTime() || time.getTime() < new Date(new Date().toLocaleDateString())
.getTime();
return times
}
})
},
//开始时间 控制结束时间
changeEnd() {
this.pickerOptionsEnd = Object.assign({}, this.pickerOptionsEnd, {
disabledDate: (time) => {
return time.getTime() > this.publicForm.startDate
}
})
},
},
created() {
this.init()
this.getProvince()
}
}
</script>
<style scoped>
</style>