|
@@ -3,203 +3,224 @@ var api = require('../../config/api.js');
|
|
|
|
|
|
var app = getApp()
|
|
|
Page({
|
|
|
- data: {
|
|
|
- keywrod: '',
|
|
|
- searchStatus: false,
|
|
|
- goodsList: [],
|
|
|
- helpKeyword: [],
|
|
|
- historyKeyword: [],
|
|
|
- categoryFilter: false,
|
|
|
- filterCategory: [],
|
|
|
- defaultKeyword: {},
|
|
|
- hotKeyword: [],
|
|
|
- page: 1,
|
|
|
- size: 1000,
|
|
|
- currentSortType: 'id',
|
|
|
- currentSortOrder: 'desc',
|
|
|
- categoryId: 0,
|
|
|
- showNavList: false,
|
|
|
- footCart: {}
|
|
|
- },
|
|
|
- toggleNav() {
|
|
|
- this.setData({
|
|
|
- showNavList: !this.data.showNavList
|
|
|
- })
|
|
|
- },
|
|
|
- switchNav(event) {
|
|
|
- let name = event.currentTarget.dataset.name;
|
|
|
- wx.switchTab({
|
|
|
- url: `/pages/${name}/${name}`,
|
|
|
- });
|
|
|
- },
|
|
|
- //事件处理函数
|
|
|
- closeSearch: function () {
|
|
|
- wx.navigateBack()
|
|
|
- },
|
|
|
- clearKeyword: function () {
|
|
|
- this.setData({
|
|
|
- keyword: '',
|
|
|
- searchStatus: false
|
|
|
- });
|
|
|
- },
|
|
|
- onLoad: function () {
|
|
|
- this.getSearchKeyword();
|
|
|
- this.getFootCart();
|
|
|
- },
|
|
|
+ data: {
|
|
|
+ keywrod: '',
|
|
|
+ searchStatus: false,
|
|
|
+ goodsList: [],
|
|
|
+ helpKeyword: [],
|
|
|
+ historyKeyword: [],
|
|
|
+ categoryFilter: false,
|
|
|
+ filterCategory: [],
|
|
|
+ defaultKeyword: {},
|
|
|
+ hotKeyword: [],
|
|
|
+ page: 1,
|
|
|
+ size: 1000,
|
|
|
+ currentSortType: 'id',
|
|
|
+ currentSortOrder: 'desc',
|
|
|
+ categoryId: 0,
|
|
|
+ showNavList: false,
|
|
|
+ footCart: {},
|
|
|
+ page: 1,
|
|
|
+ size: 6
|
|
|
+ },
|
|
|
+ toggleNav() {
|
|
|
+ this.setData({
|
|
|
+ showNavList: !this.data.showNavList
|
|
|
+ })
|
|
|
+ },
|
|
|
+ switchNav(event) {
|
|
|
+ let name = event.currentTarget.dataset.name;
|
|
|
+ wx.switchTab({
|
|
|
+ url: `/pages/${name}/${name}`,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //事件处理函数
|
|
|
+ closeSearch: function () {
|
|
|
+ wx.navigateBack()
|
|
|
+ },
|
|
|
+ clearKeyword: function () {
|
|
|
+ this.setData({
|
|
|
+ keyword: '',
|
|
|
+ searchStatus: false
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onLoad: function () {
|
|
|
+ this.getSearchKeyword();
|
|
|
+ this.getFootCart();
|
|
|
+ },
|
|
|
|
|
|
- getFootCart: function () {
|
|
|
- let that = this;
|
|
|
- util.request(api.GetFootCart).then(function (res) {
|
|
|
- if (res.errno === 0) {
|
|
|
- that.setData({
|
|
|
- footCart: res.data,
|
|
|
- });
|
|
|
- }
|
|
|
+ getFootCart: function () {
|
|
|
+ let that = this;
|
|
|
+ util.request(api.GetFootCart).then(function (res) {
|
|
|
+ if (res.errno === 0) {
|
|
|
+ that.setData({
|
|
|
+ footCart: res.data,
|
|
|
});
|
|
|
- },
|
|
|
- getSearchKeyword() {
|
|
|
- let that = this;
|
|
|
- util.request(api.SearchIndex).then(function (res) {
|
|
|
- if (res.errno === 0) {
|
|
|
- that.setData({
|
|
|
- historyKeyword: res.data.historyKeywordList,
|
|
|
- defaultKeyword: res.data.defaultKeyword,
|
|
|
- hotKeyword: res.data.hotKeywordList
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getSearchKeyword() {
|
|
|
+ let that = this;
|
|
|
+ util.request(api.SearchIndex).then(function (res) {
|
|
|
+ if (res.errno === 0) {
|
|
|
+ that.setData({
|
|
|
+ historyKeyword: res.data.historyKeywordList,
|
|
|
+ defaultKeyword: res.data.defaultKeyword,
|
|
|
+ hotKeyword: res.data.hotKeywordList
|
|
|
});
|
|
|
- },
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
- inputChange: function (e) {
|
|
|
+ inputChange: function (e) {
|
|
|
|
|
|
- this.setData({
|
|
|
- keyword: e.detail.value,
|
|
|
- searchStatus: false
|
|
|
- });
|
|
|
- this.getHelpKeyword();
|
|
|
- },
|
|
|
- getHelpKeyword: function () {
|
|
|
- let that = this;
|
|
|
- util.request(api.SearchHelper, { keyword: that.data.keyword }).then(function (res) {
|
|
|
- if (res.errno === 0) {
|
|
|
- that.setData({
|
|
|
- helpKeyword: res.data
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- inputFocus: function () {
|
|
|
- this.setData({
|
|
|
- searchStatus: false,
|
|
|
- goodsList: []
|
|
|
+ this.setData({
|
|
|
+ keyword: e.detail.value,
|
|
|
+ searchStatus: false
|
|
|
+ });
|
|
|
+ this.getHelpKeyword();
|
|
|
+ },
|
|
|
+ getHelpKeyword: function () {
|
|
|
+ let that = this;
|
|
|
+ util.request(api.SearchHelper, { keyword: that.data.keyword }).then(function (res) {
|
|
|
+ if (res.errno === 0) {
|
|
|
+ that.setData({
|
|
|
+ helpKeyword: res.data
|
|
|
});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ inputFocus: function () {
|
|
|
+ this.setData({
|
|
|
+ searchStatus: false,
|
|
|
+ goodsList: []
|
|
|
+ });
|
|
|
|
|
|
- if (this.data.keyword) {
|
|
|
- this.getHelpKeyword();
|
|
|
- }
|
|
|
- },
|
|
|
- clearHistory: function () {
|
|
|
- this.setData({
|
|
|
- historyKeyword: []
|
|
|
- })
|
|
|
+ if (this.data.keyword) {
|
|
|
+ this.getHelpKeyword();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ clearHistory: function () {
|
|
|
+ this.setData({
|
|
|
+ historyKeyword: []
|
|
|
+ })
|
|
|
|
|
|
- util.request(api.SearchClearHistory, {}, 'POST')
|
|
|
- .then(function (res) {
|
|
|
- console.log('清除成功');
|
|
|
- });
|
|
|
- },
|
|
|
- getGoodsList: function () {
|
|
|
- let that = this;
|
|
|
- wx.showLoading({
|
|
|
- title: '加载中...',
|
|
|
+ util.request(api.SearchClearHistory, {}, 'POST')
|
|
|
+ .then(function (res) {
|
|
|
+ console.log('清除成功');
|
|
|
});
|
|
|
- util.request(api.GoodsList, { keyword: that.data.keyword, page: that.data.page, size: that.data.size, sort: that.data.currentSortType, order: that.data.currentSortOrder, categoryId: that.data.categoryId,
|
|
|
- storeId:wx.getStorageSync("storeId")}).then(function (res) {
|
|
|
- if (res.errno === 0) {
|
|
|
- that.setData({
|
|
|
- searchStatus: true,
|
|
|
- categoryFilter: false,
|
|
|
- goodsList: res.data.data,
|
|
|
- filterCategory: res.data.filterCategory,
|
|
|
- page: res.data.currentPage,
|
|
|
- size: res.data.numsPerPage
|
|
|
- });
|
|
|
- wx.hideLoading();
|
|
|
- }
|
|
|
-
|
|
|
- //重新获取关键词
|
|
|
- that.getSearchKeyword();
|
|
|
+ },
|
|
|
+ getGoodsList: function () {
|
|
|
+ let that = this;
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中...',
|
|
|
+ });
|
|
|
+ util.request(api.GoodsList, {
|
|
|
+ keyword: that.data.keyword, page: that.data.page, size: that.data.size, sort: that.data.currentSortType, order: that.data.currentSortOrder, categoryId: that.data.categoryId,
|
|
|
+ storeId: wx.getStorageSync("storeId")
|
|
|
+ }).then(function (res) {
|
|
|
+ if (res.errno === 0) {
|
|
|
+ let goodsList = that.data.goodsList.concat(res.data.data);
|
|
|
+ that.setData({
|
|
|
+ searchStatus: true,
|
|
|
+ categoryFilter: false,
|
|
|
+ goodsList: goodsList,
|
|
|
+ filterCategory: res.data.filterCategory,
|
|
|
+ page: res.data.currentPage,
|
|
|
+ size: res.data.numsPerPage
|
|
|
});
|
|
|
- },
|
|
|
- onKeywordTap: function (event) {
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+
|
|
|
+ //重新获取关键词
|
|
|
+ that.getSearchKeyword();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onKeywordTap: function (event) {
|
|
|
|
|
|
- this.getSearchResult(event.target.dataset.keyword);
|
|
|
+ this.getSearchResult(event.target.dataset.keyword);
|
|
|
|
|
|
- },
|
|
|
- getSearchResult(keyword) {
|
|
|
+ },
|
|
|
+ getSearchResult(keyword) {
|
|
|
+ this.setData({
|
|
|
+ keyword: keyword,
|
|
|
+ categoryId: 0,
|
|
|
+ page: 1,
|
|
|
+ goodsList: []
|
|
|
+ });
|
|
|
+
|
|
|
+ this.getGoodsList();
|
|
|
+ },
|
|
|
+ openSortFilter: function (event) {
|
|
|
+ let currentId = event.currentTarget.id;
|
|
|
+ switch (currentId) {
|
|
|
+ case 'categoryFilter':
|
|
|
this.setData({
|
|
|
- keyword: keyword,
|
|
|
- page: 1,
|
|
|
- categoryId: 0,
|
|
|
- goodsList: []
|
|
|
+ 'categoryFilter': !this.data.categoryFilter,
|
|
|
+ 'currentSortOrder': 'asc'
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 'priceSort':
|
|
|
+ let tmpSortOrder = 'asc';
|
|
|
+ if (this.data.currentSortOrder == 'asc') {
|
|
|
+ tmpSortOrder = 'desc';
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ 'currentSortType': 'price',
|
|
|
+ 'currentSortOrder': tmpSortOrder,
|
|
|
+ 'categoryFilter': false,
|
|
|
+ page: 1,
|
|
|
+ goodsList: []
|
|
|
});
|
|
|
|
|
|
this.getGoodsList();
|
|
|
- },
|
|
|
- openSortFilter: function (event) {
|
|
|
- let currentId = event.currentTarget.id;
|
|
|
- switch (currentId) {
|
|
|
- case 'categoryFilter':
|
|
|
- this.setData({
|
|
|
- 'categoryFilter': !this.data.categoryFilter,
|
|
|
- 'currentSortOrder': 'asc'
|
|
|
- });
|
|
|
- break;
|
|
|
- case 'priceSort':
|
|
|
- let tmpSortOrder = 'asc';
|
|
|
- if (this.data.currentSortOrder == 'asc') {
|
|
|
- tmpSortOrder = 'desc';
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- 'currentSortType': 'price',
|
|
|
- 'currentSortOrder': tmpSortOrder,
|
|
|
- 'categoryFilter': false
|
|
|
- });
|
|
|
-
|
|
|
- this.getGoodsList();
|
|
|
- break;
|
|
|
- default:
|
|
|
- //综合排序
|
|
|
- this.setData({
|
|
|
- 'currentSortType': 'default',
|
|
|
- 'currentSortOrder': 'desc',
|
|
|
- 'categoryFilter': false
|
|
|
- });
|
|
|
- this.getGoodsList();
|
|
|
- }
|
|
|
- },
|
|
|
- selectCategory: function (event) {
|
|
|
- let currentIndex = event.target.dataset.categoryIndex;
|
|
|
- let filterCategory = this.data.filterCategory;
|
|
|
- let currentCategory = null;
|
|
|
- for (let key in filterCategory) {
|
|
|
- if (key == currentIndex) {
|
|
|
- filterCategory[key].selected = true;
|
|
|
- currentCategory = filterCategory[key];
|
|
|
- } else {
|
|
|
- filterCategory[key].selected = false;
|
|
|
- }
|
|
|
- }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //综合排序
|
|
|
this.setData({
|
|
|
- 'filterCategory': filterCategory,
|
|
|
- 'categoryFilter': false,
|
|
|
- categoryId: currentCategory.id,
|
|
|
- page: 1,
|
|
|
- goodsList: []
|
|
|
+ 'currentSortType': 'default',
|
|
|
+ 'currentSortOrder': 'desc',
|
|
|
+ 'categoryFilter': false,
|
|
|
+ page: 1,
|
|
|
+ goodsList: []
|
|
|
});
|
|
|
this.getGoodsList();
|
|
|
- },
|
|
|
- onKeywordConfirm(event) {
|
|
|
- this.getSearchResult(event.detail.value);
|
|
|
}
|
|
|
+ },
|
|
|
+ selectCategory: function (event) {
|
|
|
+ let currentIndex = event.target.dataset.categoryIndex;
|
|
|
+ let filterCategory = this.data.filterCategory;
|
|
|
+ let currentCategory = null;
|
|
|
+ for (let key in filterCategory) {
|
|
|
+ if (key == currentIndex) {
|
|
|
+ filterCategory[key].selected = true;
|
|
|
+ currentCategory = filterCategory[key];
|
|
|
+ } else {
|
|
|
+ filterCategory[key].selected = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ 'filterCategory': filterCategory,
|
|
|
+ 'categoryFilter': false,
|
|
|
+ categoryId: currentCategory.id,
|
|
|
+ page: 1,
|
|
|
+ goodsList: []
|
|
|
+ });
|
|
|
+ this.getGoodsList();
|
|
|
+ },
|
|
|
+ onKeywordConfirm(event) {
|
|
|
+ this.getSearchResult(event.detail.value);
|
|
|
+ },
|
|
|
+ onReachBottom() {
|
|
|
+ var that = this;
|
|
|
+ if (!that.data.goodsList) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中...',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ page: that.data.page + 1
|
|
|
+ });
|
|
|
+ that.getGoodsList();
|
|
|
+ }
|
|
|
})
|