success_result.js
45.4 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
/*
* @Author: abson
* @Date: 2022-02-16 15:36:47
* @LastEditTime: 2022-02-28 16:01:07
* @LastEditors: Please set LastEditors
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \MShopWeApp\packageB\pages\AI-test-skin\success_result\success_result.js
*/
// packageB/pages/AI-test-skin/success_result/success_result.js
const app = getApp();
const request = app.request;
const os = app.globalData;
const setting = os.setting;
const ut = require('../../../../utils/util');
//毛孔
const acne = require('acne/acne');
const blackhead = require('blackhead/blackhead');
const dark = require('dark/dark');
const pore = require('pore/pore');
const speckle = require('speckle/speckle');
const wrinkle = require('wrinkle/wrinkle');
const sensitive = require('sensitive/sensitive')
Page({
/**
* 页面的初始数据
*/
data: {
// tab: [{ id: 'zong_he', name: '综合肤质' }, { id: 'mao_kong', name: '毛孔' }, { id: 'hei_tou', name: '黑头' }, { id: 'se_ban', name: '色斑' }, { id: 'zhou_wen', name: '皱纹' }, { id: 'hei_yan_quan', name: '黑眼圈' }, { id: 'cuo_chuang', name: '痤疮' }, { id: 'min_gan_du', name: '敏感度' }],
zhouwen_arr: [{ id: 1, name: '全部皱纹' }, { id: 2, name: '抬头纹' }, { id: 3, name: '川字纹' }, { id: 4, name: '眼周细纹' }, { id: 5, name: '鱼尾纹' }, { id: 6, name: '法令纹' }, { id: 7, name: '口周纹' }],
cuochuang_arr: [{ id: 1, name: '全部痤疮' }, { id: 2, name: '粉刺 ' }, { id: 3, name: '痘印 ' }, { id: 4, name: '脓包' }, { id: 5, name: '结节' }],
zhouwen_arr1: [{ id: 1, name: '皱纹/细纹', des: '是指皮肤受到外界环境影响,形成游离自由基,自由基破坏正常细胞膜组织内的胶原蛋白、活性物质,氧化细胞,或缺水而形成的小细纹,继而严重形成皱纹', sign: 'zhou1', sign1: 'zhou2' }, { id: 2, name: '抬头皱纹/抬头细纹', des: '位于额头的皱纹、细纹。形成原因因人而异,后天因素是比较少的。-般多为横纹, 竖纹较少见。', sign: 'zhou3', sign1: 'zhou4' }, { id: 3, name: '眼部皱纹/眼部细纹', des: '眼部皱纹、细纹一般位于下眼睑部位,多见于下脸内1/3处。', sign: 'zhou5', sign1: 'zhou6' }, { id: 4, name: '鱼尾纹', des: '眼部皱纹的一种,是在人两侧外眼角和登角之间出现的皱纹,其纹路与鱼尾巴上的纹路很相似,故被形象地称为鱼尾纹。', sign: 'zhou7', sign1: 'zhou8' }, { id: 5, name: '眉间纹', des: '又叫川字纹,皱眉纹,是面部的一种正常的表情纹,随着年龄的增长,面部的皱纹会逐渐加深,双眉之间逐渐形成了较深的皱折,会使人看起来总是愁眉不展。', sign: 'zhou9', sign1: 'zhou10' }, { id: 6, name: '泪沟', des: '泪沟是指由内眼角开始出现在下眼睑靠鼻侧的两条凹沟,是由于眼眶隔膜下缘的软组织萎缩、下垂而生成的。', sign: 'zhou11', sign1: 'zhou12' }, { id: 7, name: '法令纹', des: '法令纹是位于鼻翼边延伸而下的两道纹路,是典型的皮肤组织老化、造成肌肤表面凹陷的现象。', sign: 'zhou15', sign1: 'zhou16' }, { id: 8, name: '口角纹', des: '口角纹又称木偶纹、括号纹,位于嘴角延伸而下的两道纹路,是表情肌、重力和遗传基因等几方面因素综合形成的。', sign: 'zhou13', sign1: 'zhou14' }],
cuochuang_arr1: [{ id: 1, name: '痘印,痘坑', des: '痤疮消退后留下的痕迹,- 般包括黑色痘印,红色痘印,凹洞性痘坑,增生性凸疤。', sign: 'cuo1', sign1: 'cuo2' }, { id: 2, name: '粉刺', des: '粉刺也称为白头,是毛囊漏斗部被角质层细胞堆积、堵塞,角化物质和皮脂充塞其中,形成白色丘疹,表面有表皮覆盖,与外界不相通,成为封闭式粉刺。(痤疮I级)', sign: 'cuo3', sign1: 'cuo4' }, { id: 3, name: '丘疹', des: '丘疹性痤疮是由皮损导致炎性弓|起的小米至豌豆大的坚硬的小丘疹,呈淡红色至深红色。丘疹中央可有一个黑头粉刺或顶端未变黑的皮脂栓。(痤疮II级)', sign: 'cuo5', sign1: 'cuo6' }, { id: 4, name: '结节囊肿', des: '表现为蚕豆至指甲大的炎性结节或囊肿,为重度痤疮,严重者可继发化脓感染、破溃流出血脓,后形成窦道及瘢痕。触摸有波动感。若面部相邻长着多个囊肿,可能通过皮下的“窦道"“暗通,可能需要手术解决。(痤疮IV级)', sign: 'cuo7', sign1: 'cuo8' }],
heitanquan_arr: [{ id: 1, name: '综合情况' }, { id: 2, name: '左眼' }, { id: 3, name: '右眼' }],
heitanquan_arr1: [{ id: 1, name: '色素性黑眼圈', des: '呈茶褐色,是因眼裂向外眼角的延伸段有色素沉着或因先天或外来刺激导致眼周肤色黯沉。', sign: 'hei1', sign1: 'hei2' }, { id: 2, name: '血管性黑眼圈', des: '呈青紫色,由于眼周血液循环不良,下眼脸处皮肤与皮下脂肪变薄,皮下血管透出颜色形成的。', sign: 'hei3', sign1: 'hei4' }, { id: 3, name: '阴影型黑眼圈', des: '表现为眼袋膨出、泪沟凹陷。由于年龄的增长,眼周皮肤肌肉都会变得松弛,脂肪量变化而引起。', sign: 'hei5', sign1: 'hei6' }],
currentIndex: 0,
scroll_index: 0,
yiwen_index: 0,
sex: 'female', //female女 male男
tab_id: 'zong_he',
iurl: setting.imghost,
showDialog: false,
yanjing: true, //显示皮肤问题
img_scale: true, //问题标注放大图片
heightRecord: [],
img_scale_icon: true,
show_problem: 1, //问题标注显示问题
img_scale: 1, //缩放问题
sex: '',
is_esys_show: 0, //是不是显示眼睛
scroll_id: 1, //初始为1
wrinkle_num1: 0, //抬头纹
wrinkle_num2: 0, //川字纹
wrinkle_num3: 0, //眼周细纹
wrinkle_num4: 0, //鱼尾纹
wrinkle_num5: 0, //法令纹
wrinkle_num6: 0, //口周纹
yiwen_type: 0, //1皱纹 2黑眼圈 3痤疮
acne_num1: 0, //粉刺
acne_num2: 0, //痘印
acne_num3: 0, //脓包
acne_num4: 0, //结节
},
onReady: function () {
//用异步的获取比较准一点
wx.getSystemInfo({
success(res) {
console.log(111);
console.log(res.windowWidth);
console.log(res.windowHeight);
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var th = this;
//初始化一下,获取商品的价格
this.init();
//var face_result=getApp().globalData.face_result;
//var face_data=face_result.face_list[0];
var id=options.id;
var first_leader = options.first_leader;
if (id == undefined || id == null || id == "") {
var gid_str = decodeURIComponent(options.scene);
gid_str = gid_str.split("_");
id=gid_str[0];
if (gid_str.length > 1) {
first_leader = gid_str[1];
}
}
this.data.id=id;
if (first_leader) {
console.log("log---".first_leader);
getApp().globalData.first_leader = first_leader;
//调用接口判断是不是会员
getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
if (res.data.code == 0) {
getApp().globalData.guide_id = res.data.data.id;
}
})
}
//用异步的获取比较准一点
wx.getSystemInfo({
success(res) {
//计算图片要显示的大小
th.data.cWidth = res.windowWidth;
th.data.cHeight = res.windowHeight;
console.log(222);
console.log(res.windowWidth);
console.log(res.windowHeight);
th.data.face_height = th.data.cHeight * 0.8 * 0.75;
var bi1 = (th.data.cHeight * 0.8 * 0.8) / (th.data.cWidth * 0.8);
th.get_data(function (json, json1, img) {
//-- 数据先存着 --
var face_data = th.data.face_data = json.face_list[0];
var face_data1 = th.data.face_data1 = json1.face_list[0];
var sex = face_data1.gender.type;
//痤疮数
var acne_num = face_data.acnespotmole.acne_num;
//色斑数
var speckle_num = face_data.acnespotmole.speckle_num;
//皱纹数
var wrinkle_num = face_data.wrinkle.wrinkle_num;
//黑头数
var blackhead_num = face_data.blackheadpore.blackhead_num;
//毛孔数
var pore_num = face_data.blackheadpore.pore_num;
//黑眼圈的严重程度
var dark_type = face_data.eyesattr.dark_circle_left_type.length > 0 ? face_data.eyesattr.dark_circle_left_type[0] : -1;
var dark_type1 = face_data.eyesattr.dark_circle_right_type.length > 0 ? face_data.eyesattr.dark_circle_right_type[0] : -1;
var dk_type1 = dark_type;
var dk_type2 = dark_type1;
if (dark_type1 > dark_type) {
dark_type = dark_type1;
}
var skin_sensitive_check = parseInt(face_data.skinquality.skin_sensitive_check[0]);
var skin_dryoil_check = face_data.skinquality.skin_dryoil_check;
var location = face_data.location;
var bili = th.data.face_height * 0.76 / location.height;
//获取眼睛的画图比例
var eye_data1 = face_data1.landmark150.eye_left_corner_right;
var eye_data2 = face_data1.landmark150.eye_left_corner_left;
var eye_data3 = face_data1.landmark150.eye_right_corner_right;
var hei1 = Math.abs(eye_data1.x - eye_data2.x);
var bili_eye = th.data.face_height * 0.56 / hei1;
var eye_top = eye_data1.y - hei1 / 2
var eye_left1 = eye_data1.x - hei1 / 6;
var eye_left2 = eye_data3.x - hei1 / 6;
var skin_dryoil_check_type = 0;//干性
var skin_dryoil_check_arr = []
for (let i in skin_dryoil_check) {
let item = skin_dryoil_check[i];
if (item != '1' && skin_dryoil_check_arr.indexOf(item) == -1) {
skin_dryoil_check_arr.push(item);
}
}
//皮肤干油性的判断
if (skin_dryoil_check_arr.length == 0) skin_dryoil_check_type = 1;
else if (skin_dryoil_check_arr.length == 1) skin_dryoil_check_type = parseInt(skin_dryoil_check_arr[0]);
else skin_dryoil_check_type = 3;
var wrinkle_types = face_data.wrinkle.wrinkle_types;
var w_arr = wrinkle_types.filter(function (e) {
return e == 1;
})
th.data.wrinkle_num1 = w_arr.length;
//皱纹的数量的统计
w_arr = wrinkle_types.filter(function (e) {
return e == 2;
})
th.data.wrinkle_num2 = w_arr.length;
w_arr = wrinkle_types.filter(function (e) {
return e == 3;
})
th.data.wrinkle_num3 = w_arr.length;
w_arr = wrinkle_types.filter(function (e) {
return e == 4;
})
th.data.wrinkle_num4 = w_arr.length;
w_arr = wrinkle_types.filter(function (e) {
return e == 5;
})
th.data.wrinkle_num5 = w_arr.length;
w_arr = wrinkle_types.filter(function (e) {
return e == 6;
})
th.data.wrinkle_num6 = w_arr.length;
//痘痘的不同的统计
var acne_list = face_data.acnespotmole.acne_list;
var a_arr = acne_list.filter(function (e) {
return e.type == 0;
})
th.data.acne_num1 = a_arr.length;
a_arr = acne_list.filter(function (e) {
return e.type == 1;
})
th.data.acne_num2 = a_arr.length;
a_arr = acne_list.filter(function (e) {
return e.type == 2;
})
th.data.acne_num3 = a_arr.length;
a_arr = acne_list.filter(function (e) {
return e.type == 3;
})
th.data.acne_num4 = a_arr.length;
let tab_arr = [{ id: 'zong_he', name: '综合肤质' }];
if (pore_num) {
tab_arr.push({ id: 'mao_kong', name: '毛孔' });
}
if (blackhead_num) {
tab_arr.push({ id: 'hei_tou', name: '黑头' });
}
if (speckle_num) {
tab_arr.push({ id: 'se_ban', name: '色斑' });
}
if (wrinkle_num) {
tab_arr.push({ id: 'zhou_wen', name: '皱纹' });
}
if (dark_type > -1) {
tab_arr.push({ id: 'hei_yan_quan', name: '黑眼圈' });
}
if (acne_num) {
tab_arr.push({ id: 'cuo_chuang', name: '痤疮' });
}
tab_arr.push({ id: 'min_gan_du', name: '敏感度' });
th.setData({
acne_num: acne_num,
speckle_num: speckle_num,
wrinkle_num: wrinkle_num,
wrinkle_types: wrinkle_types, //皱纹类型
blackhead_num: blackhead_num,
pore_num: pore_num,
dark_type: dark_type,
dark_typ1: dk_type1,
dark_type2: dk_type2,
skin_sensitive_check: skin_sensitive_check,
skin_dryoil_check: skin_dryoil_check,
skin_dryoil_check_type: skin_dryoil_check_type,
face_img: img,
m_top: (location.top - location.height / 3) * bili,
m_left: Math.abs(th.data.cWidth * 0.8 - (location.width + location.left * 2) * bili) / 2,
bili: bili,
bili_eye: bili_eye,
sex: sex,
tab: tab_arr,
skin_dryoil_check_type: skin_dryoil_check_type,
eye_top: eye_top * bili_eye,
eye_left1: eye_left1 * bili_eye,
eye_left2: eye_left2 * bili_eye,
wrinkle_num1: th.data.wrinkle_num1, //抬头纹
wrinkle_num2: th.data.wrinkle_num2, //川字纹
wrinkle_num3: th.data.wrinkle_num3, //眼周细纹
wrinkle_num4: th.data.wrinkle_num4, //鱼尾纹
wrinkle_num5: th.data.wrinkle_num5, //法令纹
wrinkle_num6: th.data.wrinkle_num6, //口周纹
acne_num1: th.data.acne_num1, //粉刺
acne_num2: th.data.acne_num2, //痘印
acne_num3: th.data.acne_num3, //脓包
acne_num4: th.data.acne_num4, //结节
})
var sort = 1;
//-- 调用毛孔的推荐函数 --
if (pore_num > 0)
pore.get_goods(th, setting.stoid, sort++);
//-- 调用黑头的推荐函数 --
if (blackhead_num > 0)
blackhead.get_goods(th, setting.stoid, sort++);
//-- 调用色斑的推荐函数 --
if (speckle_num > 0)
speckle.get_goods(th, setting.stoid, sort++);
//-- 调用皱纹的推荐函数 --
if (wrinkle_num > 0)
wrinkle.get_goods(th, setting.stoid, sort++);
//-- 黑眼圈 --
if (dark_type > -1)
dark.get_goods(th, setting.stoid, sort++);
//-- 黑眼圈 --
if (acne_num > -0)
acne.get_goods(th, setting.stoid, sort++);
sensitive.get_goods(th, setting.stoid, sort++);
//-- 获取一下分享要用的图片 --
th.set_share_img();
acne.get_goods(th, setting.stoid);
// let { heightRecord, tab } = th.data;
// tab.forEach(item => {
// console.log(2);
// var query = th.createSelectorQuery();
// let class_name = `.${item['id']}`;
// query.select(class_name).boundingClientRect(function (rect) {
// // let ratio = 750 / rect.width;
// let height = parseInt(rect.height); //加上导航栏50px
// heightRecord.push(height);
// // item['top'] = top;
// }).exec();
// });
// heightRecord.sort((a, b) => {
// return a - b;
// });
// th.setData({
// heightRecord,
// })
// setTimeout(() => {
// heightRecord.sort((a, b) => {
// return a - b;
// })
// let new_arr = [];
// if (heightRecord.length > 0) {
// heightRecord.reduce((pre, cur) => {
// let sum = pre + cur;
// new_arr.push(sum);
// return sum;
// })
// }
// th.setData({
// heightRecord:new_arr,
// })
// },1000)
})
}
})
},
//-- 初始等级卡 --
init: function () {
var th = this;
if (!getApp().globalData.user_id) return false;
getApp().request.get("/api/weshop/users/get/" + setting.stoid + "/" + getApp().globalData.user_id, {
isShowLoading: false,
success: function (e) {
if (e.data.code == 0 && e.data && e.data.data) {
getApp().globalData.userInfo = e.data.data;
getApp().getConfig2(function (e) {
var swithc_list = e.switch_list;
var sw_arr = JSON.parse(swithc_list);
//---如果后台有开等级卡的开关---
if (sw_arr.rank_switch && sw_arr.rank_switch == "2") {
th.setData({
rank_switch: true
});
//---回调卡的列表---
th.getPlusCardType(function (ob) {
th.setData({
card_list: ob.card_list
});
var ti = setInterval(function () {
var user = getApp().globalData.userInfo;
if (!user) return false;
clearInterval(ti);
if (user.card_field && user['card_expiredate']) {
var str = user['card_expiredate'].replace(/-/g, '/');
var end = new Date(str);
end = Date.parse(end) / 1000;
var now = ut.gettimestamp();
//--- 判断是等级会员,且在有效期范围内 ---
if (user.card_field && now < end) {
var card_name = ob.name_map.get(user.card_field);
if (card_name.length > 4) card_name = card_name.substring(0, 8);
th.setData({
card_field: user.card_field,
card_name: card_name,
card_list: ob.card_list
});
}
}
}, 500)
})
}
})
}
}
})
},
//-- 获取json数据 --
get_data: function (func) {
var url = "/api/weshop/face/storeSkinface/get/" + setting.stoid + "/" + this.data.id;
getApp().request.promiseGet(url, {}).then(res => {
if (res.data.code == 0) {
var json = JSON.parse(res.data.data.resultjson);
var json1 = JSON.parse(res.data.data.detectjson);
func(json, json1, res.data.data.img)
} else {
getApp().showWarning("获取数据失败");
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { },
set_share_img() {
var th = this;
var path3 = th.data.iurl + "/miniapp/images/skinimg/nan.png";
if (this.data.sex == 'female')
path3 = th.data.iurl + "/miniapp/images/skinimg/nv.png";
// 读取文件成功则OK--
wx.getImageInfo({
src: path3,
success: function (res) {
//获取到二维码的图片
th.data.share_head = res.path;
}
})
},
scroll_view(e) {
let scrollTop = e.detail.scrollTop;
let heightRecord = this.data.heightRecord;
if (heightRecord.length === 0) return;
let length = this.data.tab.length;
var index = 0;
if (scrollTop >= heightRecord[0]) {
for (let i = 0; i < length; i++) {
if (scrollTop >= heightRecord[i - 1] && scrollTop < heightRecord[i]) {
index = i;
break;
}
}
}
if (index !== this.data.currentIndex) {
// let tab_id = this.data.tab[index].id;
console.log(scrollTop);
this.setData({
scrollTop,
// currentIndex: index,
})
}
},
click_scroll(e) {
let { index, scroll_id } = e.currentTarget.dataset;
this.setData({
scroll_index: index,
scroll_id,
})
//-- 如果是黑眼圈的控制 --
if (this.data.show_type == 5) {
switch (scroll_id) {
case 1:
this.setData({ is_esys_show: 0 })
break;
case 2:
this.setData({ is_esys_show: 1 })
break;
default:
this.setData({ is_esys_show: 2 })
break
}
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () { },
clickTab(e) {
let { index, tab_id } = e.currentTarget.dataset;
this.setData({
currentIndex: index,
tab_id,
})
},
click_yanjing() {
this.setData({
yanjing: !this.data.yanjing,
})
},
click_fangda() {
this.setData({
img_scale: !this.data.img_scale,
img_scale_icon: !this.data.yanjing,
ig_scale: 1, img_top: 0, img_left: 0
})
},
click_yiwen_scroll(e) {
let { index, yiwen_id } = e.currentTarget.dataset;
this.setData({
yiwen_index: index,
yiwen_id,
})
},
close_yiwen() {
this.setData({
question_dialog: false,
yiwen_index: 0,
yiwen_id: 'yiwen1'
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
show_dailog(e) {
var th = this;
var type = parseInt(e.currentTarget.dataset.type);
this.setData({
showDialog: true, show_type: type, is_esys_show: 0, ig_scale: 1, img_top: 0, img_left: 0, scroll_index: 0, scroll_id: 1
})
switch (type) {
case 1: //毛孔
var pore_list = this.data.face_data.blackheadpore.circles.filter(function (e) {
return e.pore
})
this.setData({ pore_list: pore_list[0].pore });
break;
case 2://色斑
var speckle_list = this.data.face_data.acnespotmole.speckle_list;
this.setData({ speckle_list: speckle_list });
break;
case 3://皱纹
var wrinkle_list = this.data.face_data.wrinkle.wrinkle_data;
for (let i in wrinkle_list) {
let item = wrinkle_list[i];
item.map(function (e) {
e.w_type = th.data.wrinkle_types[i];
return e;
})
}
this.setData({ wrinkle_list: wrinkle_list });
break;
case 4://黑头
var blackhead_list = this.data.face_data.blackheadpore.circles.filter(function (e) {
return e.blackhead
})
this.setData({ blackhead_list: blackhead_list[0].blackhead });
break;
case 5://黑眼圈
var arr = this.data.face_data.eyesattr.dark_circle_left[0];
var arr2 = this.data.face_data.eyesattr.dark_circle_right[0];
var arr3 = [...arr, ...arr2];
this.setData({ dark_list: arr3 });
break;
case 6://痤疮
var acne_list = this.data.face_data.acnespotmole.acne_list;
this.setData({ acne_list: acne_list });
break;
default:
break
}
},
close_dialog() {
this.setData({
showDialog: false,
share_flag: false,
img_scale: true,
})
},
close_mask() {
this.setData({
showDialog: false,
img_scale: true,
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
getApp().globalData.no_clear=1;
var url="packageD/pages/AI-test-skin/success_result/success_result?id="+this.data.id+"&first_leader="+getApp().globalData.user_id;
var ob = {
title: "测肤报告",
path: url,
};
return ob;
},
//商品页面跳转
go_url: function (e) {
var url = e.currentTarget.dataset.url;
getApp().goto(url);
},
//--- 获取卡类列表 ---
getPlusCardType: function (func) {
var storid = setting.stoid;
var th = this;
getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + storid, {}).then(res => {
if (res.data.code != 0 || !res.data.data) {
var ob = {
"card_list": [],
"name_map": ""
};
func(ob);
return false;
}
var plusCard = res.data.data;
var arr = [1219, 2089, 3031];
var new_arr = new Array();
var card_name_map = new Map();
var user = getApp().globalData.userInfo;
if (plusCard) {
for (var i = 0; i < plusCard.length; i++) {
if ((!user || user.card_field == null || user.card_field == "") && (plusCard[i].IsStopBuy == true)) {
continue;
}
var name = "card" + plusCard[i].CorrPrice.toLowerCase();
card_name_map.set(name, plusCard[i].CardName);
new_arr.push(plusCard[i]);
}
}
var ob = {
"card_list": new_arr,
"name_map": card_name_map
};
func(ob);
})
},
click_share() {
this.setData({
share_flag: true,
img_scale: false,
showDialog: true,
})
},
//图片加载的时候,计算图片的像素大小
face_img_load: function (e) {
var th = this;
var imgwidth = e.detail.width;
var imgheight = e.detail.height;
var w = th.data.cWidth * 0.8;
this.setData({
iwidth: imgwidth * th.data.bili,
iheight: imgheight * th.data.bili,
eye_w: imgwidth * th.data.bili_eye,
eye_h: imgheight * th.data.bili_eye,
bili1: w / imgwidth //图片放大时候的比例
})
},
//-- 图片的拖拽缩放的功能 --
touchstartCallback: function (e) {
this.data.tc_end = 0;
// 单手指缩放开始,也不做任何处理
if (e.touches.length > 1) {
// 一开始我并没有这个回调函数,会出现缩小的时候有瞬间被放大过程的bug
// 当两根手指放上去的时候,就将distance 初始化。
let xMove = e.touches[1].clientX - e.touches[0].clientX;
let yMove = e.touches[1].clientY - e.touches[0].clientY;
let distance = Math.sqrt(xMove * xMove + yMove * yMove);
this.data.img_distance = distance;
} else if (e.touches.length == 1) {
this.data.img_x = e.touches[0].clientX;
this.data.img_y = e.touches[0].clientY;
}
},
touchmoveCallback: function (e) {
if (this.data.tc_end) return false;
// 单手指缩放我们不做任何操作
if (e.touches.length > 1) {
let xMove = e.touches[1].clientX - e.touches[0].clientX;
let yMove = e.touches[1].clientY - e.touches[0].clientY;
// 新的 ditance
let distance = Math.sqrt(xMove * xMove + yMove * yMove);
let distanceDiff = distance - this.data.img_distance;
let newScale = this.data.ig_scale + 0.005 * distanceDiff
// 为了防止缩放得太大,所以scale需要限制,同理最小值也是
if (newScale >= 2) {
newScale = 2
}
if (newScale <= 0.6) {
newScale = 0.6
}
this.data.img_distance = distance;
// 赋值 新的 => 旧的
this.setData({
'ig_scale': newScale,
})
} else if (e.touches.length == 1) {
let xMove = e.touches[0].clientX - this.data.img_x;
let yMove = e.touches[0].clientY - this.data.img_y;
this.setData({
'img_top': yMove * 0.8,
'img_left': xMove * 0.8,
});
}
},
touchendCallback: function (e) {
this.data.tc_end = 1;
},
//--定义的保存图片方法,分享团---
saveImageToPhotosAlbum: function () {
var th = this;
var rpx = this.data.cWidth / 750 * 1.35; //基础单位,
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
wx.navigateTo({ url: '/pages/togoin/togoin', })
return false;
}
if (this.data.share_hidden) {
this.setData({ share_hidden: false, });
}
wx.showLoading({ title: '生成中...', })
var that = this, th = that;
//设置画板显示,才能开始绘图
that.setData({ canvasHidden: false })
var app = getApp();
var scene = this.data.id + "";
var user_id = getApp().globalData.user_id ? getApp().globalData.user_id : 0;
if (user_id > 0) {
scene += "_" + user_id;
}
///二微码
var path3 = setting.url + "/api/wx/open/app/user/getWeAppEwm/" +
setting.stoid + "?sceneValue=" + scene + "&pageValue=packageD/pages/AI-test-skin/success_result/success_result";
// 读取文件成功则OK--
wx.getImageInfo({
src: path3,
success: function (res) {
var b = 1.1;
//获取到二维码的图片
var vpath = res.path;
var context = wx.createCanvasContext('share');
// 先画背景
context.fillStyle = '#ebf6f8';
// 灰色实心矩形
// 1. 语法: x坐标, y坐标, 宽度, 高度
context.fillRect(0, 0, 750 * rpx, 1338 * rpx);
context.setFontSize(20 * rpx)
context.setFillStyle("#00d8e9")
context.fillText("官方检测认证", 28 * b * rpx, 80 * b * rpx);
//两个底部颜色
context.fillStyle = '#a7ecf5';
context.fillRect(28 * b * rpx, 136 * b * rpx, 262 * b * rpx, 18 * b * rpx);
context.fillRect(28 * b * rpx, 194 * b * rpx, 262 * b * rpx, 18 * b * rpx);
context.setFontSize(42 * b * rpx)
context.setFillStyle("#070609")
context.fillText("我的肌底强韧", 30 * b * rpx, 140 * b * rpx);
context.fillText("肌肤鲜活润泽", 30 * b * rpx, 196 * b * rpx);
//先画一个圆形
th.circle(context, 110 * b * rpx, 280 * b * rpx, 140 * b * rpx, "#e7f3f8");
th.circle(context, 130 * b * rpx, 300 * b * rpx, 120 * b * rpx, "#c8f2fa");
//绘制人脸
context.drawImage(th.data.share_head, 132 * b * rpx, 310 * b * rpx, 230 * b * rpx, 230 * b * rpx);
//左右俩个框并填充文字
th.darwRoundRect(38 * b * rpx, 340 * b * rpx, 140 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
th.darwRoundRect(324 * b * rpx, 340 * b * rpx, 140 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
context.setFontSize(20 * b * rpx)
context.setFillStyle("black")
context.fillText("黑眼圈 重度", 50 * b * rpx, 368 * b * rpx);
context.fillText("毛孔 " + th.data.pore_num, 336 * b * rpx, 368 * b * rpx);
//左右俩个框并填充文字
th.darwRoundRect(40 * b * rpx, 412 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
th.darwRoundRect(348 * b * rpx, 412 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
context.setFillStyle("black")
context.fillText("黑头 " + th.data.blackhead_num, 52 * b * rpx, 440 * b * rpx);
context.fillText("色斑 " + th.data.speckle_num, 354 * b * rpx, 440 * b * rpx);
//左右俩个框并填充文字
th.darwRoundRect(60 * b * rpx, 484 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
th.darwRoundRect(328 * b * rpx, 484 * b * rpx, 116 * b * rpx, 40 * b * rpx, 20 * b * rpx, context);
context.setFillStyle("black")
context.fillText("皱纹 " + th.data.wrinkle_num, 74 * b * rpx, 510 * b * rpx);
context.fillText("痤疮 " + th.data.acne_num, 344 * b * rpx, 510 * b * rpx);
//底部的绘制
th.darwRoundRect(38 * b * rpx, 650 * b * rpx, 430 * b * rpx, 160 * b * rpx, 10 * b * rpx, context);
//绘制二维码
context.drawImage(vpath, 60 * b * rpx, 672 * b * rpx, 120 * b * rpx, 120 * b * rpx);
context.setFillStyle("black")
context.setFontSize(32 * b * rpx)
context.fillText("美肤管家AI测肤", 200 * b * rpx, 726 * b * rpx);
context.setFontSize(22 * b * rpx)
context.fillText("科学了解皮肤的真实状态", 200 * b * rpx, 766 * b * rpx);
//把画板内容绘制成图片,并回调 画板图片路径
context.draw(false, function () {
setTimeout(function () {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 750,
height: 1338,
destWidth: 1.4 * 750 * 750 / th.data.screenWidth,
destHeight: 1.4 * 750 * 750 / th.data.screenWidth,
canvasId: 'share',
success: function (res) {
that.setData({
shareImgPath: res.tempFilePath,
canvasHidden: true,
share_show: 1
})
/*--
wx.previewImage({
//将图片预览出来
ur--*/
wx.hideLoading();
}
})
}, 500)
});
},
fail: function (res) {
console.log(res);
wx.hideLoading();
}
});
},
// 圆形图片
circle: function (ctx, x, y, r, color) {
ctx.save()
ctx.beginPath();
var cx = x + r;
var cy = y + r;
ctx.arc(cx, cy, r, 0, 2 * Math.PI);
ctx.clip();
ctx.fillStyle = color;
ctx.fillRect(x, y, 2 * r, 2 * r);
ctx.restore()
ctx.closePath();
},
/**
* 绘制圆角矩形
* @param {*} x 起始点x坐标
* @param {*} y 起始点y坐标
* @param {*} w 矩形宽
* @param {*} h 矩形高
* @param {*} r 圆角半径
* @param {*} ctx 画板上下文
*/
darwRoundRect(x, y, w, h, r, ctx) {
ctx.save()
ctx.beginPath()
// 左上弧线
ctx.arc(x + r, y + r, r, 1 * Math.PI, 1.5 * Math.PI)
// 左直线
ctx.moveTo(x, y + r)
ctx.lineTo(x, y + h - r)
// 左下弧线
ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, 1 * Math.PI)
// 下直线
ctx.lineTo(x + r, y + h)
ctx.lineTo(x + w - r, y + h)
// 右下弧线
ctx.arc(x + w - r, y + h - r, r, 0 * Math.PI, 0.5 * Math.PI)
// 右直线
ctx.lineTo(x + w, y + h - r)
ctx.lineTo(x + w, y + r)
// 右上弧线
ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI)
// 上直线
ctx.lineTo(x + w - r, y)
ctx.lineTo(x + r, y)
ctx.setFillStyle('white')
ctx.fill()
},
close_share: function () {
this.setData({ share_show: 0 })
},
// 保存图片到手机
savePic() {
var self = this;
// 获取用户的当前设置,返回值中有小程序已经向用户请求过的权限
this.getSetting().then((res) => {
// 判断用户是否授权了保存到相册的权限,如果没有发起授权
if (!res.authSetting['scope.writePhotosAlbum']) {
this.authorize().then(() => {
// 同意授权后保存下载文件
this.saveImage(self.data.shareImgPath)
.then(() => {
self.setData({
share_show: false
});
});
})
} else {
// 如果已经授权,保存下载文件
this.saveImage(self.data.shareImgPath)
.then(() => {
self.setData({
share_show: false
});
});
}
})
},
// 获取用户已经授予了哪些权限
getSetting() {
return new Promise((resolve, reject) => {
wx.getSetting({
success: res => {
resolve(res)
}
})
})
},
// 发起首次授权请求
authorize() {
// isFirst 用来记录是否为首次发起授权,
// 如果首次授权拒绝后,isFirst赋值为1
let isFirst = wx.getStorageSync('isFirst') || 0;
return new Promise((resolve, reject) => {
wx.authorize({
scope: 'scope.writePhotosAlbum',
// 同意授权
success: () => {
resolve();
},
// 拒绝授权,这里是用户拒绝授权后的回调
fail: res => {
if (isFirst === 0) {
wx.setStorageSync('isFirst', 1);
wx.showToast({
title: '保存失败',
icon: 'none',
duration: 1000
})
} else {
this.showModal();
}
console.log('拒绝授权');
reject();
}
})
})
},
// 保存图片到系统相册
saveImage(saveUrl) {
var self = this;
return new Promise((resolve, reject) => {
wx.saveImageToPhotosAlbum({
filePath: saveUrl,
success: (res) => {
wx.showToast({
title: '保存成功',
duration: 1000,
});
resolve();
},
fail: () => {
wx.showToast({
title: '保存失败',
duration: 1000,
});
}
})
})
},
show_yiwen_dialog(e) {
let yiwen_type = e.currentTarget.dataset.yiwen_type;
this.setData({
question_dialog: true,
yiwen_type,
})
},
//-----领取券-----
get_quan: function (e) {
var cid = e.currentTarget.dataset.cid;
var index = e.currentTarget.dataset.ind;
var q_word = e.currentTarget.dataset.word;
var item = this.data[q_word][index];
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
wx.navigateTo({
url: '/pages/togoin/togoin',
})
return false;
}
//如果券还在领取中,不能再点
if (item.linging == 1) {
getApp().my_warnning('领取中..', 0, this);
return false;
}
//如果领取的次数到了
if (item.everyone_num > 0 && item.lqnum >= item.everyone_num) {
getApp().my_warnning('领取失败,您已领完该券', 0, this);
return false;
}
var lq_num = item.lqnum;
var pdata = {
'uid': getApp().globalData.user_id,
'cid': cid,
'store_id': setting.stoid,
'type': 5
};
//-- 导购ID --
if (getApp().globalData.guide_id) {
pdata.guide_id = getApp().globalData.guide_id;
}
var app = getApp(), th = this;
wx.showLoading();
app.request.post("/api/weshop/couponList/saveCouponList", {
data: pdata,
success: function (res) {
wx.hideLoading();
if (res.data.code == 0) {
app.my_warnning("领取成功", 1, th);
lq_num++;
var text = q_word + "[" + index + "].lqnum";
var text2 = q_word + "[" + index + "].linging";
var obj = {};
obj[text] = lq_num;
obj[text2] = 0;
th.setData(obj);
} else {
app.confirmBox(res.data.msg);
var text2 = q_word + "[" + index + "].linging";
var obj = {};
obj[text2] = 0;
th.setData(obj);
}
}
})
},
})