...
|
...
|
@@ -11,6 +11,7 @@ |
|
|
const filter = require('plugin/filter');
|
|
|
const noResultHbs = require('product/search/no-result-new.hbs');
|
|
|
const lazyLoad = require('yoho-jquery-lazyload');
|
|
|
const cacheStore = require('./cache-store');
|
|
|
|
|
|
class ProductListWithFilter {
|
|
|
constructor(filterParams, searchUrl, extra) {
|
...
|
...
|
@@ -101,6 +102,42 @@ class ProductListWithFilter { |
|
|
});
|
|
|
}
|
|
|
|
|
|
dataRender(result) {
|
|
|
|
|
|
// 去掉正在加载
|
|
|
$('.search-divide').remove();
|
|
|
|
|
|
let noResult = !result || result.length < 1 || (result.list && result.list.length < 1);
|
|
|
|
|
|
// 没有结果输出没有结果页面
|
|
|
if (noResult) {
|
|
|
if (this.isScrollLoad) {
|
|
|
this.view.container.after(() => {
|
|
|
return '<div class="search-divide">没有更多内容了...</div>';
|
|
|
});
|
|
|
} else {
|
|
|
this.view.container.html(noResultHbs());
|
|
|
}
|
|
|
|
|
|
if (this.nav) {
|
|
|
this.nav.end = true;
|
|
|
}
|
|
|
|
|
|
this.onSearching = false;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (this.isScrollLoad) {
|
|
|
this.view.container.append(result);
|
|
|
} else {
|
|
|
this.view.container.html(result);
|
|
|
}
|
|
|
|
|
|
lazyLoad(this.view.container.find('img[class=lazy]').not('img[src]'));
|
|
|
|
|
|
this.onSearching = false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表
|
|
|
*/
|
...
|
...
|
@@ -128,6 +165,8 @@ class ProductListWithFilter { |
|
|
}
|
|
|
|
|
|
if (!this.onSearching) {
|
|
|
let catchKey = this.searchUrl + '?' + $.param(this.defaultOpt);
|
|
|
|
|
|
this.onSearching = true;
|
|
|
|
|
|
$.ajax({
|
...
|
...
|
@@ -138,46 +177,24 @@ class ProductListWithFilter { |
|
|
withCredentials: true
|
|
|
},
|
|
|
beforeSend: () => {
|
|
|
let cacheData = cacheStore.get(catchKey);
|
|
|
|
|
|
if (cacheData) {
|
|
|
this.dataRender(cacheData);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if ($('.no-result-new').length > 0) {
|
|
|
$('.no-result-new').remove();
|
|
|
}
|
|
|
|
|
|
this.view.container.after(() => {
|
|
|
return '<div class="search-divide">正在加载...</div>';
|
|
|
});
|
|
|
},
|
|
|
success: (result) => {
|
|
|
// 去掉正在加载
|
|
|
$('.search-divide').remove();
|
|
|
|
|
|
let noResult = !result || result.length < 1 || (result.list && result.list.length < 1);
|
|
|
|
|
|
// 没有结果输出没有结果页面
|
|
|
if (noResult) {
|
|
|
if (this.isScrollLoad) {
|
|
|
this.view.container.after(() => {
|
|
|
return '<div class="search-divide">没有更多内容了...</div>';
|
|
|
});
|
|
|
} else {
|
|
|
this.view.container.html(noResultHbs());
|
|
|
}
|
|
|
|
|
|
if (this.nav) {
|
|
|
this.nav.end = true;
|
|
|
}
|
|
|
|
|
|
this.onSearching = false;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (this.isScrollLoad) {
|
|
|
this.view.container.append(result);
|
|
|
} else {
|
|
|
this.view.container.html(result);
|
|
|
}
|
|
|
|
|
|
lazyLoad(this.view.container.find('img[class=lazy]').not('img[src]'));
|
|
|
|
|
|
this.onSearching = false;
|
|
|
cacheStore.set(catchKey, result);
|
|
|
this.dataRender(result);
|
|
|
},
|
|
|
error: () => {
|
|
|
let $divide = $('.search-divide');
|
...
|
...
|
|