Commit 6d4a388a9fec0148fcb7e9b9e4dfd700896d0ab7
1 parent
03ca390c
测肤测试返回优化
Showing
2 changed files
with
76 additions
and
78 deletions
packageD/pages/AI-test-skin/index/aiskin.js
| 1 | 1 | /* |
| 2 | 2 | * @Author: abson |
| 3 | 3 | * @Date: 2022-02-11 14:13:05 |
| 4 | - * @LastEditTime: 2022-03-26 17:03:01 | |
| 4 | + * @LastEditTime: 2022-04-12 12:05:50 | |
| 5 | 5 | * @LastEditors: Please set LastEditors |
| 6 | 6 | * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
| 7 | 7 | * @FilePath: \MShopWeApp\packageB\pages\AI-test-skin\index\aiskin.js |
| ... | ... | @@ -25,12 +25,14 @@ Page({ |
| 25 | 25 | * 生命周期函数--监听页面加载 |
| 26 | 26 | */ |
| 27 | 27 | onLoad: function (options) { |
| 28 | - getApp().globalData.user_id = options?.user_id; | |
| 29 | - getApp().getUserFir(); | |
| 30 | - var user = getApp().globalData.userInfo; | |
| 31 | - if (!user || !getApp().globalData.user_id) { | |
| 32 | - let url = "/pages/togoin/togoin"; | |
| 33 | - app.goto(url); | |
| 28 | + let user_id = options.user_id || getApp().globalData.user_id; | |
| 29 | + if (user_id) { | |
| 30 | + getApp().getUserFir(); | |
| 31 | + } else { | |
| 32 | + setTimeout(function () { | |
| 33 | + let url = "/pages/togoin/togoin"; | |
| 34 | + app.goto(url); | |
| 35 | + }, 1000) | |
| 34 | 36 | } |
| 35 | 37 | }, |
| 36 | 38 | ... | ... |
utils/filter.wxs
| 1 | 1 | var filters = { |
| 2 | 2 | toFix: function (val, count) { |
| 3 | - if(!val){ | |
| 3 | + if (!val) { | |
| 4 | 4 | return parseFloat(0).toFixed(count); |
| 5 | 5 | } |
| 6 | 6 | val = parseFloat(val); |
| ... | ... | @@ -38,7 +38,7 @@ var filters = { |
| 38 | 38 | } |
| 39 | 39 | return fm; |
| 40 | 40 | }, |
| 41 | - | |
| 41 | + | |
| 42 | 42 | format_time2: function (ts, isFull) { |
| 43 | 43 | // 如果数值位数为1,则补0 |
| 44 | 44 | function appendZero(obj) { |
| ... | ... | @@ -48,7 +48,7 @@ var filters = { |
| 48 | 48 | return obj; |
| 49 | 49 | } |
| 50 | 50 | }; |
| 51 | - | |
| 51 | + | |
| 52 | 52 | if (ts == null || ts == undefined || ts == '') return ""; |
| 53 | 53 | var d = getDate(ts) |
| 54 | 54 | var fm = [appendZero(d.getFullYear()), appendZero(d.getMonth() + 1), appendZero(d.getDate())].join('-'); |
| ... | ... | @@ -81,34 +81,34 @@ var filters = { |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | }, |
| 84 | - | |
| 84 | + | |
| 85 | 85 | |
| 86 | 86 | show_default: function (value, placeholder, multiple) { |
| 87 | - if(typeof value === 'number') { | |
| 88 | - if(isNaN(value)) { | |
| 87 | + if (typeof value === 'number') { | |
| 88 | + if (isNaN(value)) { | |
| 89 | 89 | return placeholder || '-'; |
| 90 | - } else if(value === 0) { | |
| 90 | + } else if (value === 0) { | |
| 91 | 91 | return placeholder || '0'; |
| 92 | 92 | } else { |
| 93 | - if(multiple) { | |
| 93 | + if (multiple) { | |
| 94 | 94 | return value / multiple; |
| 95 | 95 | } else { |
| 96 | 96 | return value; |
| 97 | 97 | } |
| 98 | - }; | |
| 99 | - } else if(value === '' || value === undefined || value === null) { | |
| 98 | + }; | |
| 99 | + } else if (value === '' || value === undefined || value === null) { | |
| 100 | 100 | return placeholder || '-'; |
| 101 | 101 | } else { |
| 102 | 102 | return value; |
| 103 | 103 | } |
| 104 | 104 | }, |
| 105 | - | |
| 106 | - | |
| 105 | + | |
| 106 | + | |
| 107 | 107 | // 根据状态值返回相应的状态文字 |
| 108 | 108 | // num:状态数值, |
| 109 | 109 | // arr: 状态文字数组, |
| 110 | 110 | // 文字顺序必须跟状态数值对应 |
| 111 | - status: function(num, arr) { | |
| 111 | + status: function (num, arr) { | |
| 112 | 112 | // var text = ''; |
| 113 | 113 | // if(num == 0) { |
| 114 | 114 | // text = '未付款'; |
| ... | ... | @@ -121,103 +121,103 @@ var filters = { |
| 121 | 121 | // }; |
| 122 | 122 | return arr[num]; |
| 123 | 123 | }, |
| 124 | - | |
| 125 | - | |
| 126 | - in_arr: function(index, arr) { | |
| 127 | - if(arr.indexOf(index) != -1) { | |
| 124 | + | |
| 125 | + | |
| 126 | + in_arr: function (index, arr) { | |
| 127 | + if (arr.indexOf(index) != -1) { | |
| 128 | 128 | return true; |
| 129 | 129 | } else { |
| 130 | 130 | return false; |
| 131 | 131 | }; |
| 132 | 132 | }, |
| 133 | - | |
| 134 | - showByType: function(typeStr) { | |
| 133 | + | |
| 134 | + showByType: function (typeStr) { | |
| 135 | 135 | var index; |
| 136 | 136 | var newTypeArr = []; |
| 137 | 137 | var typeStrArr = typeStr.split(','); |
| 138 | - typeStrArr.forEach(function(item) { | |
| 138 | + typeStrArr.forEach(function (item) { | |
| 139 | 139 | index = parseInt(item); |
| 140 | 140 | newTypeArr.push(index); |
| 141 | 141 | }); |
| 142 | 142 | // console.log('newTypeArr', newTypeArr); |
| 143 | 143 | return newTypeArr; |
| 144 | 144 | }, |
| 145 | - | |
| 145 | + | |
| 146 | 146 | // 价格除以100 |
| 147 | - price: function(val) { | |
| 148 | - return val / 100; | |
| 147 | + price: function (val) { | |
| 148 | + return val / 100; | |
| 149 | 149 | }, |
| 150 | - | |
| 151 | - div100: function(val) { | |
| 152 | - return val / 100; | |
| 150 | + | |
| 151 | + div100: function (val) { | |
| 152 | + return val / 100; | |
| 153 | 153 | }, |
| 154 | - | |
| 154 | + | |
| 155 | 155 | // 计算百分比, 不带百分号 |
| 156 | - percent: function(num1, num2) { | |
| 156 | + percent: function (num1, num2) { | |
| 157 | 157 | // console.log('百分比',Math.round(num1/num2 * 10000) / 100); |
| 158 | - return Math.round(num1/num2 * 10000) / 100; | |
| 159 | - }, | |
| 160 | - | |
| 158 | + return Math.round(num1 / num2 * 10000) / 100; | |
| 159 | + }, | |
| 160 | + | |
| 161 | 161 | // 计算差数 |
| 162 | - difference: function(num1, num2) { | |
| 163 | - if(!num1) num1 = 0; | |
| 164 | - if(!num2) num2 = 0; | |
| 165 | - if(num1 >= num2) { | |
| 162 | + difference: function (num1, num2) { | |
| 163 | + if (!num1) num1 = 0; | |
| 164 | + if (!num2) num2 = 0; | |
| 165 | + if (num1 >= num2) { | |
| 166 | 166 | return num1 - num2; |
| 167 | 167 | } else { |
| 168 | 168 | return num2 - num1; |
| 169 | 169 | }; |
| 170 | 170 | }, |
| 171 | - | |
| 171 | + | |
| 172 | 172 | // 计算乘积 |
| 173 | - multiply: function(num1, num2) { | |
| 174 | - return num1 * 10000 * num2 / 10000; | |
| 173 | + multiply: function (num1, num2) { | |
| 174 | + return num1 * 10000 * num2 / 10000; | |
| 175 | 175 | }, |
| 176 | - | |
| 177 | - JSONStringify: function(val) { | |
| 176 | + | |
| 177 | + JSONStringify: function (val) { | |
| 178 | 178 | return JSON.stringify(val); |
| 179 | 179 | }, |
| 180 | - | |
| 180 | + | |
| 181 | 181 | // 循环列表计算数量 |
| 182 | - count: function(list) { | |
| 182 | + count: function (list) { | |
| 183 | 183 | var sum = 0; |
| 184 | - if(list && list.length != 0) { | |
| 185 | - list.forEach(function(item) { | |
| 184 | + if (list && list.length != 0) { | |
| 185 | + list.forEach(function (item) { | |
| 186 | 186 | sum += item.qty; |
| 187 | 187 | }); |
| 188 | 188 | return sum; |
| 189 | 189 | }; |
| 190 | 190 | }, |
| 191 | - | |
| 191 | + | |
| 192 | 192 | // 判断时间是否过期 |
| 193 | - isExpired: function(date) { | |
| 193 | + isExpired: function (date) { | |
| 194 | 194 | var mydate = getDate(date).getTime(); |
| 195 | 195 | var currentDate = getDate().getTime(); |
| 196 | 196 | |
| 197 | - if(currentDate >= mydate) { | |
| 197 | + if (currentDate >= mydate) { | |
| 198 | 198 | return true; |
| 199 | 199 | } else { |
| 200 | 200 | return false; |
| 201 | 201 | }; |
| 202 | 202 | }, |
| 203 | - | |
| 203 | + | |
| 204 | 204 | // 显示开始和结束日期 |
| 205 | - showStartAndEndDate: function(o, val) { | |
| 206 | - | |
| 205 | + showStartAndEndDate: function (o, val) { | |
| 206 | + | |
| 207 | 207 | var dateType = o.date_type; |
| 208 | 208 | var currentDate = getDate().getTime(); |
| 209 | 209 | var startDate, endDate, days, begin_days; |
| 210 | - | |
| 211 | - | |
| 212 | - if(dateType === 0) { | |
| 213 | - | |
| 214 | - if(o.effective_days !== 0) { | |
| 210 | + | |
| 211 | + | |
| 212 | + if (dateType === 0) { | |
| 213 | + | |
| 214 | + if (o.effective_days !== 0) { | |
| 215 | 215 | days = (o.effective_days - 1) * 24 * 60 * 60 * 1000; |
| 216 | 216 | endDate = filters.format_time2(currentDate + days); |
| 217 | 217 | currentDate = filters.format_time2(currentDate); |
| 218 | 218 | return currentDate + '至' + endDate; |
| 219 | 219 | } else { |
| 220 | - if(val) { | |
| 220 | + if (val) { | |
| 221 | 221 | days = (val - 1) * 24 * 60 * 60 * 1000; |
| 222 | 222 | endDate = filters.format_time2(currentDate + days); |
| 223 | 223 | currentDate = filters.format_time2(currentDate); |
| ... | ... | @@ -227,27 +227,27 @@ var filters = { |
| 227 | 227 | return currentDate + '至不限'; |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | - | |
| 230 | + | |
| 231 | 231 | }; |
| 232 | - | |
| 233 | - if(dateType === 1) { | |
| 232 | + | |
| 233 | + if (dateType === 1) { | |
| 234 | 234 | currentDate = filters.format_time2(currentDate); |
| 235 | - if(o.begin_date && o.effective_date) { | |
| 235 | + if (o.begin_date && o.effective_date) { | |
| 236 | 236 | return o.begin_date + '至' + o.effective_date; |
| 237 | 237 | }; |
| 238 | - if(o.begin_date && !o.effective_date) { | |
| 238 | + if (o.begin_date && !o.effective_date) { | |
| 239 | 239 | return o.begin_date + '至不限'; |
| 240 | 240 | }; |
| 241 | - if(!o.begin_date && o.effective_date) { | |
| 241 | + if (!o.begin_date && o.effective_date) { | |
| 242 | 242 | return currentDate + '至' + o.effective_date; |
| 243 | 243 | }; |
| 244 | - if(!o.begin_date && !o.effective_date) { | |
| 244 | + if (!o.begin_date && !o.effective_date) { | |
| 245 | 245 | return currentDate + '至不限'; |
| 246 | 246 | }; |
| 247 | 247 | }; |
| 248 | - | |
| 249 | - | |
| 250 | - if(dateType === 2) { | |
| 248 | + | |
| 249 | + | |
| 250 | + if (dateType === 2) { | |
| 251 | 251 | // N天后开始 |
| 252 | 252 | begin_days = o.begin_days * 24 * 60 * 60 * 1000; |
| 253 | 253 | // 有效天数 |
| ... | ... | @@ -256,11 +256,7 @@ var filters = { |
| 256 | 256 | endDate = filters.format_time2(getDate(startDate).getTime() + days); |
| 257 | 257 | return startDate + '至' + endDate; |
| 258 | 258 | }; |
| 259 | - | |
| 260 | - }, | |
| 261 | - | |
| 262 | - | |
| 263 | - | |
| 259 | + }, | |
| 264 | 260 | }; |
| 265 | 261 | |
| 266 | 262 | module.exports = { | ... | ... |