inviteBase.js
42 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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
// 公共方法:由 detail_owner_invitation2~13 中代码级一致的方法抽取,页面内请勿再重复定义同名方法
// 页面用法:import inviteBase from '../common/inviteBase'; Page({ ...inviteBase, ...页面配置 })
import util from '../../utils/util';
import App from '../../utils/api';
import canvas from '../../pages/customer/canvas';
const plugin = requirePlugin("WechatSI");
export default {
// Default forwarding to enabled; explicit 0 keeps it disabled
normalizeMarketing(marketing) {
marketing = marketing && typeof marketing === 'object' ? marketing : {};
marketing.is_transpond = (marketing.is_transpond === 0 || marketing.is_transpond === '0') ? '0' : '1';
return marketing;
},
// 获取所有的券并且展示(2-13页面)
addCoupons(coupons, couponList) {
if (coupons && util.getType(coupons) == 'object') {
couponList.push({
id: coupons.id,
number: coupons.number
});
}
if (coupons && util.getType(coupons) === 'array' && coupons.length > 0) {
coupons.forEach(item => {
couponList.push({
id: item.id,
number: item.number
});
});
}
return couponList
},
// 持续旋转动画(2-13页面)
animation() {
let that = this;
var time = setInterval(function () {
this.n = this.n + 1;
let attentionAnim = that.data._attentionAnim
attentionAnim.rotate(180 * (this.n)).step()
that.setData({
attentionAnim: attentionAnim.export(),
})
}.bind(this), 1000)
this.timers = time;
},
// 拨打电话(2-13页面)
call(e) {
const phone = e.currentTarget.dataset['phone'];
wx.reportMonitor('1012', 1)
wx.makePhoneCall({
phoneNumber: phone
})
},
// 关闭优惠券弹框(更新已被领取数量)(2-13页面)
closeCouponModal() {
this.getActivityByIdFun(this.data.couponList, '1')
this.couponModal.closeModal()
this.setData({
isShow: '1',
})
setTimeout(() => {
this.startAnimation();
}, 800);
},
// 关闭截屏弹框(2-13页面)
closeModal() {
this.modal.closeModal()
},
// 复制微信号(2-13页面)
copyWeChat() {
if (this.data.staffinfo.wechat) {
wx.setClipboardData({
data: this.data.staffinfo.wechat,
success(res) {
// 覆盖系统默认的「内容已复制」提示
wx.showToast({
title: '微信号已复制,去粘贴搜索添加吧!',
icon: 'none',
duration: 2000
})
wx.getClipboardData({
success(res) {
console.log(res.data) // data
}
})
}
})
} else {
console.log('无微信号')
}
},
// 获取日期对应的时段(2-13页面)
getLocalLunchTime(lite_style) {
let detail = this.data.detail;
let ddateStr = new Date(detail.ddate * 1000);
let year = ddateStr.getFullYear();
let month = ddateStr.getMonth() + 1;
let day = ddateStr.getDate();
let day1 = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
App.Seller.getMealSectionByDay({
sellerid: detail.seller.id,
day: day1,
}).then(res => {
let data = res.data;
let lunchDinnerList = [];
let isMany = '0'; //0默认餐段 1多时段
if (data.length <= 3 && !data[0].ddate_solt) {
isMany = '0';
data.forEach(i => {
if (i.mname == '早餐') {
lunchDinnerList.push({
mname: "早餐",
mdate: i.mdate,
ddate_solt: 1,
})
}
if (i.mname == '午餐') {
lunchDinnerList.push({
mname: "午餐",
mdate: i.mdate,
ddate_solt: 2,
})
}
if (i.mname == '晚餐') {
lunchDinnerList.push({
mname: "晚餐",
mdate: i.mdate,
ddate_solt: 3,
})
}
})
} else {
isMany = '1';
lunchDinnerList = data;
}
let obj = lunchDinnerList.filter(i => {
return i.ddate_solt == detail.ddate_solt
})
var timeList = [];
if (obj && obj.length > 0) {
var time = obj[0].mdate.split("-");
timeList = this.computeHour(time[0], time[1], 15);
}
this.setData({
timeList,
isMany,
mealName: obj && obj.length > 0 ? (obj[0].mname || '') : '', // 多时段餐段名(新版邀请函 {餐段} 用)
})
// 页面自行实现 refreshTitleRows 时,多时段数据回来后刷新一次
if (typeof this.refreshTitleRows === 'function') this.refreshTitleRows();
// 获取转发客人卡片设置
let lite = lite_style || '3';
let liteStyle = lite.split('-');
if (liteStyle[0] == '0') {
this.setData({
imgSrc: detail.seller.seller_image
})
} else {
this.painterBtn(lite);
}
}).catch(res => {
console.log(res, '获取多时段失败');
})
},
// 点击了解更多会员优惠政策(2-13页面)
gotoFavourableList() {
let url = util.http_build_query({
sellerName: this.data.seller.name,
sellerid: this.data.seller.sid,
oid: this.data.detail.id,
types: '1'
}, '/pack-cookbook/pages/favourableList')
wx.navigateTo({
url
})
},
// 处理优惠券不可用日期数据(2-13页面)
hasConsecutiveSelect(arr, type) {
let firstTitle = null;
let lastTitle = null;
let rArr = []
let num = 0
for (let i = 0; i < arr.length; i++) {
let str = type == '1' ? arr[i].selectMor : type == '2' ? arr[i].selectNoon : type == '3' ? arr[i].selectNig : '';
if (str) {
rArr.push(arr[i].title)
num++
if (num == 1) {
firstTitle = arr[i].title
}
if (num >= 5) {
lastTitle = arr[i].title
}
if (num >= 5 && i >= (arr.length - 1)) {
let fi = rArr.findIndex((item) => {
return item == firstTitle
})
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
num = 0
}
} else {
if (num < 5) {
num = 0
firstTitle = null;
lastTitle = null;
} else {
let fi = rArr.findIndex((item) => {
return item == firstTitle
})
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
num = 0
}
}
}
return {
rArr,
lastTitle,
firstTitle
};
},
// 预览其他图片(2-13页面)
lookImgs(e) {
const url = e.currentTarget.dataset['url'];
const imgs = e.currentTarget.dataset['imgs'];
let urls = imgs ? imgs : [url]
wx.previewImage({
current: url,
urls,
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
// 使用页面:2-13页面
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
// 使用页面:2-13页面
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
// 使用页面:2-13页面
onShareAppMessage: function () {
return this.sharesetting();
},
/**
* 监听用户点击分享到朋友圈按钮的操作
*/
// 使用页面:2-13页面
onShareTimeline() {
return this.sharesetting();
},
// 生成海报(2-13页面)
painterBtn(liteStyle, timeStr) {
let style = liteStyle.split('-');
let type1 = style[0];
let type2 = style[1];
let data = this.data.detail;
let isMany = this.data.isMany;
let img = data.seller.seller_image.replace(/^http:/, "https:");
let d = data.ddate_solt;
let date1 = util.unixtoTime(data.ddate, 'MM月DD日');
let date2 = util.unixtoTime(data.ddate, 'MM/DD');
let week = ' ' + util.unixtoTime(data.ddate, '周WW');
let timeSlot1 = ' ' + (isMany == '0' ? (d == '1' ? '早上' : d == '2' ? '中午' : d == '3' ? '晚上' : '') : data.mname);
let timeSlot2 = ' ' + this.data.seller.soltName;
let time = this.data.temp_ddate ? ' ' + this.data.temp_ddate : ' ' + util.unixtoTime(data.ddate, 'HH:II')
time = timeStr ? timeStr : time;
let [day1, day2] = [...util.unixtoTime(data.ddate, '周WW')]
let section = ''
// 老样式123
if (type1 && !type2 && type1 != '4') {
section = type1 == '1' ? week + timeSlot1 : type1 == '2' ? week + time : type1 == '3' ? week + timeSlot2 : '';
}
// 新样式
if (type1 && type2) {
if (type1 == '1') {
section = type2 == '1' ? date1 + week + time + timeSlot2 : type2 == '2' ? date1 + week + timeSlot1 : type2 == '3' ? date1 + week + time : type2 == '4' ? date1 + week + timeSlot2 : '';
}
if (type1 == '2') {
section = type2 == '1' ? week + time + timeSlot2 : type2 == '2' ? week + timeSlot1 : type2 == '3' ? week + time : type2 == '4' ? week + timeSlot2 : '';
}
if (type1 == '3' || type1 == '4') {
section = type2 == '1' ? time + timeSlot2.trim() : type2 == '2' ? timeSlot1.trim() : type2 == '3' ? time.trim() : type2 == '4' ? timeSlot2.trim() : '';
}
}
if (type1 && !type2 && type1 == '4') {
section = week + timeSlot2;
}
this.setData({
wxml: canvas({
imgUrl: img || 'https://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png',
info: {
sellerName: data.seller.sellername,
date: util.unixtoTime(data.ddate, 'MM月DD日'),
time: section,
oneTableName: data.oneTableName,
},
type1,
type2,
date2,
week,
day2,
})
})
},
// 再次预订(2-13页面)
secondbook() {
wx.reportMonitor('1013', 1)
wx.redirectTo({
url: '/pages/reserve/shopHome?id=' + this.data.detail.seller.id
})
},
// 开启语音播报(2-13页面)
speech() {
var attentionAnim = wx.createAnimation({
duration: 1000,
timingFunction: 'linear',
})
this.attentionAnim = attentionAnim
this.setData({
_attentionAnim: attentionAnim,
attentionAnim: attentionAnim.export()
})
this.audioCtx = wx.createInnerAudioContext()
this.audioCtx.src = this.filename
this.audioCtx.loop = true
this.audioCtx.play()
this.audioCtx.onPlay((e) => {
this.setData({
isPlay: this.audioCtx.paused ? '2' : '1'
})
})
this.audioCtx.onPause((e) => {
this.setData({
isPlay: this.audioCtx.paused ? '2' : '1'
})
})
clearInterval(this.timers)
this.animation()
},
// 开始倒计时(2-13页面)
startCountDown() {
let that = this;
const timer = setInterval(() => {
if (that.data.countDown <= 1) {
that.closeCouponModal()
clearInterval(timer);
that.setData({
timer: null
});
} else {
that.setData({
countDown: that.data.countDown - 1
});
}
}, 1000);
this.setData({
timer
});
},
// 出现商家有礼图标,并且晃动2下(2-13页面)
startSecondAnimation() {
const animation = wx.createAnimation({
duration: 200,
timingFunction: 'ease'
});
animation.scale(1).step()
.rotate(-15).step()
.rotate(15).step()
.rotate(-15).step()
.rotate(15).step()
.rotate(0).step();
this.setData({
animationData2: animation.export()
});
},
// 暂停/继续播放(2-13页面)
stopMusic() {
if (this.data.isPlay == '2') { // 2 暂停状态
console.log("开始");
clearInterval(this.timers)
this.animation()
this.audioCtx.play() //开始
return;
}
if (this.data.isPlay == '1') { // 1 运行状态
console.log('暂停');
if (this.n % 2 != 0) {
this.n = this.n + 1;
let attentionAnim = this.data._attentionAnim;
attentionAnim.rotate(180 * this.n).step();
this.setData({
attentionAnim: attentionAnim.export(),
})
}
clearInterval(this.timers)
this.audioCtx.pause() //暂停
return;
}
},
// TTS:逐字加空格,避免数字被读成数值(如 801 → 八百零一)
toTtsSpacedText(str) {
if (!str && str !== 0) return '';
return String(str).split('').join(' ');
},
// TTS:区域名保持原读法,仅将包间名逐字拆开
buildTtsTablesText(tablesText, deskStr) {
if (!tablesText) return '';
let result = String(tablesText);
const names = String(deskStr || '')
.split('、')
.filter(Boolean)
.sort((a, b) => b.length - a.length);
if (!names.length) {
return result.replace(/\d/g, d => d + ' ').replace(/ +/g, ' ').trim();
}
names.forEach(name => {
result = result.split(name).join(this.toTtsSpacedText(name));
});
return result;
},
// 文字转语音的方法(2-13页面)
textToSpeechFun(sid, reserve) {
console.log('reservereserve-----', reserve);
let play = (reserve && reserve.swich_voice == '1') ? '1' : '0';
let voice_info = (reserve && reserve.voice_info) ? reserve.voice_info : '';
let that = this;
let data = this.data;
App.Seller.GetVoiceWelcomeConfig({
sid
}).then((json) => {
let content = '';
// GetVoiceWelcomeConfig 返回为空且 reserve 为 0 时,使用默认语音欢迎配置兜底
if (!json.data && reserve == '0') {
json.data = {
is_voice_welcome: 1,
welcome_content: "尊敬的{客人姓名+称呼},您好!\n感谢您选择{店铺名}就餐!\n您在{年月日},{餐段}的用餐,坐席位于{区域名+包间名}。\n预祝您用餐愉快,期待您的光临!",
invitee_same_as_reserver: 0,
invitee_default_content: "尊敬的贵宾,您好!感谢您来到{店铺名}就餐!\n{客人姓名+称呼}预订的{年月日},{餐段}的用餐,坐席位于{区域名+包间名}。\n预祝您用餐愉快,期待您的光临!",
is_invitee_special_enabled: 1,
invitee_special_content: "尊敬的贵宾,您好!感谢您来到{店铺名}就餐!\n{客人姓名+称呼}预订的{年月日},{餐段}的{用餐类型},坐席位于{区域名+包间名}。\n预祝您用餐愉快,期待您的光临!",
special_reserve_types: ["生日宴"]
};
}
console.log('jsondata----', json.data);
if (json.data) {
let config = json.data;
let sameAs = config.invitee_same_as_reserver; // 不区分预订人/被请人 1不一致 0一致
let isReserver = data.options.hasSellerShare == '1';
if (config.is_voice_welcome == '0') {
content = ''
} else if (sameAs == '1' || sameAs === 1) {
content = config.welcome_content || '';
} else if (sameAs == '0' || sameAs === 0) {
if (isReserver) {
content = config.welcome_content || '';
} else {
let specialEnabled = config.is_invitee_special_enabled == '1'; //为1被请人播特殊模板
let reserveType = data.detail.reserve_type || '';
let specialTypes = config.special_reserve_types || [];
let isSpecial = specialEnabled && specialTypes.indexOf(reserveType) > -1;
content = isSpecial ? (config.invitee_special_content || '') : (config.invitee_default_content || '');
}
}
} else if (play == '1') {
content = voice_info;
}
console.log('content---', content);
if (!content) {
this.setData({
newStr: '',
})
return;
}
this.setData({
isPlay: '1',
})
data.detail.rname = data.detail.rname.trim()
let str = data.detail.sex == 1 ? '先生' : data.detail.sex == 2 ? '女士' : data.detail.sex == 4 ? '贵宾' : '';
let resultString = this.toTtsSpacedText(data.seller.deskStr || '');
let tablesTextForTts = this.buildTtsTablesText(data.seller.tablesText, data.seller.deskStr);
const replacements = {
"{店铺名}": data.seller.name,
"{年月日}": data.seller.yearMonthDay,
"{月日}": data.seller.yearMonth,
"{餐段}": data.seller.soltName,
"{就餐时间}": data.seller.dateStr + data.seller.dateStrDivide,
"{包间名}": resultString,
"{区域名+包间名}": tablesTextForTts,
"{经理名字}": data.staffinfo.name,
"{客人姓名+称呼}": data.detail.rname ? (data.detail.rname + str) : str == '贵宾' ? '贵宾' : '',
"{预订日期}": data.seller.yearMonthDay,
"{桌位}": resultString,
"{客人姓名}": data.detail.rname ? data.detail.rname : '',
"{称呼}": data.detail.sex == 1 ? '先生' : data.detail.sex == 2 ? '女士' : data.detail.sex == 3 ? '公司' : data.detail.sex == 4 ? '贵宾' : '',
"{客人姓氏}": data.detail.rname ? data.detail.rname : '',
"{性别}": data.detail.sex == 1 ? '先生' : data.detail.sex == 2 ? '女士' : data.detail.sex == 3 ? '公司' : data.detail.sex == 4 ? '贵宾' : '',
"{用餐类型}": data.detail.reserve_type || '',
};
let newStr = content.replace(/{店铺名}|{客人姓氏}|{性别}|{预订日期}|{桌位}|{年月日}|{月日}|{餐段}|{就餐时间}|{包间名}|{区域名\+包间名}|{经理名字}|{客人姓名\+称呼}|{客人姓名}|{称呼}|{用餐类型}/g, function (matched) {
return replacements[matched];
});
console.log('newStr---', newStr);
this.setData({
newStr,
})
plugin.textToSpeech({
lang: "zh_CN",
tts: true,
content: newStr,
success: function (res) {
that.filename = res.filename
that.speech()
},
fail: function (res) {
console.log("fail tts", res)
}
})
}).catch((err) => {
console.log('GetVoiceWelcomeConfig请求失败', err);
this.setData({
newStr: '',
})
})
},
// 跳转登录页(2-12页面)
gotoLogin(event, type) {
const types = type ? type : event.currentTarget.dataset.types;
let params = {
types, //1邀请函领券 2赴约
id: this.id,
}
if (types == '1') params.couponArr = JSON.stringify(this.data.couponArr)
let url = util.http_build_query(params, '/pages/customer/login')
wx.navigateTo({
url
})
},
// 获取是否点击过赴约(2-12页面)
getreal() {
App.Reserve.GetIsRelaSuccess({
openid: getApp().openid,
rid: this.id,
}).then((json) => {
if (json.ret == 200) {
console.log('是否点击赴约=-----', json.data);
this.setData({
isShowBtn: !json.data, //返回false 代表没有点赴约
})
if (typeof this.refreshActionBtn === 'function') this.refreshActionBtn();
}
})
},
// 领券-获取code、手机号(2-12页面)
getPhoneNumberCouponFun(e) {
if (e.detail && e.detail.code && !this.data.purePhoneNumber) {
App.Wechat.GetUserPhoneNumber({
code: e.detail.code,
}).then(res => {
if (res.ret == 200 && res.data && res.data.phone_info && res.data.phone_info.purePhoneNumber) {
this.bindUserPhoneFun(res.data.phone_info.purePhoneNumber)
} else {
console.log('点了拒绝1');
this.couponModal.closeModal()
this.gotoLogin('', '1')
}
})
} else {
console.log('点了拒绝2');
this.couponModal.closeModal()
this.gotoLogin('', '1')
}
},
// 用户绑定手机号(2-12页面)
bindUserPhoneFun(purePhoneNumber) {
App.Wechat.BindUserPhone({
phone: purePhoneNumber,
openid: getApp().openid
}).then(res => {
if (res.ret == 200) {
this.setData({
purePhoneNumber
})
if (typeof this.refreshActionBtn === 'function') this.refreshActionBtn();
this.setcouponFun()
}
})
},
// 获取code、手机号(2-12页面)
getPhoneNumberFun(e) {
console.log('获取code', e.detail);
if (e.detail && e.detail.code) {
App.Wechat.GetUserPhoneNumber({
code: e.detail.code,
}).then(res => {
if (res.ret == 200 && res.data && res.data.phone_info && res.data.phone_info.purePhoneNumber) {
this.setData({
purePhoneNumber: res.data.phone_info.purePhoneNumber,
})
this.bindUserPhoneFun(res.data.phone_info.purePhoneNumber)
this.getUserRechargeInfo(res.data.phone_info.purePhoneNumber)
} else {
util.toast('手机号获取失败!', 'none')
}
})
}
},
// 获取用户在商家的账户余额(2-12页面)
getUserRechargeInfo(phone) {
App.Activity.GetRechargeBalanceByOpenid({
openid: getApp().openid,
phone,
sellerid: this.data.seller.sid,
}).then((json) => {
if (json.ret == 200) {
let data = json.data;
if (!data) {
this.createInfoFun(phone)
console.log('用户在商家没有账号');
}
}
})
},
// 如果该用户不存在账户 新增用户在商家的账户信息(2-12页面)
createInfoFun(phone) {
let params = {
openid: getApp().openid,
sellerid: this.data.seller.sid,
phone
}
App.Activity.CreateCustomerConsumeSeller(params).then(res => {
if (res.ret == 200) {
console.log('新增用户在商家的账户信息----', res);
}
})
},
// 赴约手机号传参(2-12页面)
confirmed() {
let userinfo = JSON.stringify({
openid: getApp().openid,
avatar: this.data.wxAvatar,
nickname: this.data.wxNickname,
})
App.Reserve.SetRelaSuccess({
rid: this.id,
openid: getApp().openid,
is_agree: 1,
inviting_phone: this.data.purePhoneNumber,
userinfo
}).then(res => {
if (res.ret == 200) {
util.toast('赴约成功', 'none', 2500)
this.setData({
isShowBtn: false,
})
if (typeof this.refreshActionBtn === 'function') this.refreshActionBtn();
}
})
},
// 检测用户是否绑定手机号(2-12页面)
getCheckUserHavePhone() {
App.Wechat.CheckUserHavePhone({
openid: getApp().openid,
}).then((json) => {
if (json.ret == 200) {
let data = json.data;
if (data) {
this.setData({
purePhoneNumber: data.phone,
wxNickname: data.nickname ? data.nickname : '',
wxAvatar: data.headimgurl ? data.headimgurl : '',
})
if (typeof this.refreshActionBtn === 'function') this.refreshActionBtn();
}
}
})
},
// 打开送券弹框(2-13页面)
showCouponModal() {
this.couponModal.showModal()
this.setData({
countDown: 5,
})
if (this.data.timer) {
clearInterval(this.data.timer);
}
this.startCountDown();
},
// 跳转到商家入驻页(2-13页面)
gotoJoinSeller() {
wx.navigateTo({
url: util.http_build_query({
laiyuan: '邀请函'
}, '/pages/customer/joinSeller')
})
},
// 导航(2-13页面)
looklocation: function () {
wx.reportMonitor('1015', 1)
wx.openLocation({
latitude: Number(this.data.seller.lat),
longitude: Number(this.data.seller.long),
scale: 17,
address: this.data.seller.addr,
success: function (res) {
console.log(res)
}
})
},
// 获取商家版本,不是超能版或者没有开通对应模块,不显示(2-13页面)
getSellerVersionFun(sellerid) {
App.SellerVersion.GetSellerVersion({
sellerid
}).then((res) => {
let data = res.data;
console.log('版本列表', data);
if (data && data.length > 0) {
data.sort((a, b) => b.cdate * 1 - a.cdate * 1);
// 获取店铺当前版本 (cdate最大最后一个充入的 && 当前时间有效 && 当前版本)
let obj = data.find(item => item.vtype == 1 || item.vtype == 2 || item.vtype == 4);
console.log('当前版本', {
...obj
});
// 提前点餐功能:超能版 || 有提前点餐模块
const hasValueOrder = obj.vtype == '1' || data.some(item => item.vid == '6');
// 优惠券功能:超能版 || 高级版 || 有优惠券模块
const hasValueCertificate = obj.vtype == '1' || obj.vtype == '4' || data.some(item => item.vid == '8');
// 充值功能:超能版 || 有充值模块
const hasValueRecharge = obj.vtype == '1' || data.some(item => item.vid == '9');
// 播报功能:超能版 || 标准版 || 标准版首年 || 高级版
const hasValueBroadcast = obj.vtype == '1' || obj.vid == '4' || obj.vid == '13' || obj.vtype == '4';
this.setData({
hasValueOrder,
hasValueCertificate,
hasValueRecharge,
hasValueBroadcast,
})
}
})
},
// 通过预订ID查收定金详情(2-13页面)
getPaymentStatus() {
App.Reserve.GetReserveDepositByRid({
rid: this.data.options.id
}).then(res => {
if (res.ret == 200 && res.data && res.data.length > 0) {
let data = res.data[0];
let paymentStatus = data.trade_state == 'SUCCESS' ? '1' : '0';
let options = this.data.options
this.setData({
paymentId: data.id,
paymentStatus,
isPaymenBtn: options.isOrder != '1' && data.id && paymentStatus == '0' && options.hasSellerShare == '1' && options.isDeposit == '1',
})
if (typeof this.refreshActionBtn === 'function') this.refreshActionBtn();
}
})
},
// 点击支付定金(2-13页面)
paymentFun() {
let that = this;
let openid = getApp().openid;
if (!openid) return wx.showToast({
title: '请在小程序中支付订金!',
icon: 'none',
})
App.PayOnline.CombineTransactionsByDeposit({
id: this.data.paymentId,
openid,
}).then(res => {
if (res.ret == 200) {
wx.requestPayment({
timeStamp: res.data.timeStamp + '',
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success(ress) {
console.log('微信支付结果', ress);
if (ress.errMsg == 'requestPayment:ok') {
console.log('支付成功', ress);
that.setData({
paymentStatus: '1',
toastBool: true,
toastText: '支付成功'
})
that.hideToast();
return
}
console.log('支付失败1', ress);
that.setData({
toastBool: true,
toastText: '支付失败,请重新支付'
})
that.hideToast();
},
fail(ress) {
console.log('支付失败2', ress);
that.setData({
toastBool: true,
toastText: '支付失败,请重新支付'
})
that.hideToast();
},
})
} else {
wx.showToast({
title: res.msg,
icon: 'none',
})
}
})
},
// 关闭支付失败或者成功弹框(2-13页面)
hideToast() {
setTimeout(() => {
this.setData({
toastBool: false
})
}, 1500)
},
// 使用页面:(2-13页面)
onImgOK(e) {
this.setData({
imgSrc: e.detail.path
})
console.log('海报生成成功', this.data.imgSrc);
},
// 设置虚拟到店时间(2-13页面)
bindPickerChange: function (e) {
let index = e.detail.value
let temp_ddate = this.data.timeList[index]
this.setData({
temp_ddate
})
let detailInfo = this.data.detail;
const reserveDate = new Date(detailInfo.ddate * 1000);
let reserveTime =
reserveDate.getFullYear() +
"-" +
(reserveDate.getMonth() + 1) +
"-" +
reserveDate.getDate();
let times = this.getNewDate(reserveTime + " " + temp_ddate).getTime() / 1000
App.Reserve.SetReserveTempDdate({
rid: this.id,
temp_ddate: times,
}).then(res => {
if (res.ret == 200) {
let lite_style = this.data.lite_style
lite_style = lite_style || '3';
let style = lite_style.split('-');
let type1 = style[0];
let type2 = style[1];
if ((type1 == '2' && !type2) || (type2 && (type2 == '1' || type2 == '3') || (type1 == '4' && !type2))) {
let time = temp_ddate || this.data.timeList[index]
this.painterBtn(
lite_style,
time
);
}
}
})
},
// ios 部分机型不兼容new Date() 转换字符串(2-13页面)
getNewDate(data) {
if (typeof data === 'string') {
let arr = data.split(/[- : \/]/)
if (arr[1] !== undefined || arr[1] !== null) {
arr[1] = arr[1] - 1
}
return new Date(...arr)
}
return new Date(data || new Date())
},
//根据起始时间(获取时间时间段)(2-13页面)
computeHour(time1, time2, interval) {
//time1 开始时间 time2结束时间 interval间隔时长
function getTimeList(time1, time2, interval) {
var timeList = [];
time1 = time1.split(":");
time2 = time2.split(":");
time1 = new Date(0, 0, 0, time1[0], time1[1], 0);
time2 = new Date(0, 0, 0, time2[0], time2[1], 0);
interval = interval * 60 * 1000;
while (time1 <= time2) {
timeList.push(time1.format("hh:mm"));
time1 = new Date(time1.getTime() + interval);
}
return timeList;
}
Date.prototype.format = function (format) {
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
S: this.getMilliseconds(),
};
if (/(y+)/.test(format))
format = format.replace(
RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length)
);
for (var k in date)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(
RegExp.$1,
RegExp.$1.length == 1 ?
date[k] :
("00" + date[k]).substr(("" + date[k]).length)
);
return format;
};
return getTimeList(time1, time2, interval);
},
// 获取自定义图文内容(2-13页面)
getText() {
App.Reserve.GetReserveImgText({
rid: this.data.options.id
}).then(res => {
if (res.ret == 200 && res.data) {
let data = res.data;
let content = util.determine(data.content)
console.log('contentcontentcontent', content);
this.setData({
reserveData: {
title: data.title || '',
content,
}
})
}
})
},
// 修改detail数据(2-13页面)
formatDatail(detail, dateSmart) {
detail.rdateStr = dateSmart;
detail.tableFirst = detail.tables[0].name;
if (detail.tables.length > 1) {
detail.tableSubInfo = '等' + (detail.tables.length) + '个' +
(detail.tables[0].tid == 2 ? '包间' : '');
}
detail.rname = detail.rname.trim()
if (detail.rname && detail.sex != 3) {
let sexStr = detail.sex == 1 ? '先生' : detail.sex == 2 ? '女士' : detail.sex == 4 ? '贵宾' : '';
let str = this.data.options.showSex == '2' ? '' : sexStr;
detail.rnameStr = detail.rname + str
} else if (!detail.rname && detail.sex == 4) {
detail.rnameStr = '贵宾'
} else {
detail.rnameStr = detail.rname
}
detail.eatStr = '邀请您共进晚餐';
let hi = util.unixtoTime(detail.ddate, 'HHII');
if (hi < '10:00') {
detail.eatStr = '邀请您共进早餐';
} else if (hi < '15:00') {
detail.eatStr = '邀请您共进午餐';
}
return detail;
},
// 点击商家有礼(2-13页面)
gotoSellerGift(e) {
this.couponModal.closeModal()
const form = e.currentTarget.dataset['form'];
let url = util.http_build_query({
id: this.data.detail.id,
hasSellerShare: this.data.options.hasSellerShare,
form
}, '/pages/reserve/sellerGift')
wx.navigateTo({
url
})
},
// 计算免费券有效期的起始、结束日期(2-13页面)
setTimeRange(cdate, startOffset, endOffset) {
console.log(cdate, startOffset, endOffset);
const startDate = new Date((cdate + startOffset * 86400) * 1000);
startDate.setHours(0, 0, 0, 0);
const useStime = util.unixtoTime(startDate.getTime() / 1000, 'YYYY-MM-DD');
const endDate = new Date((cdate + endOffset * 86400) * 1000);
endDate.setHours(23, 59, 59, 0);
const useEtime = util.unixtoTime(endDate.getTime() / 1000, 'YYYY-MM-DD');
let useEtimeNum = endDate.getTime() / 1000;
return {
useStime,
useEtime,
useEtimeNum
};
},
// 底部操作栏状态计算(2~12 通用;13 号页在页面内覆盖)
refreshActionBtn(extraData) {
// 优先用调用方传入的最新数据(如刚setData的obj),避免setData异步/时序导致读到旧值;不传则读this.data
const data = extraData ? Object.assign({}, this.data, extraData) : this.data;
const {
detail,
options,
isMoreBtn,
isPaymenBtn,
isShareItem,
isShowBtn,
seller,
reserveOpenid,
openid,
wxNickname,
purePhoneNumber
} = data;
const notCancel = detail.status != '4';
const isOver = options.isOrder == '1';
const A = !!isMoreBtn;
const C = !A && !!seller.phone;
const D = notCancel && !!isPaymenBtn;
const E = notCancel && !!isShareItem;
const isOwner = options.hasSellerShare == '1';
const Y = reserveOpenid != openid && !isOver && !!isShowBtn;
const X = Y && !isOwner && options.isMeeting == '1';
const authorized = !!(wxNickname && purePhoneNumber);
this.setData({
barShow: !!(A || isOver || C || D || E),
showMoreOnline: A,
showMoreCall: C,
canPay: D,
canShare: E,
isOver,
isOwner,
canMeet: X,
needLogin: !authorized,
guestShareCls: Y ? 'paymenBtn paymenBtn1' : 'shareItem shareItem1',
threeBtnMore: (D || X) && (E || isOver) ? 'threeBtn' : '',
threeBtnCall: D && (E || isOver) ? 'threeBtn' : '',
threeBtnPay: (A || C) && (E || isOver) ? 'threeBtn' : '',
})
},
// 模块文字、轮播图数据重组(停车、餐厅介绍、菜品、主厨)(10-12页面)
processInfo(intel, type) {
let imgs = [];
intel.textInfo = '';
intel.imgsInfo = [];
intel.videoImgsInfo = [];
if (type == '1' && intel.is_introduce_all == '1') {
if (intel.swich_park == '1' && (intel.park_info || intel.park_info_images)) {
intel.textInfo = intel.park_info;
imgs = intel.park_info_images
}
}
if (type == '2') {
imgs = intel.images && intel.images.length > 0 && (!intel.is_images || intel.is_images !== '0') ? intel.images : [];
intel.textInfo = (intel.introduce && (!intel.is_introduce || intel.is_introduce !== '0')) ? intel.introduce : '';
}
if (type == '3') {
imgs = intel.images || []
intel.textInfo = '';
}
if (type == '4') {
imgs = ((!intel.is_images || intel.is_images != '0') && intel.image) ? intel.image : []
intel.textInfo = (intel.introduce && (!intel.is_introduce || intel.is_introduce != '0')) ? intel.introduce : '';
}
intel.imgsInfo = imgs;
if (intel.content && intel.content.length > 0 && intel.is_introduce_all == '1') {
intel.textInfo = intel.content.filter(item => item.type == "2").map(item => item.content).join('\n');
intel.imgsInfo = intel.content.filter(item => item.type == "1" && item.content).map(item => item.content);
intel.videosInfo = intel.content.filter(item => (item.type == "3" && item.content));
}
return intel
},
// 选中充值活动(11-12页面)
checkRechargeData(e) {
let id = e.currentTarget.dataset['id'];
let obj = this.data.recharge_data.filter(item => {
return item.id == id
})
if (obj && obj.length > 0) {
this.setData({
activeData: obj[0]
})
}
},
};