Authored by 姜枫

fix price search, when max value is empty

... ... @@ -143,10 +143,18 @@ const helpers = {
if (!matchPrice && q.price) {
let prices = q.price.split(',');
let priceTxt = ${prices[0]}-¥${prices[1]}`;
filters.push(this.newFilter('price', q.price, ${prices[0]}-¥${prices[1]}`));
customPriceLow = prices[0];
customPriceHigh = prices[1];
if (prices[1] === Number.MAX_SAFE_INTEGER.toString()) {
priceTxt = `大于¥${prices[0]}`;
customPriceHigh = '';
}
filters.push(this.newFilter('price', q.price, priceTxt));
}
}
... ...
... ... @@ -3,12 +3,22 @@
const api = global.yoho.API;
const _ = require('lodash');
function clearEmptyVal(obj) {
function _paramHanlde(obj) {
_.keys(obj).forEach(k => {
if (obj[k] === null || obj[k] === '') {
_.unset(obj, k);
}
});
if (obj.price) {
let prices = obj.price.split(',');
if (!prices[1]) {
prices[1] = Number.MAX_SAFE_INTEGER;
obj.price = prices.join(',');
}
}
return obj;
}
... ... @@ -20,7 +30,7 @@ const Search = {
limit: 45
};
Object.assign(finalParams, clearEmptyVal(params));
Object.assign(finalParams, _paramHanlde(params));
return api.get('', finalParams);
},
... ... @@ -30,7 +40,7 @@ const Search = {
limit: 45
};
Object.assign(finalParams, clearEmptyVal(params));
Object.assign(finalParams, _paramHanlde(params));
return api.get('', finalParams);
},
... ... @@ -40,7 +50,7 @@ const Search = {
limit: 45
};
Object.assign(finalParams, clearEmptyVal(params));
Object.assign(finalParams, _paramHanlde(params));
return api.get('', finalParams);
},
... ...
... ... @@ -117,7 +117,7 @@ var YohoListPage = {
});
$('.price-btns .confirm', this.rootDoc).click(function() {
var priceLow = $('.price-low', $(this).parent()).val() || '';
var priceLow = $('.price-low', $(this).parent()).val() || 0;
var priceHigh = $('.price-high', $(this).parent()).val() || '';
if (priceLow > 0 || priceHigh > 0) {
... ...