appment_main.js
15.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
var e = getApp(),
a = e.globalData.setting,
os = a,
t = e.request,
d = e.globalData;
Page({
/**
* 页面的初始数据
*/
data: {
inurl: a.url, //接口网址
iurl: a.imghost, //服务器网址
store: 0, //是否显示服务门店列表
beautician: 0, //是否显示美容师列表
beautician_name: "", //选中的美容师名称
beauticianID: "", //美容师id
bea_index: "", //美容师列表下标
placeholder: "填写备注", //备注为空的placeholder
store_list: [], //门店列表
beautician_list: [], //美容师列表
store_name: "", //选择的服务门店
fir_pick_index: 0, //选择的门店下标
curpage: 1, //当前分页数
pageSize: 8, //页大小
total: 0,
ismore: 0, //是否加载完毕
itemId: "", //服务id
project_id: "", //项目id
isScroll: true, //scroll-y是否可以滑动
key_word: "", //是否按门店文字查询
is_service_read: 0, //是否调用过门店接口
is_search: 0, //是否通过key_word调用接口
is_success: 0, //是否提交成功
remarks: "", //备注
storageId: "", //线下门店id
url: "/pages/user/my_service/appment_main", //本页面地址路径用于选择时间页面跳转回来
buyType: "", //项目类型
time: "", //选择预约时间
tment_count: "", //可预约人数
lat: "", //纬度坐标
lon: "", //经度坐标
is_gps: 1, //是否开启gps
validay: "", //服务项目有效期
is_sub: 0, //判断是否重复提交
is_textea: 1, //备注是否是可输入
},
//控制备注输入
check_text: function() {
var th = this;
var is_textea = th.data.is_textea;
th.setData({
is_textea: 1,
beautician: 0
})
},
onclickstore: function() {
var th = this;
var store = th.data.store;
if (store) {
th.setData({
store: 0,
is_textea: 1
})
} else {
th.setData({
beautician: 0,
store: 1,
is_textea: 0
})
if (th.data.store_list.length < 1) {
wx.showLoading({
title: '加载中',
})
th.query_store();
}
}
},
//输入的备注
input_remarks: function(e) {
var remarks = e.detail.value;
this.setData({
remarks: remarks
})
},
//提交成功及发送模版代码
success: function() {
var th = this;
var store = th.data.store_name; //门店名称
var bea_name = th.data.beautician_name; //美容师名称
var time = th.data.time; //预约时间
var is_sub = th.data.is_sub; //是否重复提交
var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/insert"; //接口路径
var serviceId = th.data.itemId; //服务id
var beauticianID = th.data.beauticianID; //美容师id
var buyType = th.data.buyType; //服务项目类型
var storeId = a.stoid; //商家id
var storageId = th.data.storageId; //门店id
var userId = d.user_id; //用户id
var remarks = th.data.remarks; //用户备注
var project_id = th.data.project_id; //项目id
var validay = th.data.validay;
var json = {
"arrangeTime": time + ":00",
"beauticianId": beauticianID,
"buyType": buyType,
"effectiveDay": "",
"number": "",
"projectId": project_id,
"remark": remarks,
"serviceId": serviceId,
"states": 0,
"storageId": storageId,
"storeId": storeId,
"userId": userId,
"validay": validay
}
var data = JSON.stringify(json);
wx.request({
url: url,
data: json,
method: 'post',
header: {
'content-type': 'application/json'
}, // 设置请求的 header
success: function(res) {
console.log("真正提交1111111",res.data);
th.setData({
is_sub: 0
})
wx.hideLoading();
if (res.data.code == 0) {
getApp().my_warnning("预约成功", 1, th);
var store_name = th.data.store_name; //预约门店
var number = res.data.data.Number;
var temp_url = "/api/wx/open/app/user/sendSubscribeMsg"; //模版接口
var userinfo = getApp().globalData.userInfo;
var name = d.userInfo.nickname;
var json = {
// "formId": formid,
"keyWord": [{
"keyword": res.data.data.ServiceName
},
{
"keyword": time.substring(0, 16)
}, {
"keyword": res.data.data.BeauticianName
}, {
"keyword": res.data.data.StorageName
}, {
"keyword": res.data.data.Address
}
],
"page": "/pages/user/my_service/tment_details?number=" + number,
"storeId": a.stoid,
"typeId": "1011",
"userId": d.user_id
};
var data = JSON.stringify(json);
//调用发送预约成功模版接口
wx.request({
url: th.data.inurl + temp_url,
data: data,
method: 'post',
header: {
'content-type': 'application/json'
}, // 设置请求的 header
success: function(data) {}
})
setTimeout(function() {
wx.redirectTo({
url: "/pages/user/my_service/tment_details?number=" + number
});
}, 1000);
} else {
getApp().my_warnning(res.data.msg, 0, th);
th.settime();
}
}
})
},
//定时显示texteat
settime: function() {
var th = this;
setTimeout(function() {
th.setData({
is_textea: 1
})
}, 2000);
},
//提交预约
sub_success: function(e) {
var th = this;
var temp_url = th.data.inurl + "/api/wx/weappSendlist/page";
var template_id = "";
if (th.data.is_sub == 1) {
return false;
}
var store = th.data.store_name; //门店名称
var bea_name = th.data.beautician_name; //美容师名称
var time = th.data.time; //预约时间
var is_sub = th.data.is_sub; //是否重复提交
th.setData({
is_textea: 0,
is_sub: 1
})
//提交预约前的判断
if (store == "") {
getApp().my_warnning("请选择服务门店", 0, th);
th.setData({
is_sub:0
})
th.settime();
return false;
} else if (bea_name == "") {
getApp().my_warnning("请选择美容师", 0, th);
th.setData({
is_sub: 0
})
th.settime();
return false;
} else if (time==undefined || time=='') {
getApp().my_warnning("请选择预约时间", 0, th);
th.setData({
is_sub: 0
})
th.settime();
return false;
}else{
//获取模版id
getApp().request.promiseGet(temp_url, {
data: {
store_id: a.stoid,
typeid: "1011"
}
}).then(res => {
wx.showLoading({
title: '加载中',
})
if (res.data.code == 0 && res.data.data.pageData.length > 0) {
template_id = res.data.data.pageData[0].template_id;
// //授权订阅
wx.requestSubscribeMessage({
tmplIds: [template_id],
success(res) {
console.log("成功的回调222222", res);
th.success();
},
fail(res) {
console.log("失败的回调1111111", res.data);
th.success();
}
})
} else {
console.log("接口调用失败0000000", res.data);
th.success();
}
})
}
},
goto: function(e) {
var th = this;
th.setData({
beautician: 0,
is_textea: 0
})
if (th.data.store_name == "") {
getApp().my_warnning("请选择服务门店", 0, th);
th.settime();
} else if (th.data.beautician_name == "") {
getApp().my_warnning("请选择美容师", 0, th);
th.settime();
} else {
th.setData({
is_textea: 1
})
var url = e.currentTarget.dataset.url;
getApp().goto(url);
}
},
//点击选择门店
choose_for_store: function(e) {
var th = this;
var index_c = e.currentTarget.dataset.ind;
var fir_pick_index = th.data.fir_pick_index;
//判断是否点击选中的门店,防止重复点击重复设置选中下标
if (index_c == fir_pick_index) {
return false;
} else {
th.setData({
fir_pick_index: index_c,
beautician_name: "",
time: "",
tment_count: ""
})
}
},
//确认选择门店
choice_store: function() {
var th = this;
var index = th.data.fir_pick_index;
var store_name = th.data.store_list[index].StorageName;
var Id = th.data.store_list[index].Id;
th.setData({
store: 0,
store_name: store_name,
storageId: Id,
is_textea: 1
})
},
onReachBottom: function() {
var th = this;
if (this.data.total <= th.data.pageSize) return;
if (this.data.ismore) return;
wx.showLoading({
title: '加载中...',
})
th.query_store();
},
//分页查询门店信息
query_store: function() {
var th = this;
th.setData({
is_textea: 0
})
var itemId = th.data.itemId; //服务id
var url = "/api/weshop/marketing/reservation/storage/page";
var key_word = th.data.key_word;
key_word = key_word.replace(/\s+/g, "");
getApp().request.promiseGet(url, {
data: {
storeId: a.stoid,
serviceId: itemId,
latitude: th.data.lat,
longitude: th.data.lon,
page: th.data.curpage,
pageSize: th.data.pageSize,
keyWord: key_word
}
}).then(res => {
wx.hideLoading();
if (res.data.code == 0) {
th.data.curpage++;
var arr1 = th.data.store_list;
var arr2 = res.data.data.pageData;
var arr3 = [...arr1, ...arr2];
var ismore = 0;
if (arr3.length == res.data.data.total) ismore = 1
th.setData({
store_list: arr3,
total: res.data.data.total,
ismore: ismore,
is_service_read: 1,
}), wx.stopPullDownRefresh(); //停止下拉刷新
if (key_word != "" && res.data.data.pageData.length < 1) {
th.setData({
is_search: 1
})
}
} else {
getApp().my_warnning(res.data.msg, 0, th);
th.settime();
}
})
},
//查询
query_beautician: function() {
var th = this;
th.setData({
is_textea: 0
})
if (th.data.store_name == "") {
getApp().my_warnning("请选择服务门店", 0, th);
th.settime();
} else {
wx.showLoading({
title: '加载中',
})
var itemid = th.data.itemId; //正式使用的项目id
var storageId = th.data.storageId; //正式使用的线下门店id
var url = "/api/weshop/marketing/reservation/staff/page"; //接口地址
getApp().request.promiseGet(url, {
data: {
storeId: a.stoid,
userId: d.user_id,
serviceId: itemid,
storageId: storageId
}
}).then(res => {
wx.hideLoading();
if (res.data.code == 0) {
th.setData({
beautician_list: res.data.data.pageData
})
if (res.data.data.pageData.length < 1) {
getApp().my_warnning("暂无美容师", 0, th);
th.settime();
} else {
if (th.data.beautician == 0) {
th.setData({
beautician: 1,
})
} else {
th.setData({
beautician: 0,
})
}
}
} else {
getApp().my_warnning(res.data.msg, 0, th);
th.settime();
}
})
}
},
choice_beautician: function(e) {
var th = this;
var bea_index = e.currentTarget.dataset.baaindex;
var bea_name = th.data.beautician_list[bea_index].StaffName;
var BeauticianID = th.data.beautician_list[bea_index].Id;
th.setData({
beautician_name: bea_name,
beautician: 0,
bea_index: bea_index,
beauticianID: BeauticianID,
time: "",
tment_count: "",
is_textea: 1
})
},
//获取搜索门店输入的值
input_store: function(e) {
this.setData({
key_word: e.detail.value
})
},
//搜索门店
search_store: function() {
var th = this;
var key_word = th.data.key_word;
var store_list = th.data.store_list;
th.setData({
curpage: 1,
is_search: 0,
store_list: []
})
wx.showLoading({
title: '加载中',
})
th.query_store();
},
//美容师预约跳转页面
nav_bea: function() {
var th = this;
th.setData({
beautician: 0
})
var storageId = th.data.storageId; //线下门店id
var itemId = th.data.itemId; //服务id
var project_id = th.data.project_id;
if (storageId == "") {
getApp().my_warnning("请选择服务门店", 0, th);
th.settime();
} else {
th.setData({
is_textea: 1
})
wx.navigateTo({
url: "/pages/user/my_service/cosmetology_list?" + 'storageId=' + storageId + '&' + 'itemId=' + itemId + '&' + "projectId=" + project_id
});
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var th = this;
th.setData({
itemId: options.service_id,
buyType: options.BuyType,
project_id: options.ProjectID,
validay: options.Validay
})
wx.getLocation({
type: 'wgs84',
success: function(res) {
th.data.lat = res.latitude;
th.data.lon = res.longitude;
th.data.is_get_local_ok = 1;
th.setData({
is_gps: 1
});
},
fail: function(res) {
if (res.errCode == 2) {
th.setData({
is_gps: 0
});
if (th.data.is_gps == 0) {
getApp().confirmBox("请开启GPS定位", null, 25000, !1);
th.settime();
}
} else {
th.setData({
is_gps: "3"
});
}
th.data.is_get_local_ok = 1;
}
})
},
//查询剩下可预约人数
query_more: function() {
var th = this;
var url = "/api/weshop/marketing/reservation/can/reservation/count";
var beauticianID = th.data.beauticianID; //美容师id
var projectID = th.data.itemId; //服务id
var seekTime = th.data.time; //预约日期
var storageId = th.data.storageId; //门店id
var storeId = a.stoid; //商家id
getApp().request.promiseGet(url, {
data: {
beauticianId: beauticianID,
seekTime: seekTime,
serviceId: projectID,
storageId: storageId,
storeId: storeId
}
}).then(res => {
if (res.data.code == 0) {
var tment_count = res.data.data.CanReservation;
th.setData({
tment_count: tment_count
})
} else {
getApp().my_warnning(res.data.msg, 0, th);
th.settime();
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
var th = this;
var seekTime = th.data.time; //预约日期
if (seekTime != "") {
th.query_more();
}
th.setData({
time: th.data.time.substring(0, 16),
is_textea: 1
})
th.query_project();
},
//获取单个服务项目信息
query_project: function() {
var th = this;
var url = "/api/weshop/marketing/reservation/sm/page"; //获取服务项目接口
var project_id = th.data.project_id; //服务项目id
getApp().request.promiseGet(url, {
data: {
storeId: a.stoid,
userId: d.user_id,
projectId: project_id
}
}).then(res => {
if (res.data.code == 0) {
th.setData({
validay: res.data.data.pageData[0].Validay
})
} else {
getApp().my_warnning(res.data.msg, 0, th);
th.settime();
}
})
},
//关闭导航
close: function() {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.close_box();
}
})