diff --git a/pages/goods/search/index.js b/pages/goods/search/index.js
index c726041..b5f34ee 100644
--- a/pages/goods/search/index.js
+++ b/pages/goods/search/index.js
@@ -1,7 +1,7 @@
-import {
- getSearchHistory,
- getSearchPopular,
-} from '../../../services/good/fetchSearchHistory';
+import { getHistorySearchList } from '~/services/home/getHistorySearchList';
+import { getHotSearchList } from '~/services/home/getHotSearchList';
+import { addHistorySearch } from '~/services/home/addHistorySearch';
+import { deleteHistorySearch } from '~/services/home/deleteHistorySearch';
Page({
data: {
@@ -9,7 +9,6 @@ Page({
popularWords: [],
searchValue: '',
dialog: {
- title: '确认删除当前历史记录',
showCancelButton: true,
message: '',
},
@@ -26,50 +25,61 @@ Page({
async queryHistory() {
try {
- const data = await getSearchHistory();
- const code = 'Success';
- if (String(code).toUpperCase() === 'SUCCESS') {
- const { historyWords = [] } = data;
- this.setData({
- historyWords,
- });
- }
+ getHistorySearchList().then((res) => {
+ if (res.code == 200) {
+ this.setData({
+ historyWords: res.data,
+ });
+ } else {
+ console.log(res.msg);
+ }
+ });
} catch (error) {
- console.error(error);
+ console.log(error);
}
},
async queryPopular() {
try {
- const data = await getSearchPopular();
- const code = 'Success';
- if (String(code).toUpperCase() === 'SUCCESS') {
- const { popularWords = [] } = data;
- this.setData({
- popularWords,
- });
- }
+ getHotSearchList().then((res) => {
+ if (res.code == 200) {
+ this.setData({
+ popularWords: res.data,
+ });
+ } else {
+ console.log(res.msg);
+ }
+ });
} catch (error) {
- console.error(error);
+ console.log(error);
}
},
confirm() {
const { historyWords } = this.data;
const { deleteType, deleteIndex } = this;
- historyWords.splice(deleteIndex, 1);
+ // console.log('deleteType', deleteType, 'deleteIndex', deleteIndex);
+ // console.log(historyWords);
if (deleteType === 0) {
+ const deleteWord = historyWords[deleteIndex];
+ historyWords.splice(deleteIndex, 1);
this.setData({
historyWords,
dialogShow: false,
});
+ deleteHistorySearch(deleteWord.historySearchId);
} else {
- this.setData({ historyWords: [], dialogShow: false });
+ this.setData({
+ historyWords: [],
+ dialogShow: false,
+ });
}
},
close() {
- this.setData({ dialogShow: false });
+ this.setData({
+ dialogShow: false,
+ });
},
handleClearHistory() {
@@ -109,9 +119,16 @@ Page({
}
},
+ // TODO:提交搜索
handleSubmit(e) {
const { value } = e.detail.value;
- if (value.length === 0) return;
+ if (value?.length === 0) return;
+ const data = {
+ HistorySearchContent: e.detail.value,
+ };
+ addHistorySearch(data).then((res) => {
+ this.queryHistory();
+ });
wx.navigateTo({
url: `/pages/goods/result/index?searchValue=${value}`,
});
diff --git a/pages/goods/search/index.wxml b/pages/goods/search/index.wxml
index b50c96d..9c924ad 100644
--- a/pages/goods/search/index.wxml
+++ b/pages/goods/search/index.wxml
@@ -1,13 +1,5 @@
-
+
@@ -17,45 +9,32 @@
清除
-
- {{item}}
+
+
+ {{item.historySearchContent}}
+
+
+
+ 暂无数据
+
-
- {{item}}
+
+
+ {{item.searchTerm}}
+
+
+
+ 暂无数据
-
-
+
+
\ No newline at end of file
diff --git a/pages/home/home.js b/pages/home/home.js
index 0937265..578b3a3 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -1,5 +1,6 @@
import { fetchHome } from '~/services/home/home';
import { fetchGoodsList } from '~/services/good/fetchGoods';
+import { getbannerList } from '~/services/home/getbannerList';
import Toast from 'tdesign-miniprogram/toast/index';
Page({
@@ -58,10 +59,20 @@ Page({
this.setData({
pageLoading: true,
});
+
+ // 获取轮播图列表
+ getbannerList().then((res) => {
+ if (res.code == 200) {
+ this.setData({
+ imgSrcs: res.data.map((v) => v.bannerImg),
+ });
+ }
+ });
+
fetchHome().then(({ swiper, tabList }) => {
this.setData({
tabList,
- imgSrcs: swiper,
+ // imgSrcs: swiper,
pageLoading: false,
});
this.loadGoodsList(true);
diff --git a/services/home/addHistorySearch.js b/services/home/addHistorySearch.js
new file mode 100644
index 0000000..ab3c016
--- /dev/null
+++ b/services/home/addHistorySearch.js
@@ -0,0 +1,21 @@
+import {
+ request
+} from '~/services/_utils/request';
+
+
+/** 添加历史搜索 */
+export function addHistorySearch(data) {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `HistorySearchApi/addHistorySearch`,
+ method: 'POST',
+ data: data,
+ success: function (res) {
+ resolve(res);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
+ });
+}
\ No newline at end of file
diff --git a/services/home/deleteHistorySearch.js b/services/home/deleteHistorySearch.js
new file mode 100644
index 0000000..dcffbcd
--- /dev/null
+++ b/services/home/deleteHistorySearch.js
@@ -0,0 +1,17 @@
+import { request } from '~/services/_utils/request';
+
+/** 删除历史搜索 */
+export function deleteHistorySearch(ids) {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `HistorySearchApi/` + ids,
+ method: 'DELETE',
+ success: function (res) {
+ resolve(res);
+ },
+ fail: function (error) {
+ reject(error);
+ },
+ });
+ });
+}
diff --git a/services/home/getHistorySearchList.js b/services/home/getHistorySearchList.js
new file mode 100644
index 0000000..20a9b3c
--- /dev/null
+++ b/services/home/getHistorySearchList.js
@@ -0,0 +1,19 @@
+import {
+ request
+} from '../_utils/request';
+
+/** 获取历史搜索列表 */
+export function getHistorySearchList() {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `HistorySearchApi/getHistorySearchList`,
+ method: 'GET',
+ success: function (res) {
+ resolve(res);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
+ });
+}
\ No newline at end of file
diff --git a/services/home/getHotSearchList.js b/services/home/getHotSearchList.js
new file mode 100644
index 0000000..9990b4f
--- /dev/null
+++ b/services/home/getHotSearchList.js
@@ -0,0 +1,17 @@
+import { request } from '../_utils/request';
+
+/** 获取热门搜索列表 */
+export function getHotSearchList() {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `HistorySearchApi/getHotSearchList`,
+ method: 'GET',
+ success: function (res) {
+ resolve(res);
+ },
+ fail: function (error) {
+ reject(error);
+ },
+ });
+ });
+}
diff --git a/services/home/getbannerList.js b/services/home/getbannerList.js
new file mode 100644
index 0000000..d43a9e8
--- /dev/null
+++ b/services/home/getbannerList.js
@@ -0,0 +1,19 @@
+import {
+ request
+} from '../_utils/request';
+
+/** 获取轮播图列表 */
+export function getbannerList() {
+ return new Promise((resolve, reject) => {
+ request({
+ url: `BannerApi/getBannerList?BannerPosition=1`,
+ method: 'GET',
+ success: function (res) {
+ resolve(res);
+ },
+ fail: function (error) {
+ reject(error);
+ }
+ });
+ });
+}
\ No newline at end of file