reservationDialog.vue
10.2 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
<template>
<div>
<GLDialog
bigTitle="预约时间"
:visible.sync="dialogShow"
class="detail-content-warn"
width="620px"
mode="big"
:close-on-click-modal="false"
:before-close="handleClose"
@onOk="handleAddConfirm"
@onCancel="dialogShow = false"
>
<div v-loading="loading">
<div class="form_div">
<div class="tipsDiv">
<div class="tipsText">
{{ paramsObj.customer.customerName + ' | ' + paramsObj.customer.customerPhone }}
</div>
</div>
<el-form
label-width="100px"
:model="infoForm"
ref="editRef"
:rules="formRules"
>
<el-form-item label="流量有效性:">
<el-form-item>
<el-select
v-model="infoForm.trafficEffectiveness"
placeholder="请选择"
class="select-width"
:disabled="trafficEffectivenessDisabled"
>
<el-option
v-for="(item, key) in trafficEffectivenessOpt"
:key="key"
:label="item.confValue"
:value="item.confId"
>
</el-option>
</el-select>
</el-form-item>
</el-form-item>
<el-form-item
label="预约时间:"
required
>
<el-col :span="10">
<el-form-item prop="dateTime">
<el-date-picker
v-model="infoForm.dateTime"
:clearable="false"
type="date"
class="default-width"
placeholder="选择日期"
value-format="yyyy-MM-dd"
@change="inviteStatMerchantList(true)"
:picker-options="datePickerOptions"
></el-date-picker>
</el-form-item>
</el-col>
<el-col :span="1"></el-col>
<el-col :span="13">
<el-form-item prop="times">
<el-select
v-model="infoForm.times"
filterable
placeholder="请选择"
class="default-width"
>
<el-option
v-for="(item, key) in timesOpt"
:key="key"
:label="item.confValue"
:value="item.confId"
:disabled="item.disabled"
></el-option>
</el-select>
<el-button
type="text"
size="small"
class="timesSle"
v-if="paramsObj.inviteDate"
@click="cancelInvite"
>取消预约</el-button>
</el-form-item>
</el-col>
</el-form-item>
</el-form>
</div>
</div>
</GLDialog>
</div>
</template>
<script>
import * as dayjs from 'dayjs'
export default {
name: 'ReservationDialog',
components: {},
props: {
visible: {
type: Boolean,
default: false
},
paramsObj: {
type: Object,
default: null
}
},
computed: {
dialogShow: {
get () {
return this.visible
},
set (val) {
this.$emit('dialogClose', { flag: val })
}
},
trafficEffectivenessDisabled () {
let { orderStatus } = this.paramsObj
//已支付4、已施工、已失效11、已撤销9、已评价6、已关闭10、战败2 不支持编辑
return [4, 11, 9, 6, 10, 2].includes(orderStatus)
}
},
mounted () {
this.loading = false
console.log('this.paramsObj', this.paramsObj)
this.inviteDatePush()
},
data () {
// var validateDateTime = {
// validator: (rule, value, callback) => {
// if (!value) {
// return callback(new Error(`请选择日期`))
// }
// const times = this.infoForm.times
// if (!times) {
// return callback(new Error(`请选择时间段`))
// }
// callback() // 验证通过
// },
// trigger: 'change'
// }
return {
infoForm: {
dateTime: '',
times: '',
trafficEffectiveness: ''
},
editChildRef: 'editChildRef',
formRules: {
// dateTime: [validateDateTime]
dateTime: [{ required: true, message: '请选择日期', trigger: 'change' }],
times: [{ required: true, message: '请选择时间段', trigger: 'change' }]
},
datePickerOptions: {
disabledDate: time => {
const today = new Date()
// 设置时间到当天的开始 (00:00:00.000),避免时分秒影响比较
today.setHours(0, 0, 0, 0)
// 计算一个月后的日期 (今天 + 30天)
const oneMonthLater = new Date(today)
oneMonthLater.setDate(today.getDate() + 30) // 粗略按30天算一个月
// 或者更精确地处理月份 (考虑不同月份天数差异)
// oneMonthLater.setMonth(today.getMonth() + 1);
// 禁用规则:
// 1. 禁用早于今天(包含今天00:00:00之前)的日期
// 2. 禁用晚于一个月后(包含一个月后23:59:59之后)的日期
return time.getTime() < today.getTime() || time.getTime() > oneMonthLater.getTime()
}
},
loading: true,
baseData: {
technicianList: []
},
timesOpt: [
{ confId: '09:00', confValue: '09:00', disabled: false },
{ confId: '10:30', confValue: '10:30', disabled: false },
{ confId: '13:00', confValue: '13:00', disabled: false },
{ confId: '14:30', confValue: '14:30', disabled: false },
{ confId: '16:00', confValue: '16:00', disabled: false }
],
trafficEffectivenessOpt: [
{ confId: 1, confValue: "有效客户" },
{ confId: 2, confValue: "无效客户" },
],
}
},
methods: {
inviteDatePush () {
let { trafficEffectiveness, inviteDate } = this.paramsObj
if (trafficEffectiveness) this.infoForm.trafficEffectiveness = trafficEffectiveness
if (inviteDate) {
const dateTimeStr = dayjs(inviteDate).format('YYYY-MM-DD HH:mm:ss')
// 截取年月日(空格前)
this.infoForm.dateTime = dateTimeStr.split(' ')[0]
// 截取时分(去掉秒)
this.infoForm.times = dateTimeStr.split(' ')[1].substring(0, 5) // "09:00"
this.inviteStatMerchantList(false)
}
},
inviteStatMerchantList (flag) {
if (flag) {
this.infoForm.times = ''
}
var params = {}
params.merchantId = this.paramsObj.yqMerchantId
params.startDate = this.infoForm.dateTime
params.endDate = this.infoForm.dateTime
console.log('params', params)
this.$apis.invitation.inviteStatMerchantList(params).then(res => {
const saturdayFlag = res[0].saturdayFlag
const sundayFlag = res[0].sundayFlag
const timeStats = res[0].timeStats
const day = new Date(this.infoForm.dateTime).getDay()
if (saturdayFlag === 'N' && day === 6) {
this.$message.warning('工位设置不允许周六施工,请选择其他时间')
this.infoForm.dateTime = ''
return
} else if (sundayFlag === 'N' && day === 0) {
this.$message.warning('工位设置不允许周日施工,请选择其他时间')
this.infoForm.dateTime = ''
return
}
timeStats.forEach(item => {
this.timesOpt.forEach(optItem => {
if (item.inviteTime === optItem.confValue) {
if (item.inviteNum < item.maxNum) {
optItem.disabled = false
} else {
optItem.disabled = true
}
}
})
})
console.log('this.timesOpt', this.timesOpt)
})
},
handleAddConfirm () {
this.$refs.editRef.validate(valid => {
if (valid) {
var params = this.$common.utils.deepClone(this.infoForm)
params.id = this.paramsObj.id
params.inviteType = this.paramsObj.customerCoupon.couponType
params.inviteDateStr = params.dateTime + ' ' + params.times + ':00'
delete params.dateTime
delete params.times
const targetTime = new Date(params.inviteDateStr).getTime() // 转为时间戳
const now = new Date().getTime() // 当前时间戳
if (targetTime < now) {
this.$message.warning('预约时间不能选择已过去的时间')
return
}
this.$apis.invitation.dateUpdate(params).then(res => {
this.$notify({
type: 'success',
title: '操作成功'
})
this.dialogShow = true
})
}
})
},
cancelInvite () {
this.$confirm('请确认是否要执行当前操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
closeOnClickModal: false
})
.then(() => {
var params = {}
params.id = this.paramsObj.id
this.$apis.invitation.cancelInvite(params).then(res => {
this.$notify({
type: 'success',
title: '操作成功'
})
this.dialogShow = true
})
})
.catch(err => {
console.log(err)
})
}
}
}
</script>
<style lang="scss" scoped>
.detail-content-warn {
.div-title {
width: 1040px;
height: 30px;
border-bottom: 1px solid #e5e5e5;
font-size: 16px;
font-weight: 600;
color: #333333;
margin: 10px 0 20px 0;
}
.el-icon-circle-close {
color: #ffffff;
}
.form_div {
color: #333333;
.tipsDiv {
height: 28px;
margin-bottom: 20px;
.tipsText {
padding-left: 20px;
font-size: 14px;
}
}
}
.default-width {
width: 170px;
}
.timesSle {
padding-left: 10px;
}
.select-width {
width: calc(100% - 110px);
}
}
</style>