1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| import {
| getSearchHistory,
| getSearchPopular,
| } from '../../../services/good/fetchSearchHistory';
|
| Page({
| data: {
| historyWords: [],
| popularWords: [],
| searchValue: '',
| dialog: {
| title: '确认删除当前历史记录',
| showCancelButton: true,
| message: '',
| },
| dialogShow: false,
| },
|
| deleteType: 0,
| deleteIndex: '',
|
| onShow() {
| this.queryHistory();
| this.queryPopular();
| },
|
| async queryHistory() {
| try {
| const data = await getSearchHistory();
| const code = 'Success';
| if (String(code).toUpperCase() === 'SUCCESS') {
| const { historyWords = [] } = data;
| this.setData({
| historyWords,
| });
| }
| } catch (error) {
| console.error(error);
| }
| },
|
| async queryPopular() {
| try {
| const data = await getSearchPopular();
| const code = 'Success';
| if (String(code).toUpperCase() === 'SUCCESS') {
| const { popularWords = [] } = data;
| this.setData({
| popularWords,
| });
| }
| } catch (error) {
| console.error(error);
| }
| },
|
| confirm() {
| const { historyWords } = this.data;
| const { deleteType, deleteIndex } = this;
| historyWords.splice(deleteIndex, 1);
| if (deleteType === 0) {
| this.setData({
| historyWords,
| dialogShow: false,
| });
| } else {
| this.setData({ historyWords: [], dialogShow: false });
| }
| },
|
| close() {
| this.setData({ dialogShow: false });
| },
|
| handleClearHistory() {
| const { dialog } = this.data;
| this.deleteType = 1;
| this.setData({
| dialog: {
| ...dialog,
| message: '确认删除所有历史记录',
| },
| dialogShow: true,
| });
| },
|
| deleteCurr(e) {
| const { index } = e.currentTarget.dataset;
| const { dialog } = this.data;
| this.deleteIndex = index;
| this.setData({
| dialog: {
| ...dialog,
| message: '确认删除当前历史记录',
| deleteType: 0,
| },
| dialogShow: true,
| });
| },
|
| handleHistoryTap(e) {
| const { historyWords } = this.data;
| const { dataset } = e.currentTarget;
| const _searchValue = historyWords[dataset.index || 0] || '';
| if (_searchValue) {
| wx.navigateTo({
| url: `/pages/goods/result/index?searchValue=${_searchValue}`,
| });
| }
| },
|
| handleSubmit(e) {
| const { value } = e.detail.value;
| if (value.length === 0) return;
| wx.navigateTo({
| url: `/pages/goods/result/index?searchValue=${value}`,
| });
| },
| });
|
|