BookingDialog.vue
10.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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<template>
<el-dialog
:visible.sync="visibleProxy"
:show-close="false"
width="520px"
:close-on-click-modal="false"
custom-class="booking-dialog"
append-to-body
>
<div class="booking-dialog-inner">
<div class="booking-header">
<div class="booking-title-wrap">
<div class="booking-title">{{ prefill.editBookingId ? '编辑预约' : '新建预约' }}</div>
</div>
</div>
<el-form
ref="form"
:model="form"
:rules="rules"
label-width="96px"
size="small"
class="booking-form"
>
<el-form-item label="预约体验项目" prop="yytyxm">
<el-select
v-model="form.yytyxm"
placeholder="请选择体验项目"
filterable
clearable
>
<el-option
v-for="item in projectOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="顾客姓名" prop="gkxm">
<el-select
v-model="form.gkxm"
placeholder="请选择顾客姓名"
filterable
clearable
>
<el-option
v-for="item in customerOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="预约健康师" prop="yyjks">
<el-select
v-model="form.yyjks"
placeholder="请选择健康师"
filterable
clearable
:disabled="!!prefill.yyjks"
>
<el-option
v-for="item in effectiveHealthWorkerOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="预约日期" prop="yyrq">
<el-date-picker
v-model="form.yyrq"
type="date"
placeholder="请选择预约日期"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="开始时间" prop="yysj">
<el-time-select
v-model="form.yysj"
:picker-options="timeOptions"
placeholder="开始时间"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="结束时间" prop="yysjEnd">
<el-time-select
v-model="form.yysjEnd"
:picker-options="timeOptionsEnd"
placeholder="结束时间"
style="width: 100%"
/>
</el-form-item>
</el-form>
<div class="booking-footer">
<el-button size="small" @click="handleCancel">取 消</el-button>
<el-button
type="primary"
size="small"
:loading="submitting"
@click="handleSubmit"
>
{{ submitting ? '提交中...' : '保 存' }}
</el-button>
</div>
</div>
</el-dialog>
</template>
<script>
export default {
name: 'BookingDialog',
props: {
visible: { type: Boolean, default: false },
prefill: {
type: Object,
default: () => ({})
},
// 外部传入的健康师列表,用于排班等场景(与 employeeList 对应)
healthWorkerOptions: {
type: Array,
default: null
}
},
data() {
return {
submitting: false,
form: {
yytyxm: '',
gkxm: '',
yyjks: '',
yyrq: '',
yysj: '',
yysjEnd: ''
},
projectOptions: [
{ value: 'proj001', label: '基础护理' },
{ value: 'proj002', label: '深度清洁' },
{ value: 'proj003', label: '美白护理' },
{ value: 'proj004', label: '抗衰护理' },
{ value: 'proj005', label: '补水保湿' }
],
customerOptions: [
{ value: 'cust001', label: '张三' },
{ value: 'cust002', label: '李四' },
{ value: 'cust003', label: '王五' },
{ value: 'cust004', label: '赵六' },
{ value: 'cust005', label: '钱七' }
],
defaultHealthWorkerOptions: [
{ value: 'jks001', label: '张健康师' },
{ value: 'jks002', label: '李健康师' },
{ value: 'jks003', label: '王健康师' },
{ value: 'jks004', label: '赵健康师' },
{ value: 'jks005', label: '钱健康师' }
],
timeOptions: {
start: '09:00',
step: '00:30',
end: '21:00'
},
rules: {
yytyxm: [{ required: true, message: '请选择体验项目', trigger: 'change' }],
gkxm: [{ required: true, message: '请选择顾客姓名', trigger: 'change' }],
yyjks: [{ required: true, message: '请选择健康师', trigger: 'change' }],
yyrq: [{ required: true, message: '请选择预约日期', trigger: 'change' }],
yysj: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
yysjEnd: [
{ required: true, message: '请选择结束时间', trigger: 'change' },
{ validator: (rule, value, cb) => {
if (!value || !this.form.yysj) { cb(); return }
const [sh, sm] = this.form.yysj.split(':').map(Number)
const [eh, em] = value.split(':').map(Number)
if (eh < sh || (eh === sh && em <= sm)) cb(new Error('结束时间须晚于开始时间'))
else cb()
}, trigger: 'change' }
]
}
}
},
computed: {
visibleProxy: {
get() {
return this.visible
},
set(val) {
this.$emit('update:visible', val)
}
},
effectiveHealthWorkerOptions() {
return this.healthWorkerOptions && this.healthWorkerOptions.length
? this.healthWorkerOptions
: this.defaultHealthWorkerOptions
},
timeOptionsEnd() {
const base = { ...this.timeOptions }
if (this.form.yysj) {
const [h, m] = this.form.yysj.split(':').map(Number)
const next = (h * 60 + m + 30) % (24 * 60)
base.start = `${String(Math.floor(next / 60)).padStart(2, '0')}:${String(next % 60).padStart(2, '0')}`
const [eh, em] = (base.end || '21:00').split(':').map(Number)
if (next >= eh * 60 + em) base.end = '22:00'
}
return base
}
},
watch: {
visible(val) {
if (val) {
this.applyPrefill()
}
},
prefill: {
deep: true,
handler() {
if (this.visible) {
this.applyPrefill()
}
}
},
'form.yysj'(val) {
if (val && this.form.yysjEnd) {
const [sh, sm] = val.split(':').map(Number)
const [eh, em] = this.form.yysjEnd.split(':').map(Number)
if (eh < sh || (eh === sh && em <= sm)) this.form.yysjEnd = ''
}
}
},
methods: {
applyPrefill() {
if (!this.prefill) return
if (this.prefill.name) this.form.gkxm = this.prefill.name
if (this.prefill.yyjks != null) this.form.yyjks = this.prefill.yyjks
if (this.prefill.yyrq != null) {
this.form.yyrq = this.prefill.yyrq instanceof Date ? this.prefill.yyrq : new Date(this.prefill.yyrq)
}
if (this.prefill.yysj) this.form.yysj = this.prefill.yysj
if (this.prefill.yysjEnd) this.form.yysjEnd = this.prefill.yysjEnd
if (this.prefill.gkxm) this.form.gkxm = this.prefill.gkxm
else if (this.prefill.name) this.form.gkxm = this.prefill.name
if (this.prefill.yytyxm) this.form.yytyxm = this.prefill.yytyxm
if (!this.form.yyrq) this.form.yyrq = new Date()
},
resetForm() {
this.form = {
yytyxm: '',
gkxm: '',
yyjks: '',
yyrq: '',
yysj: '',
yysjEnd: ''
}
this.$refs.form && this.$refs.form.clearValidate()
},
handleCancel() {
this.visibleProxy = false
this.resetForm()
},
handleSubmit() {
this.$refs.form.validate(valid => {
if (!valid) return
this.submitting = true
setTimeout(() => {
this.submitting = false
this.$message.success('预约已保存(示例)')
this.visibleProxy = false
this.resetForm()
}, 800)
})
}
}
}
</script>
<style lang="scss" scoped>
.booking-dialog-inner {
padding: 18px 22px 14px;
}
.booking-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
padding: 10px 14px;
border-radius: 14px;
background: rgba(219, 234, 254, 0.96);
}
.booking-title-wrap {
flex: 1;
}
.booking-title {
font-size: 17px;
font-weight: 600;
color: #0f172a;
}
.booking-form {
padding-top: 6px;
}
::v-deep .booking-dialog .el-form-item__label {
white-space: nowrap;
}
.booking-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 8px;
}
::v-deep .booking-dialog {
max-width: 520px;
margin-top: 10vh !important;
border-radius: 20px;
padding: 0;
background: radial-gradient(
circle at 0 0,
rgba(255, 255, 255, 0.96) 0,
rgba(248, 250, 252, 0.98) 40%,
rgba(241, 245, 249, 0.98) 100%
);
box-shadow:
0 24px 48px rgba(15, 23, 42, 0.18),
0 0 0 1px rgba(255, 255, 255, 0.9);
backdrop-filter: blur(22px);
-webkit-backdrop-filter: blur(22px);
}
::v-deep .el-dialog__header {
display: none;
}
::v-deep .el-dialog__body {
padding: 0;
}
/* 输入框圆角与现代化样式 */
::v-deep .booking-dialog .el-input__inner {
border-radius: 999px;
height: 32px;
line-height: 32px;
border-color: #e5e7eb;
background-color: #f9fafb;
}
::v-deep .booking-dialog .el-input__inner:focus {
border-color: #2563eb;
box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.18);
}
::v-deep .booking-dialog .el-picker-panel {
border-radius: 12px;
}
/* 统一按钮风格:胶囊 + 蓝色主按钮,与其他弹窗一致 */
::v-deep .booking-dialog .el-button--primary {
border-radius: 999px;
padding: 0 20px;
height: 30px;
line-height: 30px;
background: #2563eb;
border-color: #2563eb;
box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
font-size: 12px;
}
::v-deep .booking-dialog .el-button--primary.is-disabled {
box-shadow: none;
}
::v-deep .booking-dialog .el-button--default {
border-radius: 999px;
padding: 0 18px;
height: 30px;
line-height: 30px;
background: rgba(239, 246, 255, 0.9);
color: #2563eb;
border-color: rgba(37, 99, 235, 0.18);
font-size: 12px;
}
::v-deep .booking-dialog .el-button--default:hover {
background: rgba(219, 234, 254, 0.95);
color: #1d4ed8;
}
</style>