success_result.js
15.6 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
/*
* @Author: abson
* @Date: 2022-02-16 15:36:47
* @LastEditTime: 2022-02-22 16:16:59
* @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');
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: '敏感度' }],
currentIndex: 0,
tab_id: 'zong_he',
iurl: setting.imghost,
showDialog: false,
yanjing: true, //显示皮肤问题
img_scale: true, //问题标注放大图片
img_scale_icon:true,
show_problem:1, //问题标注显示问题
img_scale:1, //缩放问题
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var th = this;
//初始化一下,获取商品的价格
this.init();
//var face_result=getApp().globalData.face_result;
//var face_data=face_result.face_list[0];
this.data.id = options.id;
//计算图片要显示的大小
th.data.cWidth = wx.getSystemInfoSync().windowWidth;
th.data.cHeight = wx.getSystemInfoSync().windowHeight;
th.data.face_height = th.data.cHeight * 0.8 * 0.8;
this.get_data(function (json, json1, img) {
//-- 数据先存着 --
var face_data = th.data.face_data = json.face_list[0];
var sex = json1.face_list[0].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;
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;
th.data.bili = th.data.face_height / (location.height + location.height / 2.3);
th.setData({
acne_num: acne_num,
speckle_num: speckle_num,
wrinkle_num: wrinkle_num,
blackhead_num: blackhead_num,
pore_num: pore_num,
dark_type: dark_type,
skin_sensitive_check: skin_sensitive_check,
skin_dryoil_check: skin_dryoil_check,
face_img: img,
m_top: (location.top - location.height / 2.5) * th.data.bili,
m_left: (location.left - location.width / 7) * th.data.bili,
bili: th.data.bili
})
//-- 调用毛孔的推荐函数 --
if (pore_num > 0)
pore.get_goods(th, setting.stoid);
//-- 调用黑头的推荐函数 --
if (blackhead_num > 0)
blackhead.get_goods(th, setting.stoid);
//-- 调用色斑的推荐函数 --
if (speckle_num > 0)
speckle.get_goods(th, setting.stoid);
//-- 调用皱纹的推荐函数 --
if (wrinkle_num > 0)
wrinkle.get_goods(th, setting.stoid);
//-- 黑眼圈 --
if (dark_type > -1)
dark.get_goods(th, setting.stoid);
//-- 黑眼圈 --
if (acne_num > -0)
acne.get_goods(th, setting.stoid);
})
},
//-- 初始等级卡 --
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) {
console.log(res, 'dsffffff');
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 () {
// let heightRecords = [];
// setTimeout(() => {
// for (let i = 0; i < this.data.tab.length; i++) {
// let item = this.data.tab[i];
// let id = `#${item.id}`;
// let query = wx.createSelectorQuery();
// query.select(id).boundingClientRect(rect => {
// console.log(rect, i);
// heightRecords[i] = rect.height;
// }).exec()
// }
// this.setData({
// heightRecords,
// })
// }, 1000)
},
binddragend(e) {
console.log(e);
this.setData({
scrollTop: e.detail.scrollTop,
})
},
/**
* 生命周期函数--监听页面显示
*/
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,
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
show_dailog(e) {
var type = parseInt(e.currentTarget.dataset.type);
this.setData({
showDialog: true, show_type: type
})
switch (type) {
case 1: //毛孔
var pore_list = this.data.face_data.blackheadpore.circles[0].pore;
this.setData({ pore_list: pore_list });
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;
this.setData({ wrinkle_list: wrinkle_list });
break;
case 4://黑头
var blackhead_list = this.data.face_data.blackheadpore.circles[0].blackhead;
this.setData({ blackhead_list: blackhead_list });
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,
})
},
close_mask() {
this.setData({
showDialog: false,
img_scale: true,
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
//商品页面跳转
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);
})
},
//图片加载的时候,计算图片的像素大小
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,
bili1: w / imgwidth //图片放大时候的比例
})
},
//-- 图片的拖拽缩放的功能 --
touchstartCallback: function(e) {
// 单手指缩放开始,也不做任何处理
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(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.img_scale + 0.005 * distanceDiff
// 为了防止缩放得太大,所以scale需要限制,同理最小值也是
if(newScale >= 2) {
newScale = 2
}
if(newScale <= 0.6) {
newScale = 0.6
}
this.data.img_distance=distance;
// 赋值 新的 => 旧的
this.setData({
'img_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,
'img_left': xMove,
});
this.data.img_x=e.touches[0].clientX;
this.data.img_y=e.touches[0].clientY;
}
},
})