作者 朱振飞
1 { 1 {
2 "pages": [ 2 "pages": [
  3 + "pages/homeblock/search/search",
  4 + "pages/find/find",
  5 +
3 "pages/login/login", 6 "pages/login/login",
4 "pages/homapage/homepage", 7 "pages/homapage/homepage",
5 - "pages/find/find", 8 +
6 "pages/index/index", 9 "pages/index/index",
7 "pages/logs/logs", 10 "pages/logs/logs",
8 "pages/mine/mine", 11 "pages/mine/mine",
9 "pages/myblock/personpage/personpage", 12 "pages/myblock/personpage/personpage",
10 - "pages/homeblock/search/search", 13 +
11 "pages/homeblock/brandlist/brandlist", 14 "pages/homeblock/brandlist/brandlist",
12 "pages/homeblock/brandpage/brandpage", 15 "pages/homeblock/brandpage/brandpage",
13 "pages/homeblock/companyintro/companyintro", 16 "pages/homeblock/companyintro/companyintro",
@@ -184,6 +184,13 @@ Page({ @@ -184,6 +184,13 @@ Page({
184 this.getcity() 184 this.getcity()
185 }, 185 },
186 186
  187 + //进入搜索页
  188 + entersearch(){
  189 + wx.navigateTo({
  190 + url: '/pages/homeblock/search/search',
  191 + })
  192 + },
  193 +
187 194
188 //获取用户当前位置 195 //获取用户当前位置
189 getcity() { 196 getcity() {
@@ -215,6 +222,7 @@ Page({ @@ -215,6 +222,7 @@ Page({
215 that.setData({ 222 that.setData({
216 currentCity: province 223 currentCity: province
217 }) 224 })
  225 + wx.setStorageSync('city', province)
218 wx.request({ 226 wx.request({
219 // url: 'xxx' + city, 227 // url: 'xxx' + city,
220 // data: {}, 228 // data: {},
@@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
72 <view class="addressname">{{currentCity}}</view> 72 <view class="addressname">{{currentCity}}</view>
73 </view> 73 </view>
74 74
75 - <view class="headmiddle"> 75 + <view class="headmiddle" bindtap="entersearch">
76 <view class="searchimg"> 76 <view class="searchimg">
77 <image src="{{url}}aicon_04@2x.png"></image> 77 <image src="{{url}}aicon_04@2x.png"></image>
78 </view> 78 </view>
@@ -9,7 +9,16 @@ Page({ @@ -9,7 +9,16 @@ Page({
9 select:1, 9 select:1,
10 url:'', 10 url:'',
11 searchshow:false, 11 searchshow:false,
12 - recordshow:false 12 + recordshow:true,
  13 + list:[],
  14 + history:[],
  15 + favorite:[],
  16 + keyword:'',
  17 + searchlist:[],
  18 + page:1,
  19 + searchlist:false,
  20 + searchlistarr:[],
  21 +
13 }, 22 },
14 23
15 /** 24 /**
@@ -19,11 +28,173 @@ Page({ @@ -19,11 +28,173 @@ Page({
19 this.setData({ 28 this.setData({
20 url: app.globalData.url 29 url: app.globalData.url
21 }) 30 })
  31 +
  32 + this.getsearchtext()
  33 + },
  34 + clear(){
  35 + console.log(3478734878)
  36 + this.setData({
  37 + keyword:'',
  38 + // searchshow: false,
  39 + // recordshow: true,
  40 +
  41 + })
  42 + },
  43 + //获取搜索内容
  44 + getsearchtext(){
  45 +
  46 + let that = this;
  47 + let url = '/index/Index/search_default', params = {
  48 + sort:that.data.select,
  49 + city:wx.getStorageSync('city')
  50 +
  51 + }
  52 + app.post(url, params).then((res) => {
  53 + console.log(res);
  54 +
  55 + that.setData({
  56 + list: res.list,
  57 + history: res.history,
  58 + favorite: res.favorite
  59 + })
  60 + console.log(this.data.history)
  61 +
  62 + }).catch((err) => {
  63 +
  64 + })
22 }, 65 },
23 select(e){ 66 select(e){
24 this.setData({ 67 this.setData({
25 - select:e.currentTarget.dataset.id 68 + select:e.currentTarget.dataset.id,
  69 + searchshow: false,
  70 + recordshow: true,
  71 + searchlist:false
26 }) 72 })
  73 +
  74 + this.getsearchtext()
  75 + },
  76 + //搜索页面
  77 + searchlist(){
  78 + this.setData({
  79 + searchlist:true,
  80 + searchshow:false
  81 + })
  82 + this.getlist()
  83 + },
  84 +
  85 + getlist(){
  86 + let that = this;
  87 + let url = '/index/Index/search', params = {
  88 + sort: that.data.select,
  89 + keyword:that.data.keyword,
  90 + page:that.data.page
  91 + }
  92 + app.post(url, params).then((res) => {
  93 + console.log(res);
  94 + that.setData({
  95 + searchlistarr:res.list
  96 + })
  97 +
  98 + let newsearchlistarr = that.data.searchlistarr;
  99 + for (var obj of newsearchlistarr){
  100 + obj.sel=false;
  101 +
  102 + }
  103 + that.setData({
  104 + searchlistarr: newsearchlistarr
  105 + })
  106 +
  107 +
  108 +
  109 + }).catch((err) => {
  110 +
  111 + })
  112 + },
  113 +
  114 +//收藏和取消收藏
  115 + collect(e){
  116 + let that = this;
  117 + let id=e.currentTarget.dataset.id;
  118 + let newsearchlistarr = this.data.searchlistarr;
  119 +
  120 + for (var obj of newsearchlistarr){
  121 + obj.sel = !obj.sel
  122 + if(obj.id==id){
  123 + // obj.sel=true
  124 + }else{
  125 + obj.sel = false
  126 + }
  127 + }
  128 + this.setData({
  129 + searchlistarr: newsearchlistarr
  130 + })
  131 +
  132 +
  133 + let url = '/index/Common/favorite', params = {
  134 + sort: that.data.select,
  135 + id:id
  136 + }
  137 + app.post(url, params).then((res) => {
  138 + console.log(res);
  139 + wx.showToast({
  140 + title: res,
  141 + icon:'none'
  142 + })
  143 +
  144 +
  145 +
  146 + }).catch((err) => {
  147 +
  148 + })
  149 + },
  150 +
  151 + //搜索关键词
  152 + getkeyword(){
  153 + let that = this;
  154 + let url = '/index/Index/search_recommend', params = {
  155 + sort: that.data.select,
  156 + keyword:that.data.keyword
  157 +
  158 + }
  159 + app.post(url, params).then((res) => {
  160 + console.log(res);
  161 + that.setData({
  162 + searchlist:res.list
  163 + })
  164 +
  165 +
  166 +
  167 + }).catch((err) => {
  168 + this.setData({
  169 + searchshow: false,
  170 + recordshow: true,
  171 +
  172 + })
  173 +
  174 + })
  175 + },
  176 +
  177 + enterword(e){
  178 +
  179 +
  180 + this.setData({
  181 + searchshow:true,
  182 + recordshow:false,
  183 + searchlist:false,
  184 + keyword:e.detail.value
  185 + })
  186 +
  187 + this.getkeyword()
  188 + },
  189 +
  190 + searchhistory(e){
  191 + this.setData({
  192 + keyword:e.currentTarget.dataset.keyword,
  193 + recordshow:false,
  194 + searchshow:true
  195 + })
  196 +
  197 + this.getkeyword()
27 }, 198 },
28 /** 199 /**
29 * 生命周期函数--监听页面初次渲染完成 200 * 生命周期函数--监听页面初次渲染完成
1 <!-- 搜索输入框的遮罩层 --> 1 <!-- 搜索输入框的遮罩层 -->
2 <view class="searchregister" wx:if="{{searchshow}}"> 2 <view class="searchregister" wx:if="{{searchshow}}">
3 - <view class="searchitem">  
4 - <view class="searchitemleft"> 3 + <view class="searchitem" wx:for="{{searchlist}}" wx:key='' bindtap="searchlist">
  4 + <view class="searchitemleft" >
5 <view class="searimg"> 5 <view class="searimg">
6 <image src="{{url}}aicon_04@2x.png"></image> 6 <image src="{{url}}aicon_04@2x.png"></image>
7 </view> 7 </view>
8 8
9 - <view class="searchtitle">泸州老窖</view>  
10 - </view>  
11 -  
12 - <view class="iconfont icon-jiantou listrow "></view>  
13 -  
14 - </view>  
15 - <view class="searchitem">  
16 - <view class="searchitemleft">  
17 - <view class="searimg">  
18 - <image src="{{url}}aicon_04@2x.png"></image>  
19 - </view>  
20 -  
21 - <view class="searchtitle">泸州老窖</view>  
22 - </view>  
23 -  
24 - <view class="iconfont icon-jiantou listrow "></view>  
25 -  
26 - </view>  
27 - <view class="searchitem">  
28 - <view class="searchitemleft">  
29 - <view class="searimg">  
30 - <image src="{{url}}aicon_04@2x.png"></image>  
31 - </view>  
32 -  
33 - <view class="searchtitle">泸州老窖</view>  
34 - </view>  
35 -  
36 - <view class="iconfont icon-jiantou listrow "></view>  
37 -  
38 - </view>  
39 - <view class="searchitem">  
40 - <view class="searchitemleft">  
41 - <view class="searimg">  
42 - <image src="{{url}}aicon_04@2x.png"></image>  
43 - </view>  
44 -  
45 - <view class="searchtitle">泸州老窖</view>  
46 - </view>  
47 -  
48 - <view class="iconfont icon-jiantou listrow "></view>  
49 -  
50 - </view>  
51 - <view class="searchitem">  
52 - <view class="searchitemleft">  
53 - <view class="searimg">  
54 - <image src="{{url}}aicon_04@2x.png"></image>  
55 - </view>  
56 -  
57 - <view class="searchtitle">泸州老窖</view> 9 + <view class="searchtitle">{{item.name}}</view>
58 </view> 10 </view>
59 11
60 <view class="iconfont icon-jiantou listrow "></view> 12 <view class="iconfont icon-jiantou listrow "></view>
61 13
62 </view> 14 </view>
  15 +
63 16
64 </view> 17 </view>
65 <view class="searchhead"> 18 <view class="searchhead">
@@ -75,10 +28,10 @@ @@ -75,10 +28,10 @@
75 </view> 28 </view>
76 29
77 <view class="searcontent"> 30 <view class="searcontent">
78 - <input placeholder='搜索酒品/品牌/酒企' placeholder-class='searcontent' /> 31 + <input placeholder='搜索酒品/品牌/酒企' placeholder-class='searcontent' bindinput="enterword" value="{{keyword}}" />
79 </view> 32 </view>
80 33
81 - <view class="closeimg"> 34 + <view class="closeimg" bindtap="clear">
82 <image src="{{url}}aicon_07x.png"></image> 35 <image src="{{url}}aicon_07x.png"></image>
83 </view> 36 </view>
84 </view> 37 </view>
@@ -92,13 +45,9 @@ @@ -92,13 +45,9 @@
92 45
93 <view class="textbox"> 46 <view class="textbox">
94 47
95 - <view class="seahead">  
96 - <view class="searword">茅台</view>  
97 - <view class="searword">茅台</view>  
98 - <view class="searword">茅台</view>  
99 - <view class="searword">茅台</view>  
100 - <view class="searword">茅台</view>  
101 - <view class="searword">茅台</view> 48 + <view class="seahead" >
  49 + <view class="searword" wx:for="{{list}}" wx:key="">{{item.name}}</view>
  50 +
102 </view> 51 </view>
103 52
104 <view class="historyrecord"> 53 <view class="historyrecord">
@@ -109,13 +58,9 @@ @@ -109,13 +58,9 @@
109 <view class="hisword">历史记录</view> 58 <view class="hisword">历史记录</view>
110 59
111 </view> 60 </view>
112 - <view class="seahead">  
113 - <view class="searword">茅台</view>  
114 - <view class="searword">茅台</view>  
115 - <view class="searword">茅台</view>  
116 - <view class="searword">茅台</view>  
117 - <view class="searword">茅台</view>  
118 - <view class="searword">茅台</view> 61 + <view class="seahead" wx:if="{{history.length!=0}}">
  62 + <view class="searword" wx:for="{{history}}" wx:key='' bindtap="searchhistory" data-keyword="{{item.keyword}}">{{item.keyword}}</view>
  63 +
119 </view> 64 </view>
120 <view class="historyrecord"> 65 <view class="historyrecord">
121 <view class="hisimg"> 66 <view class="hisimg">
@@ -127,46 +72,42 @@ @@ -127,46 +72,42 @@
127 </view> 72 </view>
128 73
129 <view class="seahead"> 74 <view class="seahead">
130 - <view class="searword">茅台</view>  
131 - <view class="searword">茅台</view>  
132 - <view class="searword">茅台</view>  
133 - <view class="searword">茅台</view>  
134 - <view class="searword">茅台</view>  
135 - <view class="searword">茅台</view> 75 + <view class="searword" wx:for="{{favorite}}" wx:key=''>{{item.name}}</view>
  76 +
136 </view> 77 </view>
137 78
138 </view> 79 </view>
139 </view> 80 </view>
140 81
141 -<view class="searchresult" wx:else> 82 +<view class="searchresult" wx:if="{{searchlist}}">
142 83
143 <view class="jiupin" wx:if="{{select==1}}"> 84 <view class="jiupin" wx:if="{{select==1}}">
144 85
145 - <view class="searchitem"> 86 + <view class="searchitem" wx:for="{{searchlistarr}}" wx:key=''>
146 <view class="searchitemleft"> 87 <view class="searchitemleft">
147 <view class="itemleftimg"> 88 <view class="itemleftimg">
148 - <image src="{{url}}aicon_11@2x.png"></image> 89 + <image src="{{item.logo}}"></image>
149 </view> 90 </view>
150 91
151 <view class="itemiddle"> 92 <view class="itemiddle">
152 - <view class="itemidelename">泸州迎宾酒</view> 93 + <view class="itemidelename">{{item.name}}</view>
153 <view class="nambottom"> 94 <view class="nambottom">
154 - <text class="namebottomitem">53°</text>  
155 - <text class="namebottomitem">浓香型</text>  
156 - <text class="namebottomitem">53°</text>  
157 - <text class="namebottomitem">53°</text> 95 + <text class="namebottomitem">{{item.degree_name}}</text>
  96 + <text class="namebottomitem">{{item.odor_name}}</text>
  97 + <text class="namebottomitem">{{item.price}}</text>
  98 + <text class="namebottomitem">{{item.ml}}</text>
158 </view> 99 </view>
159 </view> 100 </view>
160 </view> 101 </view>
161 102
162 - <view class="starimg">  
163 - <!-- aicon_010x.png -->  
164 -  
165 - <image src="{{url}}aicon_09x.png"></image> 103 + <view class="starimg" catchtap="collect" data-id="{{item.id}}">
  104 + <image src="{{url}}aicon_10x.png" wx:if="{{item.sel}}"></image>
  105 + <image src="{{url}}aicon_09x.png" wx:else></image>
  106 +
166 </view> 107 </view>
167 108
168 </view> 109 </view>
169 - <view class="searchitem"> 110 + <!-- <view class="searchitem">
170 <view class="searchitemleft"> 111 <view class="searchitemleft">
171 <view class="itemleftimg"> 112 <view class="itemleftimg">
172 <image src="{{url}}aicon_11@2x.png"></image> 113 <image src="{{url}}aicon_11@2x.png"></image>
@@ -184,7 +125,7 @@ @@ -184,7 +125,7 @@
184 </view> 125 </view>
185 126
186 <view class="starimg"> 127 <view class="starimg">
187 - <!-- aicon_010x.png --> 128 +
188 129
189 <image src="{{url}}aicon_09x.png"></image> 130 <image src="{{url}}aicon_09x.png"></image>
190 </view> 131 </view>
@@ -208,7 +149,7 @@ @@ -208,7 +149,7 @@
208 </view> 149 </view>
209 150
210 <view class="starimg"> 151 <view class="starimg">
211 - <!-- aicon_010x.png --> 152 +
212 153
213 <image src="{{url}}aicon_09x.png"></image> 154 <image src="{{url}}aicon_09x.png"></image>
214 </view> 155 </view>
@@ -232,7 +173,7 @@ @@ -232,7 +173,7 @@
232 </view> 173 </view>
233 174
234 <view class="starimg"> 175 <view class="starimg">
235 - <!-- aicon_010x.png --> 176 +
236 177
237 <image src="{{url}}aicon_09x.png"></image> 178 <image src="{{url}}aicon_09x.png"></image>
238 </view> 179 </view>
@@ -256,12 +197,11 @@ @@ -256,12 +197,11 @@
256 </view> 197 </view>
257 198
258 <view class="starimg"> 199 <view class="starimg">
259 - <!-- aicon_010x.png -->  
260 - 200 +
261 <image src="{{url}}aicon_09x.png"></image> 201 <image src="{{url}}aicon_09x.png"></image>
262 </view> 202 </view>
263 203
264 - </view> 204 + </view> -->
265 </view> 205 </view>
266 206
267 <view class="brand" wx:if="{{select==2}}"> 207 <view class="brand" wx:if="{{select==2}}">
@@ -81,7 +81,7 @@ image{ @@ -81,7 +81,7 @@ image{
81 display:flex; 81 display:flex;
82 align-items: center; 82 align-items: center;
83 flex-wrap: wrap; 83 flex-wrap: wrap;
84 - margin-top:40rpx; 84 + margin-top:20rpx;
85 } 85 }
86 .searword{ 86 .searword{
87 padding:10rpx 20rpx; 87 padding:10rpx 20rpx;
@@ -90,6 +90,7 @@ image{ @@ -90,6 +90,7 @@ image{
90 font-size: 26rpx; 90 font-size: 26rpx;
91 color:#666; 91 color:#666;
92 margin-left:20rpx; 92 margin-left:20rpx;
  93 + margin-top:20rpx;
93 } 94 }
94 .hisword{ 95 .hisword{
95 color:#1A1A1A; 96 color:#1A1A1A;