Authored by 姜敏

yohosearch搜索

@@ -319,18 +319,22 @@ var goodsgird = new common.grid({ @@ -319,18 +319,22 @@ var goodsgird = new common.grid({
319 el: '#goodsgird', 319 el: '#goodsgird',
320 parms: function() { 320 parms: function() {
321 return { 321 return {
322 - xxx: "",  
323 - xxx1: "", 322 + query:common.util.__input('skns')
324 }; 323 };
325 }, 324 },
326 columns: [{ 325 columns: [{
327 display: "选择", 326 display: "选择",
328 type: "checkbox" 327 type: "checkbox"
329 - }, { 328 + },{
330 display: "产品图片", 329 display: "产品图片",
331 render: function(item) { 330 render: function(item) {
332 - item.default_images = common.util.__joinImg("goodsimg", item.default_images)  
333 - return "<img width=120 height=60 src='" + item.default_images + "'/>"; 331 + if(item.default_images){
  332 + item.default_images=common.util.__joinImg("goodsimg",item.default_images);
  333 + }
  334 + else{
  335 + item.default_images="";
  336 + }
  337 + return "<img width=120 height=60 src='"+item.default_images+"'/>";
334 } 338 }
335 }, { 339 }, {
336 display: "产品名称", 340 display: "产品名称",
@@ -3,37 +3,40 @@ var _ = require('lodash'); @@ -3,37 +3,40 @@ var _ = require('lodash');
3 var fs = require('fs'); 3 var fs = require('fs');
4 var searchDomain = require('../../config/common.js').yohoSearch; 4 var searchDomain = require('../../config/common.js').yohoSearch;
5 5
6 -exports.getJSONFile=function(req,res){ 6 +exports.getJSONFile = function (req, res) {
7 request.get("http://192.168.102.208:8087/yohosearch/brand/list.json").pipe(res); 7 request.get("http://192.168.102.208:8087/yohosearch/brand/list.json").pipe(res);
8 } 8 }
9 9
10 -exports.search=function(req,res){  
11 - //req.body  
12 - var url="http://192.168.102.208:8087/yohosearch/search.json";//?viewNum=15&query=51022754,51178582  
13 - request({url: url}, function (error, response, body) {  
14 - var data={};  
15 - data.list=[];  
16 - body=JSON.parse(body);  
17 - var dataList=body.data.product_list;  
18 - var goodslist=[];  
19 - var goodslist1=[];  
20 - for(var m=0;m<dataList.length;m++){  
21 - for(var n=0;n<dataList[m].goods_list.length;n++){  
22 - goodslist.push({a:dataList[m],b:dataList[m].goods_list[n]})  
23 - }  
24 - }  
25 - for(var i=0;i<goodslist.length;i++){  
26 - goodslist1[i]= _.assign({},goodslist[i].a,goodslist[i].b);  
27 - }  
28 - data.list=goodslist1.concat();  
29 - //data.list=body.data.product_list;  
30 - data.total=data.list.length;  
31 - data.page=body.data.page;  
32 - data.size=5;  
33 - var a = (/^[1-9]\d*$/).test(data.total/data.size);  
34 - data.totalPage=a?parseInt(data.total/data.size):parseInt(data.total/data.size)+1;  
35 - res.json({data:{data:data}});  
36 - }); 10 +exports.search = function (req, res) {
  11 + var size = 10;//每页数据量
  12 + var page = 1;
  13 + if (req.body.page) {
  14 + page = req.body.page;
  15 + }
  16 + var url = "http://x.yohobuy.com//yohosearch/search.json?viewNum=" + size + "&query=" + req.body.query + "&page=" + page;
  17 + request({url: url}, function (error, response, body) {
  18 + var data = {};
  19 + data.list = [];
  20 + body = JSON.parse(body);
  21 + var dataList = body.data.product_list;
  22 + var goodslist = [];
  23 + var goodslist1 = [];
  24 + for (var m = 0; m < dataList.length; m++) {
  25 + for (var n = 0; n < dataList[m].goods_list.length; n++) {
  26 + goodslist.push({a: dataList[m], b: dataList[m].goods_list[n]})
  27 + }
  28 + }
  29 + for (var i = 0; i < goodslist.length; i++) {
  30 + goodslist1[i] = _.assign({}, goodslist[i].a, goodslist[i].b);
  31 + }
  32 + //data.list=body.data.product_list;
  33 + data.list = goodslist1.concat();//显示数据
  34 + data.page = body.data.page;//页码
  35 + data.totalPage = body.data.page_total;
  36 + data.nums = data.list.length;//记录每一页数据量
  37 + console.log("最终data", data);
  38 + res.json({data: {data: data}});
  39 + });
37 }; 40 };
38 41
39 42
@@ -400,12 +400,12 @@ @@ -400,12 +400,12 @@
400 <script type="text/template" id="template_dialog_goodsgird"> 400 <script type="text/template" id="template_dialog_goodsgird">
401 <div class="rows"> 401 <div class="rows">
402 <div class="form-group"> 402 <div class="form-group">
403 - <div class="col-sm-4">  
404 - <input class="form-control" placeholder="输入SKN" />  
405 - </div>  
406 - <div class="col-sm-4">  
407 - <input class="form-control" placeholder="输入标签" /> 403 + <div class="col-sm-6">
  404 + <input class="form-control" id="skns" placeholder="输入SKN(多个skn以逗号分隔)" />
408 </div> 405 </div>
  406 + <!--<div class="col-sm-4">-->
  407 + <!--<input class="form-control" placeholder="输入标签" />-->
  408 + <!--</div>-->
409 <div class="col-sm-1"> 409 <div class="col-sm-1">
410 <input type="button" id="search" class="btn btn-primary mr5" value="搜索" /> 410 <input type="button" id="search" class="btn btn-primary mr5" value="搜索" />
411 </div> 411 </div>