...
|
...
|
@@ -19,6 +19,27 @@ const _procProductImg = (product, gender, yhChannel) => { |
|
|
return product.cover1 || product.imagesUrl || product.cover2 || '';
|
|
|
};
|
|
|
|
|
|
const toArray = (obj) => {
|
|
|
if (_.isArray(obj)) {
|
|
|
return obj;
|
|
|
}
|
|
|
let arr = [];
|
|
|
|
|
|
_.forEach(obj, (v, k) => {
|
|
|
if (_.isObject(v)) {
|
|
|
v._key = k;
|
|
|
} else {
|
|
|
v = {
|
|
|
_key: k,
|
|
|
_value: v
|
|
|
};
|
|
|
}
|
|
|
arr.push(v);
|
|
|
});
|
|
|
|
|
|
return arr;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 按照数组中指定字段排序二维数组
|
|
|
*
|
...
|
...
|
@@ -27,8 +48,9 @@ const _procProductImg = (product, gender, yhChannel) => { |
|
|
* @param boolean 有 desc 时候降序排列,默认为false
|
|
|
*/
|
|
|
const _sortListByField = (list, key, desc) => {
|
|
|
list = _.toArray(list);
|
|
|
list = list.sort((a, b) => {
|
|
|
let array = toArray(list);
|
|
|
|
|
|
array = array.sort((a, b) => {
|
|
|
let matchNumber = /([\d]+)/g;
|
|
|
|
|
|
// 有键,使用键的值排序
|
...
|
...
|
@@ -40,12 +62,13 @@ const _sortListByField = (list, key, desc) => { |
|
|
}
|
|
|
|
|
|
// 无键, 使用本身
|
|
|
let numA = +(_.toArray(a.match(matchNumber))[0] || 0);
|
|
|
let numB = +(_.toArray(b.match(matchNumber))[0] || 0);
|
|
|
let numA = +(_.toArray(a._value.match(matchNumber))[0] || 0);
|
|
|
let numB = +(_.toArray(b._value.match(matchNumber))[0] || 0);
|
|
|
|
|
|
return numA < numB ? -1 : 1;
|
|
|
});
|
|
|
return list;
|
|
|
|
|
|
return array;
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -256,7 +279,11 @@ exports.processFilter = (list, options) => { |
|
|
_.forEach(item, (sub, index) => {
|
|
|
let subs = {};
|
|
|
|
|
|
if (filtersType[key].dataId === 'key') {
|
|
|
if (key === 'discount') {
|
|
|
subs.dataId = sub._key;
|
|
|
} else if (key === 'priceRange') {
|
|
|
subs.dataId = sub._key;
|
|
|
} else if (filtersType[key].dataId === 'key') {
|
|
|
subs.dataId = index;
|
|
|
} else if (filtersType[key].dataId === 'relationParameter') {
|
|
|
subs.dataId = sub.relationParameter['sort']; // eslint-disable-line
|
...
|
...
|
@@ -264,7 +291,9 @@ exports.processFilter = (list, options) => { |
|
|
subs.dataId = sub[filtersType[key].dataId];
|
|
|
}
|
|
|
|
|
|
if (filtersType[key].subsName === 'flag') {
|
|
|
if (key === 'priceRange') {
|
|
|
subs.name = sub._value;
|
|
|
} else if (filtersType[key].subsName === 'flag') {
|
|
|
subs.name = sub;
|
|
|
} else {
|
|
|
subs.name = sub[filtersType[key].subsName];
|
...
|
...
|
|