From 6d4a388a9fec0148fcb7e9b9e4dfd700896d0ab7 Mon Sep 17 00:00:00 2001 From: abson Date: Tue, 12 Apr 2022 16:34:00 +0800 Subject: [PATCH] 测肤测试返回优化 --- packageD/pages/AI-test-skin/index/aiskin.js | 16 +++++++++------- utils/filter.wxs | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------- 2 files changed, 76 insertions(+), 78 deletions(-) diff --git a/packageD/pages/AI-test-skin/index/aiskin.js b/packageD/pages/AI-test-skin/index/aiskin.js index 8ba5e78..49bb8e8 100644 --- a/packageD/pages/AI-test-skin/index/aiskin.js +++ b/packageD/pages/AI-test-skin/index/aiskin.js @@ -1,7 +1,7 @@ /* * @Author: abson * @Date: 2022-02-11 14:13:05 - * @LastEditTime: 2022-03-26 17:03:01 + * @LastEditTime: 2022-04-12 12:05:50 * @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\index\aiskin.js @@ -25,12 +25,14 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - getApp().globalData.user_id = options?.user_id; - getApp().getUserFir(); - var user = getApp().globalData.userInfo; - if (!user || !getApp().globalData.user_id) { - let url = "/pages/togoin/togoin"; - app.goto(url); + let user_id = options.user_id || getApp().globalData.user_id; + if (user_id) { + getApp().getUserFir(); + } else { + setTimeout(function () { + let url = "/pages/togoin/togoin"; + app.goto(url); + }, 1000) } }, diff --git a/utils/filter.wxs b/utils/filter.wxs index 52cd24a..c5d1959 100644 --- a/utils/filter.wxs +++ b/utils/filter.wxs @@ -1,6 +1,6 @@ var filters = { toFix: function (val, count) { - if(!val){ + if (!val) { return parseFloat(0).toFixed(count); } val = parseFloat(val); @@ -38,7 +38,7 @@ var filters = { } return fm; }, - + format_time2: function (ts, isFull) { // 如果数值位数为1,则补0 function appendZero(obj) { @@ -48,7 +48,7 @@ var filters = { return obj; } }; - + if (ts == null || ts == undefined || ts == '') return ""; var d = getDate(ts) var fm = [appendZero(d.getFullYear()), appendZero(d.getMonth() + 1), appendZero(d.getDate())].join('-'); @@ -81,34 +81,34 @@ var filters = { } } }, - + show_default: function (value, placeholder, multiple) { - if(typeof value === 'number') { - if(isNaN(value)) { + if (typeof value === 'number') { + if (isNaN(value)) { return placeholder || '-'; - } else if(value === 0) { + } else if (value === 0) { return placeholder || '0'; } else { - if(multiple) { + if (multiple) { return value / multiple; } else { return value; } - }; - } else if(value === '' || value === undefined || value === null) { + }; + } else if (value === '' || value === undefined || value === null) { return placeholder || '-'; } else { return value; } }, - - + + // 根据状态值返回相应的状态文字 // num:状态数值, // arr: 状态文字数组, // 文字顺序必须跟状态数值对应 - status: function(num, arr) { + status: function (num, arr) { // var text = ''; // if(num == 0) { // text = '未付款'; @@ -121,103 +121,103 @@ var filters = { // }; return arr[num]; }, - - - in_arr: function(index, arr) { - if(arr.indexOf(index) != -1) { + + + in_arr: function (index, arr) { + if (arr.indexOf(index) != -1) { return true; } else { return false; }; }, - - showByType: function(typeStr) { + + showByType: function (typeStr) { var index; var newTypeArr = []; var typeStrArr = typeStr.split(','); - typeStrArr.forEach(function(item) { + typeStrArr.forEach(function (item) { index = parseInt(item); newTypeArr.push(index); }); // console.log('newTypeArr', newTypeArr); return newTypeArr; }, - + // 价格除以100 - price: function(val) { - return val / 100; + price: function (val) { + return val / 100; }, - - div100: function(val) { - return val / 100; + + div100: function (val) { + return val / 100; }, - + // 计算百分比, 不带百分号 - percent: function(num1, num2) { + percent: function (num1, num2) { // console.log('百分比',Math.round(num1/num2 * 10000) / 100); - return Math.round(num1/num2 * 10000) / 100; - }, - + return Math.round(num1 / num2 * 10000) / 100; + }, + // 计算差数 - difference: function(num1, num2) { - if(!num1) num1 = 0; - if(!num2) num2 = 0; - if(num1 >= num2) { + difference: function (num1, num2) { + if (!num1) num1 = 0; + if (!num2) num2 = 0; + if (num1 >= num2) { return num1 - num2; } else { return num2 - num1; }; }, - + // 计算乘积 - multiply: function(num1, num2) { - return num1 * 10000 * num2 / 10000; + multiply: function (num1, num2) { + return num1 * 10000 * num2 / 10000; }, - - JSONStringify: function(val) { + + JSONStringify: function (val) { return JSON.stringify(val); }, - + // 循环列表计算数量 - count: function(list) { + count: function (list) { var sum = 0; - if(list && list.length != 0) { - list.forEach(function(item) { + if (list && list.length != 0) { + list.forEach(function (item) { sum += item.qty; }); return sum; }; }, - + // 判断时间是否过期 - isExpired: function(date) { + isExpired: function (date) { var mydate = getDate(date).getTime(); var currentDate = getDate().getTime(); - if(currentDate >= mydate) { + if (currentDate >= mydate) { return true; } else { return false; }; }, - + // 显示开始和结束日期 - showStartAndEndDate: function(o, val) { - + showStartAndEndDate: function (o, val) { + var dateType = o.date_type; var currentDate = getDate().getTime(); var startDate, endDate, days, begin_days; - - - if(dateType === 0) { - - if(o.effective_days !== 0) { + + + if (dateType === 0) { + + if (o.effective_days !== 0) { days = (o.effective_days - 1) * 24 * 60 * 60 * 1000; endDate = filters.format_time2(currentDate + days); currentDate = filters.format_time2(currentDate); return currentDate + '至' + endDate; } else { - if(val) { + if (val) { days = (val - 1) * 24 * 60 * 60 * 1000; endDate = filters.format_time2(currentDate + days); currentDate = filters.format_time2(currentDate); @@ -227,27 +227,27 @@ var filters = { return currentDate + '至不限'; } } - + }; - - if(dateType === 1) { + + if (dateType === 1) { currentDate = filters.format_time2(currentDate); - if(o.begin_date && o.effective_date) { + if (o.begin_date && o.effective_date) { return o.begin_date + '至' + o.effective_date; }; - if(o.begin_date && !o.effective_date) { + if (o.begin_date && !o.effective_date) { return o.begin_date + '至不限'; }; - if(!o.begin_date && o.effective_date) { + if (!o.begin_date && o.effective_date) { return currentDate + '至' + o.effective_date; }; - if(!o.begin_date && !o.effective_date) { + if (!o.begin_date && !o.effective_date) { return currentDate + '至不限'; }; }; - - - if(dateType === 2) { + + + if (dateType === 2) { // N天后开始 begin_days = o.begin_days * 24 * 60 * 60 * 1000; // 有效天数 @@ -256,11 +256,7 @@ var filters = { endDate = filters.format_time2(getDate(startDate).getTime() + days); return startDate + '至' + endDate; }; - - }, - - - + }, }; module.exports = { -- libgit2 0.21.4