From f8ca61f4a50a7806306cfb07470a795bf669f688 Mon Sep 17 00:00:00 2001
From: lihongjuan <18848113498@163.com>
Date: Fri, 12 Jul 2019 16:35:39 +0800
Subject: [PATCH] 修改酒字典

---
 app.json                           |   7 +++++--
 pages/homapage/homepage.js         |   8 ++++++++
 pages/homapage/homepage.wxml       |   2 +-
 pages/homeblock/search/search.js   | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 pages/homeblock/search/search.wxml | 124 ++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------
 pages/homeblock/search/search.wxss |   3 ++-
 6 files changed, 221 insertions(+), 98 deletions(-)

diff --git a/app.json b/app.json
index e6e7a37..900ba51 100644
--- a/app.json
+++ b/app.json
@@ -1,13 +1,16 @@
 {
   "pages": [
+    "pages/homeblock/search/search",
+    "pages/find/find",
+   
     "pages/login/login",
     "pages/homapage/homepage",
-    "pages/find/find",
+    
     "pages/index/index",
     "pages/logs/logs",
     "pages/mine/mine",
     "pages/myblock/personpage/personpage",
-    "pages/homeblock/search/search",
+   
     "pages/homeblock/brandlist/brandlist",
     "pages/homeblock/brandpage/brandpage",
     "pages/homeblock/companyintro/companyintro",
diff --git a/pages/homapage/homepage.js b/pages/homapage/homepage.js
index 3c8781e..1b7adc7 100644
--- a/pages/homapage/homepage.js
+++ b/pages/homapage/homepage.js
@@ -184,6 +184,13 @@ Page({
     this.getcity()
   },
 
+  //进入搜索页
+  entersearch(){
+    wx.navigateTo({
+      url: '/pages/homeblock/search/search',
+    })
+  },
+
 
   //获取用户当前位置
   getcity() {
@@ -215,6 +222,7 @@ Page({
             that.setData({
               currentCity: province
             })
+            wx.setStorageSync('city', province)
             wx.request({
               // url: 'xxx' + city,
               // data: {},
diff --git a/pages/homapage/homepage.wxml b/pages/homapage/homepage.wxml
index 9d85dff..fdd96d5 100644
--- a/pages/homapage/homepage.wxml
+++ b/pages/homapage/homepage.wxml
@@ -88,7 +88,7 @@
       <view class="addressname">{{currentCity}}</view>
     </view>
 
-    <view class="headmiddle">
+    <view class="headmiddle" bindtap="entersearch">
       <view class="searchimg">
         <image src="{{url}}aicon_04@2x.png"></image>
       </view>
diff --git a/pages/homeblock/search/search.js b/pages/homeblock/search/search.js
index fac8048..48eef40 100644
--- a/pages/homeblock/search/search.js
+++ b/pages/homeblock/search/search.js
@@ -9,7 +9,16 @@ Page({
     select:1,
     url:'',
     searchshow:false,
-    recordshow:false
+    recordshow:true,
+    list:[],
+    history:[],
+    favorite:[],
+    keyword:'',
+    searchlist:[],
+    page:1,
+    searchlist:false,
+    searchlistarr:[],
+    
   },
 
   /**
@@ -19,11 +28,173 @@ Page({
     this.setData({
       url: app.globalData.url
     })
+
+    this.getsearchtext()
+  },
+  clear(){
+   console.log(3478734878)
+    this.setData({
+      keyword:'',
+      // searchshow: false,
+      // recordshow: true,
+
+    })
+  },
+  //获取搜索内容
+  getsearchtext(){
+
+    let that = this;
+    let url = '/index/Index/search_default', params = {
+      sort:that.data.select,
+      city:wx.getStorageSync('city')
+
+    }
+    app.post(url, params).then((res) => {
+      console.log(res);
+
+      that.setData({
+        list: res.list,
+        history: res.history,
+        favorite: res.favorite
+      })
+      console.log(this.data.history)
+
+    }).catch((err) => {
+
+    })
   },
   select(e){
    this.setData({
-     select:e.currentTarget.dataset.id
+     select:e.currentTarget.dataset.id,
+     searchshow: false,
+      recordshow: true,
+     searchlist:false
    })
+
+    this.getsearchtext()
+  },
+  //搜索页面
+  searchlist(){
+    this.setData({
+      searchlist:true,
+      searchshow:false
+    })
+    this.getlist()
+  },
+
+  getlist(){
+    let that = this;
+    let url = '/index/Index/search', params = {
+      sort: that.data.select,
+      keyword:that.data.keyword,
+      page:that.data.page
+    }
+    app.post(url, params).then((res) => {
+      console.log(res);
+      that.setData({
+        searchlistarr:res.list
+      })
+
+      let newsearchlistarr = that.data.searchlistarr;
+      for (var obj of newsearchlistarr){
+        obj.sel=false;
+
+      }
+      that.setData({
+        searchlistarr: newsearchlistarr
+      })
+
+
+
+    }).catch((err) => {
+
+    })
+  },
+
+//收藏和取消收藏
+  collect(e){
+    let that = this;
+    let id=e.currentTarget.dataset.id;
+    let newsearchlistarr = this.data.searchlistarr;
+   
+    for (var obj of newsearchlistarr){
+      obj.sel = !obj.sel
+      if(obj.id==id){
+        // obj.sel=true
+      }else{
+        obj.sel = false
+      }
+    }
+    this.setData({
+      searchlistarr: newsearchlistarr
+    })
+
+   
+    let url = '/index/Common/favorite', params = {
+      sort: that.data.select,
+      id:id
+    }
+    app.post(url, params).then((res) => {
+      console.log(res);
+      wx.showToast({
+        title: res,
+        icon:'none'
+      })
+
+
+
+    }).catch((err) => {
+
+    })
+  },
+
+  //搜索关键词
+  getkeyword(){
+    let that = this;
+    let url = '/index/Index/search_recommend', params = {
+      sort: that.data.select,
+      keyword:that.data.keyword
+
+    }
+    app.post(url, params).then((res) => {
+      console.log(res);
+      that.setData({
+        searchlist:res.list
+      })
+
+
+
+    }).catch((err) => {
+      this.setData({
+        searchshow: false,
+        recordshow: true,
+        
+      })
+
+    })
+  },
+
+  enterword(e){
+
+   
+    this.setData({
+      searchshow:true,
+      recordshow:false,
+      searchlist:false,
+      keyword:e.detail.value
+    })
+
+    this.getkeyword()
+  },
+
+  searchhistory(e){
+    this.setData({
+      keyword:e.currentTarget.dataset.keyword,
+      recordshow:false,
+      searchshow:true
+    })
+
+    this.getkeyword()
   },
   /**
    * 生命周期函数--监听页面初次渲染完成
diff --git a/pages/homeblock/search/search.wxml b/pages/homeblock/search/search.wxml
index 3efe020..9f4ce6a 100644
--- a/pages/homeblock/search/search.wxml
+++ b/pages/homeblock/search/search.wxml
@@ -1,65 +1,18 @@
 <!-- 搜索输入框的遮罩层 -->
 <view class="searchregister" wx:if="{{searchshow}}">
-  <view class="searchitem">
-    <view class="searchitemleft">
+  <view class="searchitem" wx:for="{{searchlist}}" wx:key='' bindtap="searchlist">
+    <view class="searchitemleft" >
       <view class="searimg">
         <image src="{{url}}aicon_04@2x.png"></image>
       </view>
 
-      <view class="searchtitle">泸州老窖</view>
-    </view>
-
-    <view class="iconfont icon-jiantou listrow "></view>
-
-  </view>
-  <view class="searchitem">
-    <view class="searchitemleft">
-      <view class="searimg">
-        <image src="{{url}}aicon_04@2x.png"></image>
-      </view>
-
-      <view class="searchtitle">泸州老窖</view>
-    </view>
-
-    <view class="iconfont icon-jiantou listrow "></view>
-
-  </view>
-  <view class="searchitem">
-    <view class="searchitemleft">
-      <view class="searimg">
-        <image src="{{url}}aicon_04@2x.png"></image>
-      </view>
-
-      <view class="searchtitle">泸州老窖</view>
-    </view>
-
-    <view class="iconfont icon-jiantou listrow "></view>
-
-  </view>
-  <view class="searchitem">
-    <view class="searchitemleft">
-      <view class="searimg">
-        <image src="{{url}}aicon_04@2x.png"></image>
-      </view>
-
-      <view class="searchtitle">泸州老窖</view>
-    </view>
-
-    <view class="iconfont icon-jiantou listrow "></view>
-
-  </view>
-  <view class="searchitem">
-    <view class="searchitemleft">
-      <view class="searimg">
-        <image src="{{url}}aicon_04@2x.png"></image>
-      </view>
-
-      <view class="searchtitle">泸州老窖</view>
+      <view class="searchtitle">{{item.name}}</view>
     </view>
 
     <view class="iconfont icon-jiantou listrow "></view>
 
   </view>
+ 
 
 </view>
 <view class="searchhead">
@@ -75,10 +28,10 @@
     </view>
 
     <view class="searcontent">
-      <input placeholder='搜索酒品/品牌/酒企' placeholder-class='searcontent' />
+      <input placeholder='搜索酒品/品牌/酒企' placeholder-class='searcontent' bindinput="enterword" value="{{keyword}}" />
     </view>
 
-    <view class="closeimg">
+    <view class="closeimg" bindtap="clear">
       <image src="{{url}}aicon_07x.png"></image>
     </view>
   </view>
@@ -92,13 +45,9 @@
 
   <view class="textbox">
 
-    <view class="seahead">
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
+    <view class="seahead" >
+      <view class="searword" wx:for="{{list}}" wx:key="">{{item.name}}</view>
+      
     </view>
 
     <view class="historyrecord">
@@ -109,13 +58,9 @@
       <view class="hisword">历史记录</view>
 
     </view>
-    <view class="seahead">
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
+    <view class="seahead" wx:if="{{history.length!=0}}">
+      <view class="searword" wx:for="{{history}}" wx:key='' bindtap="searchhistory" data-keyword="{{item.keyword}}">{{item.keyword}}</view>
+     
     </view>
     <view class="historyrecord">
       <view class="hisimg">
@@ -127,46 +72,42 @@
     </view>
 
     <view class="seahead">
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
-      <view class="searword">茅台</view>
+      <view class="searword" wx:for="{{favorite}}" wx:key=''>{{item.name}}</view>
+ 
     </view>
 
   </view>
 </view>
 
-<view class="searchresult" wx:else>
+<view class="searchresult" wx:if="{{searchlist}}">
 
   <view class="jiupin" wx:if="{{select==1}}">
 
-    <view class="searchitem">
+    <view class="searchitem" wx:for="{{searchlistarr}}" wx:key=''>
       <view class="searchitemleft">
         <view class="itemleftimg">
-          <image src="{{url}}aicon_11@2x.png"></image>
+          <image src="{{item.logo}}"></image>
         </view>
 
         <view class="itemiddle">
-          <view class="itemidelename">泸州迎宾酒</view>
+          <view class="itemidelename">{{item.name}}</view>
           <view class="nambottom">
-            <text class="namebottomitem">53°</text>
-            <text class="namebottomitem">浓香型</text>
-            <text class="namebottomitem">53°</text>
-            <text class="namebottomitem">53°</text>
+            <text class="namebottomitem">{{item.degree_name}}</text>
+            <text class="namebottomitem">{{item.odor_name}}</text>
+            <text class="namebottomitem">{{item.price}}</text>
+            <text class="namebottomitem">{{item.ml}}</text>
           </view>
         </view>
       </view>
 
-      <view class="starimg">
-        <!-- aicon_010x.png -->
-
-        <image src="{{url}}aicon_09x.png"></image>
+      <view class="starimg" catchtap="collect" data-id="{{item.id}}">
+        <image src="{{url}}aicon_10x.png" wx:if="{{item.sel}}"></image>
+        <image src="{{url}}aicon_09x.png" wx:else></image>
+        
       </view>
 
     </view>
-    <view class="searchitem">
+    <!-- <view class="searchitem">
       <view class="searchitemleft">
         <view class="itemleftimg">
           <image src="{{url}}aicon_11@2x.png"></image>
@@ -184,7 +125,7 @@
       </view>
 
       <view class="starimg">
-        <!-- aicon_010x.png -->
+        
 
         <image src="{{url}}aicon_09x.png"></image>
       </view>
@@ -208,7 +149,7 @@
       </view>
 
       <view class="starimg">
-        <!-- aicon_010x.png -->
+       
 
         <image src="{{url}}aicon_09x.png"></image>
       </view>
@@ -232,7 +173,7 @@
       </view>
 
       <view class="starimg">
-        <!-- aicon_010x.png -->
+     
 
         <image src="{{url}}aicon_09x.png"></image>
       </view>
@@ -256,12 +197,11 @@
       </view>
 
       <view class="starimg">
-        <!-- aicon_010x.png -->
-
+        
         <image src="{{url}}aicon_09x.png"></image>
       </view>
 
-    </view>
+    </view> -->
   </view>
 
   <view class="brand" wx:if="{{select==2}}">
diff --git a/pages/homeblock/search/search.wxss b/pages/homeblock/search/search.wxss
index 34fb9e9..b322543 100644
--- a/pages/homeblock/search/search.wxss
+++ b/pages/homeblock/search/search.wxss
@@ -81,7 +81,7 @@ image{
   display:flex;
   align-items: center;
   flex-wrap: wrap;
-  margin-top:40rpx;
+  margin-top:20rpx;
 }
 .searword{
   padding:10rpx 20rpx;
@@ -90,6 +90,7 @@ image{
   font-size: 26rpx;
   color:#666;
   margin-left:20rpx;
+  margin-top:20rpx;
 }
 .hisword{
   color:#1A1A1A;
--
libgit2 0.24.0