...
|
...
|
@@ -644,21 +644,20 @@ function parseProductList(json) { |
|
|
isSelect: false,
|
|
|
});
|
|
|
let priceObject = filter['priceRange'];
|
|
|
priceObject = sortListByField(priceObject, 'name'); // 折扣,价格区间,需要排序
|
|
|
let newPriceList = [];
|
|
|
newPriceList.push({
|
|
|
key: '',
|
|
|
name: '所有价格',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
for (var price in priceObject) {
|
|
|
if (priceObject.hasOwnProperty(price)) {
|
|
|
newPriceList.push({
|
|
|
key: price,
|
|
|
name: priceObject[price],
|
|
|
isSelect: false,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
_.forEach(priceObject, (v, k) => {
|
|
|
newPriceList.push({
|
|
|
key: v._key,
|
|
|
name: v._value,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
});
|
|
|
filterCategoryDetailFilterList.price;
|
|
|
filterCategoryDetailFilterList.price = newPriceList;
|
|
|
}
|
...
|
...
|
@@ -670,21 +669,20 @@ function parseProductList(json) { |
|
|
isSelect: false,
|
|
|
});
|
|
|
let p_dObject = filter['discount'];
|
|
|
p_dObject = sortListByField(p_dObject, 'name'); // 折扣,价格区间,需要排序
|
|
|
let newP_dList = [];
|
|
|
newP_dList.push({
|
|
|
key: '',
|
|
|
name: '所有折扣',
|
|
|
isSelect: true,
|
|
|
});
|
|
|
for (var p_d in p_dObject) {
|
|
|
if (p_dObject.hasOwnProperty(p_d)) {
|
|
|
newP_dList.push({
|
|
|
key: p_d,
|
|
|
name: p_dObject[p_d].name,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
_.forEach(p_dObject, (v, k) => {
|
|
|
newP_dList.push({
|
|
|
key: v._key,
|
|
|
name: v.name,
|
|
|
isSelect: false,
|
|
|
});
|
|
|
});
|
|
|
filterCategoryDetailFilterList.p_d;
|
|
|
filterCategoryDetailFilterList.p_d = newP_dList;
|
|
|
}
|
...
|
...
|
@@ -701,6 +699,59 @@ function parseProductList(json) { |
|
|
}
|
|
|
|
|
|
|
|
|
function 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照数组中指定字段排序二维数组
|
|
|
*
|
|
|
* @param array list 需要排序的数组
|
|
|
* @param string key 字段名称
|
|
|
* @param boolean 有 desc 时候降序排列,默认为false
|
|
|
*/
|
|
|
function sortListByField(list, key, desc) {
|
|
|
let array = toArray(list);
|
|
|
|
|
|
array = array.sort((a, b) => {
|
|
|
let matchNumber = /([\d]+)/g;
|
|
|
|
|
|
// 有键,使用键的值排序
|
|
|
if (a[key] && b[key]) {
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
// 无键, 使用本身
|
|
|
let numA = +(_.toArray(a._value.match(matchNumber))[0] || 0);
|
|
|
let numB = +(_.toArray(b._value.match(matchNumber))[0] || 0);
|
|
|
|
|
|
return numA < numB ? -1 : 1;
|
|
|
});
|
|
|
|
|
|
return array;
|
|
|
}
|
|
|
|
|
|
|
|
|
export function productListForPersonRequest() {
|
|
|
return {
|
|
|
type: PRODUCT_LIST_FORPERSON_REQUEST,
|
...
|
...
|
|