Authored by weiqingting

提交

... ... @@ -14,32 +14,39 @@ exports.search = function (req, res) {
params.push(key + "=" + encodeURI(req.body[key]));
}
var url = searchDomain + "/search.json?viewNum=" + size + "&" + params.join('&');
console.log(url);
request({url: url}, function (error, response, body) {
request({url: url}, function (error, httpResponse, body) {
var data = {};
data.list = [];
body = JSON.parse(body);
var dataList = body.data.product_list;
var goodslist = [];
var goodslist1 = [];
for (var m = 0; m < dataList.length; m++) {
if(dataList[m].goods_list&&dataList[m].goods_list.length!=0){
for (var n = 0; n < dataList[m].goods_list.length; n++) {
goodslist.push({a: dataList[m], b: dataList[m].goods_list[n]})
if (!error && httpResponse.statusCode == 200) {
try{
body = JSON.parse(body);
var dataList = body.data.product_list;
var goodslist = [];
var goodslist1 = [];
for (var m = 0; m < dataList.length; m++) {
if(dataList[m].goods_list&&dataList[m].goods_list.length!=0){
for (var n = 0; n < dataList[m].goods_list.length; n++) {
goodslist.push({a: dataList[m], b: dataList[m].goods_list[n]})
}
}else{
goodslist.push({a: dataList[m],b:{}});
}
}
}else{
goodslist.push({a: dataList[m],b:{}});
for (var i = 0; i < goodslist.length; i++) {
goodslist1[i] = _.assign({}, goodslist[i].a, goodslist[i].b);
}
data.list = goodslist1.concat();//显示数据
data.page = body.data.page;//页码
data.totalPage = 1;//body.data.page_total;
data.nums = data.list.length;//记录每一页数据量
//console.log("最终data", data);
res.json({data: {data: data, code: 200}});
}catch(ex){
res.json({data: {data: data, code: 500}});
}
}else{
res.json({data: {data: data, code: 500}});
}
for (var i = 0; i < goodslist.length; i++) {
goodslist1[i] = _.assign({}, goodslist[i].a, goodslist[i].b);
}
data.list = goodslist1.concat();//显示数据
data.page = body.data.page;//页码
data.totalPage = 1;//body.data.page_total;
data.nums = data.list.length;//记录每一页数据量
//console.log("最终data", data);
res.json({data: {data: data, code: 200}});
});
};
... ...