Authored by ccbikai

价格 折扣排序

... ... @@ -29,10 +29,21 @@ const _procProductImg = (product, gender, yhChannel) => {
const _sortListByField = (list, key, desc) => {
list = _.toArray(list);
list = list.sort((a, b) => {
let matchNumber = /([\d]+)/g;
// 有键,使用键的值排序
if (a[key] && b[key]) {
return (desc ? a[key] > b[key] : a[key] < b[key]) ? -1 : 1;
let numA = +(_.toArray(a[key].match(matchNumber))[0] || 0); // 取第一个出现的数字排序,如果不存在,取0
let numB = +(_.toArray(b[key].match(matchNumber))[0] || 0);
return (desc ? numA > numB : numA < numB) ? -1 : 1;
}
return (desc ? a > b : a < b) ? -1 : 1;
// 无键, 使用本身
let numA = +(_.toArray(a.match(matchNumber))[0] || 0);
let numB = +(_.toArray(b.match(matchNumber))[0] || 0);
return numA < numB ? -1 : 1;
});
return list;
};
... ...