/* * @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, //问题标注显示问题 }, /** * 生命周期函数--监听页面加载 */ 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 //图片放大时候的比例 }) }, })