Showing
1 changed file
with
88 additions
and
90 deletions
@@ -29,105 +29,103 @@ const list = (req, res, next) => { | @@ -29,105 +29,103 @@ const list = (req, res, next) => { | ||
29 | params.shopId = params.shop_id; | 29 | params.shopId = params.shop_id; |
30 | } | 30 | } |
31 | 31 | ||
32 | - if (params.query) { | ||
33 | - return searchModel.searchKeyActivity(params.query).then(activityResult => { | ||
34 | - let activity = _.get(activityResult, 'urlobj.appUrl', ''); | ||
35 | - | ||
36 | - if (activity) { | ||
37 | - return res.redirect(activity); | ||
38 | - } else { | ||
39 | - | ||
40 | - /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */ | ||
41 | - return Promise.all([ | ||
42 | - searchModel.getAllBrandNames(), | ||
43 | - searchModel.getClassNames() | ||
44 | - ]).then(result => { | ||
45 | - if (query) { | ||
46 | - query = query.toLowerCase(); | ||
47 | - _.forEach(result[0], obj => { | ||
48 | - | ||
49 | - if (query === obj.brandDomain) { // 精确查品牌域名 | ||
50 | - domain = query; | ||
51 | - return false; | ||
52 | - } | ||
53 | - | ||
54 | - if (query === obj.brandName || query === obj.brandName || query === obj.brandName) { // 精确查品牌名称 | ||
55 | - domain = obj.brandDomain; | ||
56 | - return false; | ||
57 | - } | ||
58 | - | ||
59 | - // if (obj.brandDomain.indexOf(query) > 0) { // 模糊查品牌域名 | ||
60 | - // domain = obj.brandDomain; | ||
61 | - // return false; | ||
62 | - // } | ||
63 | - }); | ||
64 | - | ||
65 | - // 跳转到品牌商品列表页 | ||
66 | - if (domain !== null && !params.shop_id) { | ||
67 | - let url = helpers.urlFormat('', { | ||
68 | - from: 'search', | ||
69 | - query: query | ||
70 | - | ||
71 | - }, domain); | ||
72 | - | ||
73 | - return res.redirect(url); | 32 | + return searchModel.searchKeyActivity(params.query || '').then(activityResult => { |
33 | + let activity = _.get(activityResult, 'urlobj.appUrl', ''); | ||
34 | + | ||
35 | + if (activity) { | ||
36 | + return res.redirect(activity); | ||
37 | + } else { | ||
38 | + | ||
39 | + /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */ | ||
40 | + return Promise.all([ | ||
41 | + searchModel.getAllBrandNames(), | ||
42 | + searchModel.getClassNames() | ||
43 | + ]).then(result => { | ||
44 | + if (query) { | ||
45 | + query = query.toLowerCase(); | ||
46 | + _.forEach(result[0], obj => { | ||
47 | + | ||
48 | + if (query === obj.brandDomain) { // 精确查品牌域名 | ||
49 | + domain = query; | ||
50 | + return false; | ||
74 | } | 51 | } |
75 | 52 | ||
76 | - // 品类名称为空时跳出 | ||
77 | - if (!result[1]) { | ||
78 | - return; | 53 | + if (query === obj.brandName || query === obj.brandName || query === obj.brandName) { // 精确查品牌名称 |
54 | + domain = obj.brandDomain; | ||
55 | + return false; | ||
79 | } | 56 | } |
80 | 57 | ||
81 | - _.forEach(result[1].first, (obj) => { | ||
82 | - // 精确查一级品类 | ||
83 | - if (obj === query) { | ||
84 | - isQueryFirstClass = true; | ||
85 | - return false; | ||
86 | - } | ||
87 | - }); | ||
88 | - | ||
89 | - _.forEach(result[1].second, (obj) => { | ||
90 | - // 精确查二级品类 | ||
91 | - if (obj === query) { | ||
92 | - isQuerySecondClass = true; | ||
93 | - return false; | ||
94 | - } | ||
95 | - }); | ||
96 | - } else { | ||
97 | - params.query = ''; | 58 | + // if (obj.brandDomain.indexOf(query) > 0) { // 模糊查品牌域名 |
59 | + // domain = obj.brandDomain; | ||
60 | + // return false; | ||
61 | + // } | ||
62 | + }); | ||
63 | + | ||
64 | + // 跳转到品牌商品列表页 | ||
65 | + if (domain !== null && !params.shop_id) { | ||
66 | + let url = helpers.urlFormat('', { | ||
67 | + from: 'search', | ||
68 | + query: query | ||
69 | + | ||
70 | + }, domain); | ||
71 | + | ||
72 | + return res.redirect(url); | ||
98 | } | 73 | } |
99 | 74 | ||
100 | - // 搜索是一级品类 | ||
101 | - if (isQueryFirstClass) { | ||
102 | - title = '全部' + query; | ||
103 | - } else if (isQuerySecondClass) { // 搜索是二级品类 | ||
104 | - title = query; | ||
105 | - } else { // 搜索其它内容 | ||
106 | - if (query || params.form) { | ||
107 | - params.search = { | ||
108 | - default: query === '' ? false : query, | ||
109 | - url: helpers.urlFormat('', null, 'search') | ||
110 | - }; | ||
111 | - } | ||
112 | - title = '搜索'; | 75 | + // 品类名称为空时跳出 |
76 | + if (!result[1]) { | ||
77 | + return; | ||
113 | } | 78 | } |
114 | 79 | ||
115 | - title = params.title ? params.title : title; | ||
116 | - | ||
117 | - res.render('search/list', { | ||
118 | - module: 'product', | ||
119 | - page: 'search-list', | ||
120 | - pageHeader: headerModel.setNav({ | ||
121 | - navTitle: title | ||
122 | - }), | ||
123 | - title: title, | ||
124 | - goodList: params, | ||
125 | - pageFooter: true | 80 | + _.forEach(result[1].first, (obj) => { |
81 | + // 精确查一级品类 | ||
82 | + if (obj === query) { | ||
83 | + isQueryFirstClass = true; | ||
84 | + return false; | ||
85 | + } | ||
126 | }); | 86 | }); |
127 | - }).catch(next); | ||
128 | - } | ||
129 | - }); | ||
130 | - } | 87 | + |
88 | + _.forEach(result[1].second, (obj) => { | ||
89 | + // 精确查二级品类 | ||
90 | + if (obj === query) { | ||
91 | + isQuerySecondClass = true; | ||
92 | + return false; | ||
93 | + } | ||
94 | + }); | ||
95 | + } else { | ||
96 | + params.query = ''; | ||
97 | + } | ||
98 | + | ||
99 | + // 搜索是一级品类 | ||
100 | + if (isQueryFirstClass) { | ||
101 | + title = '全部' + query; | ||
102 | + } else if (isQuerySecondClass) { // 搜索是二级品类 | ||
103 | + title = query; | ||
104 | + } else { // 搜索其它内容 | ||
105 | + if (query || params.form) { | ||
106 | + params.search = { | ||
107 | + default: query === '' ? false : query, | ||
108 | + url: helpers.urlFormat('', null, 'search') | ||
109 | + }; | ||
110 | + } | ||
111 | + title = '搜索'; | ||
112 | + } | ||
113 | + | ||
114 | + title = params.title ? params.title : title; | ||
115 | + | ||
116 | + res.render('search/list', { | ||
117 | + module: 'product', | ||
118 | + page: 'search-list', | ||
119 | + pageHeader: headerModel.setNav({ | ||
120 | + navTitle: title | ||
121 | + }), | ||
122 | + title: title, | ||
123 | + goodList: params, | ||
124 | + pageFooter: true | ||
125 | + }); | ||
126 | + }).catch(next); | ||
127 | + } | ||
128 | + }); | ||
131 | }; | 129 | }; |
132 | 130 | ||
133 | /** | 131 | /** |
-
Please register or login to post a comment