search.js
3.3 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {
request
} from "../../request/index.js"
const a = getApp()
Page({
data: {
imagesUrl: a.globalData.baseUrl,
list: [],
inputVal: '',
searchRecord: [],
showDialog: false,
messageAlert: '',
msg: '',
content: '',
page: 1,
searchValue: '',
S4_num: '',
},
onShow: function () {
let that = this
let token = wx.getStorageSync('token')
if (token) {
if (that.data.S4_num == '') {
that.getList()
}
} else {
that.popConfirm() // 未登录
}
},
onLoad: function (options) {
// console.log(options);
this.setData({
S4_num: options.S4_num || '' // 首页进来传递的值 其他页面没有
})
},
async getList() { // 获取搜索记录
let that = this
try {
const {
data: {
data
}
} = await request({
url: 'api/shop/souLog',
})
// console.log(data, "搜索历史");
that.setData({
searchRecord: data
})
} catch (err) {
// console.log(err);
a.popTest(err.msg)
}
},
async delClear() { // 删除
let that = this
try {
const {
data
} = await request({
url: 'api/shop/delSou'
})
// console.log(data);
a.popSuccessTest(data.msg)
setTimeout(() => {
that.getList()
}, 1000);
} catch (err) {
// console.log(err);
a.popTest(err.msg)
}
},
getInput(e) { // 获取input内容
this.setData({
searchValue: e.detail.value
})
},
async searchInput() { // 点击搜索按钮
let that = this;
if (that.data.searchValue != '') {
// console.log(that.data.searchValue, "that.data.searchValue");
if (that.data.S4_num == 1) { // 首页进来的
wx.navigateTo({
url: '/pages/Vmore4SList/Vmore4SList?kw=' + that.data.searchValue
})
} else {
wx.navigateTo({
url: '/pages/searchList/searchList?kw=' + that.data.searchValue + '&change=1'
})
}
that.setData({
searchValue: '',
})
} else {
a.popTest('请输入搜索内容')
}
},
popMaskTest() {
wx.showToast({
title: this.data.msg,
duration: 1300,
icon: 'none',
mask: true //是否有透明蒙层,默认为false
//如果有透明蒙层,弹窗的期间不能点击文档内容
})
},
toSearch(e) { // 点击搜索历史进行搜索
let that = this;
let kw = e.currentTarget.dataset.value
if (that.data.S4_num == 1) {
wx.navigateTo({
url: '/pages/Vmore4SList/Vmore4SList?kw=' + kw
})
} else {
wx.navigateTo({
url: '/pages/searchList/searchList?kw=' + kw + '&change=1'
})
}
that.setData({
searchValue: ''
})
},
popTest() {
wx.showToast({
title: this.data.msg,
icon: 'none', //如果要纯文本,不要icon,将值设为'none'
duration: 1300
})
},
popConfirm() {
wx.showModal({
title: '提示',
content: '您尚未登录,请登录后操作',
success: function (res) {
if (res.confirm) {
// console.log('点击确认回调')
wx.navigateTo({
url: '/pages/authorization/authorization?num=1'
})
} else {
// console.log('点击取消回调')
}
}
})
},
})