beauty_deta.js
11.9 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
var e = getApp(),
a = e.globalData.setting,
os = a,
t = e.request,
d = e.globalData;
Page({
/**
* 页面的初始数据
*/
data: {
inurl: a.url, //接口网址
iurl: a.imghost,
url: "", //选择选择时间后返回的页面
defimgurl: "/miniapp/images/no-head.jpg",
seekTime: "", //当前服务预约选择的时间
time_list: [], //可预约时间
name: "", //美容师姓名
comment: "", //美容师评价
aweeks: [], //七天的预约时间
head_img: "", //美容师头像
time:['08:00','08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00','14:30', '15:00', '15:30', '16:00', '16:30', '17:00','17:30', '18:00','18:30', '19:00', '19:30', '20:00', '20:30', '21:00', '21:30', '22:00','22:30'],
weeks: [], //星期几数组
time_index: -1, //选择预约时间下标
date_id: 0, //选择日期的id
beautician_id: "", //美容师id
itemId: "", //服务id
number: "", //预约单号
modify: 0, //是否是修改时间
iscos: 0, //是否是从美容师列表过来的
hours: "", //获取当前时分秒
projectId: "", //项目id
StaffName: "", //美容师名称
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var th = this;
var myDate = new Date();
var minutes = myDate.getMinutes(); //获取当前分钟数(0-59)
var hours = myDate.getHours() + ":" + minutes; //获取当前小时数(0-23)
var beautician_id = options.BeauticianID;
var storageId = options.StorageId;
th.setData({
options,
storeid: options.storeid,
beautician_id: beautician_id,
itemId: options.itemId,
modify: options.modify,
hours: hours,
projectId: options.projectId,
storageId:storageId
})
if (options.url != undefined) {
th.setData({
url: options.url
})
}
if (options.number != undefined) {
th.setData({
number: options.number
})
}
if (options.iscos != undefined) {
th.setData({
iscos: options.iscos
})
}
if (options.StaffName!=undefined){
th.setData({
StaffName: options.StaffName
})
}
th.query_beatea(th.query_aweek);
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
var th = this;
//获取当前时间
var myDate = new Date();
// var date = myDate.getHours(); //获取当前小时数(0-23);
let str = myDate.toTimeString(); //"10:55:24 GMT+0800 (中国标准时间)"
let date = str.substring(0, 8); // '10:55:24'
th.setData({
hours: date
});
},
//图片失败,默认图片
bind_bnerr1: function(e) {
var _errImg = e.target.dataset.errorimg;
var _Img = e.target.dataset.img;
if (_Img != undefined) {
var _errObj = {};
_errObj[_errImg] = "/miniapp/images/no-head.jpg";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
},
//选择服务日期
check_date: function(e) {
var th = this;
var id = e.currentTarget.dataset.dateid;
var date_id = th.data.date_id;
var seekTime = th.data.aweeks[id].time;
if (id != date_id) {
th.setData({
date_id: id,
seekTime: seekTime
})
th.query_date();
}
},
//获取美容师信息
query_beatea: function(func) {
var th = this;
var url = "/api/weshop/marketing/reservation/staff/get"; //接口路径
var beautician_id = th.data.beautician_id;
getApp().request.promiseGet(url, {
data: {
beauticianId: beautician_id,
storeId: th.data.storeid,
}
}).then(res => {
if (res.data.code == 0) {
var data = res.data.data;
var ob={
name: data.StaffName,
comment: data.Remark1,
head_img: data.PhotoUrl
};
if(!th.data.storageId){
ob.storageId=data.StorageId;
}
th.setData(ob);
func();
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
})
},
//返回上个页面
navigateBack: function() {
var th = this;
var modify = th.data.modify; //是否是更改时间
var seekTime = th.data.seekTime; //选择的日期
var time_list = th.data.time_list;
var time_index = th.data.time_index;
if (time_index == -1) {
getApp().my_warnning("请选择预约时间", 0, th);
return false;
}
var date_id = th.data.date_id;
var date = th.data.aweeks[date_id].time;
var time = date + " " + time_list[time_index] + ":00";
if (modify == 1) {
var json = {
"arrangeTime": time,
"number": th.data.number,
"remark": "更改时间",
"states": 0,
"storeId": th.data.storeid,
};
var data = JSON.stringify(json);
var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址
wx.request({
url: url,
data: data,
method: 'put',
header: {
'content-type': 'application/json'
}, // 设置请求的 header
success: function(res) {
if (res.data.code == 0) {
getApp().my_warnning(res.data.data, 1, th);
setTimeout(function() {
wx.navigateBack({
//返回
delta: 1
})
}, 1000);
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
}
})
} else {
var pages = getCurrentPages(); //当前页面
var iscos = th.data.iscos;
var delta = 1;
if (Number(iscos) == 1) {
delta = delta + Number(iscos); //返回哪个页面
var prevPage = pages[pages.length - 2 - Number(iscos)]; //上一页面
prevPage.setData({
//直接给上一个页面赋值
time: time,
beautician_name: th.data.StaffName,
beauticianID: th.data.beautician_id
});
wx.navigateBack({
//返回
delta: 2
})
} else {
var prevPage = pages[pages.length - 2]; //上一页面
prevPage.setData({
//直接给上一个页面赋值
time: time
});
wx.navigateBack({
//返回
delta: 1
})
}
}
},
//选择时间
Selection_time: function(e) {
var th = this;
var index = e.currentTarget.dataset.index;
var time_index = th.data.time_index;
if (index == time_index) {
return false;
} else {
th.setData({
time_index: index
})
}
},
//查询七天预约时间
query_aweek: function() {
var th = this;
var beautician_id = th.data.beautician_id; //美容师id
var storageId=th.data.storageId;
var itemId = th.data.itemId; //服务id
var projectId = th.data.projectId; //项目id
var url = "/api/weshop/marketing/reservation/staff/seven/time/listnew"; //接口地址
getApp().request.promiseGet(url, {
data: {
projectId: projectId,
beauticianId: beautician_id,
serviceId: itemId,
storeId: th.data.storeid,
storageId:storageId
}
}).then(res => {
if (res.data.code == 0) {
var data = res.data.data;
var arr = [];
for (var i in data) {
var em = {
"time": i,
"val": data[i]
};
arr.push(em);
}
arr.sort(th.sort_arr);
var weeks = ["今天", "明天", "后天"];
var week = "";
for (var i = 3; i < arr.length; i++) {
var date = new Date(arr[i].time);
if (date.getDay() == 0) week = "周日"
if (date.getDay() == 1) week = "周一"
if (date.getDay() == 2) week = "周二"
if (date.getDay() == 3) week = "周三"
if (date.getDay() == 4) week = "周四"
if (date.getDay() == 5) week = "周五"
if (date.getDay() == 6) week = "周六"
weeks[i] = week;
}
th.setData({
aweeks: arr,
weeks: weeks
})
th.query_date();
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
})
},
query_date: function() {
var th = this;
var projectId = th.data.projectId;
var date_id = th.data.date_id; //日期下标
var SeekTime = th.data.aweeks[date_id].time;
var val = th.data.aweeks[date_id].val;
var url = "/api/weshop/marketing/reservation/staff/time/listnew";
getApp().request.promiseGet(url, {
data: {
projectId: projectId,
staffId: th.data.beautician_id,
storageId:th.data.storageId,
serviceId: th.data.itemId,
seekTime: SeekTime,
storeId: th.data.storeid,
}
}).then(res => {
if (res.data.code == 0) {
var hours = th.data.hours;
var time_list = res.data.data;
var time = th.data.time;
var date_id = th
var new_time = [];
var date = th.data.hours.substring(0,2);
//不等于空就是有可以预约的时间
if (time_list != null) {
if (res.data.data && res.data.data[0]!= undefined) {
if (res.data.data[0].GroupHour && res.data.data[0].GroupHour.length > 11) {
getApp().my_warnning(res.data.data[0].GroupHour, 0, th);
}
}
//循环固定和可预约的时间
for (var i = 0; i < time.length; i++) {
for (var ii = 0; ii < time_list.length; ii++) {
//判断固定的时间和可以预约的时间
if (time[i] == time_list[ii].begintime.substring(0, 5)) {
var date_id = th.data.date_id;
if (date > time_list[ii].begintime.substring(0, 2) && date_id == 0) {
new_time[i] = "";
break;
}else{
new_time[i] = time_list[ii].begintime.substring(0, 5);
break;
}
} else {
new_time[i] = "";
}
}
}
}else{
for(var i = 0 ;i<time.length;i++){
new_time[i]="";
}
}
th.setData({
time_list: new_time,
})
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
})
},
//更改预约时间
change_time: function() {
var th = this;
var seekTime = th.data.seekTime; //选择的日期
var time_list = th.data.time_list;
var time_index = th.data.time_index;
var time = time_list[time_index];
var number = th.data.number; //预约单号
var json = {
"arrangeTime": seekTime + " " + time,
"number": number,
"remark": "更改预约时间",
"states": 0,
"storeId": th.data.storeid,
};
var data = JSON.stringify(json);
var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址
wx.request({
url: url,
data: data,
method: 'put',
header: {
'content-type': 'application/json'
}, // 设置请求的 header
success: function(res) {
if (res.data.code == 0) {
getApp().my_warnning("更改成功", 0, th);
} else {
getApp().my_warnning(res.data.msg, 0, th);
}
}
})
},
//预览头像
previewImage: function(e) {
var th = this;
var current = e.currentTarget.dataset.src;
wx.previewImage({
current: current, // 当前显示图片的http链接
urls: [th.data.head_img] // 需要预览的图片http链接列表
})
},
sort_arr: function(a, b) {
a = a['time'];
b = b['time'];
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
},
check_is_in_arr:function(val,pdata) {
if(!val || !pdata) return false;
for(var i in pdata){
if(pdata[i].begintime.indexOf(val)!=-1){
return true;
}
}
return false;
}
})