Browse Source

修改移动端全局搜索

shenjj 7 years ago
parent
commit
fcea40e886

+ 13 - 0
assets/scss/mobileCommon.scss

@@ -130,6 +130,19 @@ html {
     border: none;
   }
 
+  input::-webkit-input-placeholder{
+    color:#999;
+  }
+  input::-moz-placeholder{   /* Mozilla Firefox 19+ */
+    color:#999;
+  }
+  input:-moz-placeholder{    /* Mozilla Firefox 4 to 18 */
+    color:#999;
+  }
+  input:-ms-input-placeholder{  /* Internet Explorer 10-11 */
+    color:#999;
+  }
+
 
 
   /*search*/

+ 207 - 21
components/mobile/Home.vue

@@ -1,7 +1,33 @@
 <template>
   <div class="home">
     <div v-if="!showMainSearch">
+      <ul class="associate-list" v-show="associate.show" @click="associate.show = false">
+        <li @click.stop="onAssociateClick(similar)" v-for="similar in similarKeywords.result">
+          <i class="icon-sousuo iconfont"></i>
+          <span>{{Getsimilar(similar)}}</span>
+          <!--<span v-if="ChooseTop === 'component'">{{similar.code}}</span>-->
+          <!--<span v-else-if="ChooseTop === 'product'">{{similar}}</span>-->
+          <!--<span v-else-if="ChooseTop === 'store'">{{similar}}</span>-->
+          <!--<span v-else-if="ChooseTop === 'brand'">{{similar.nameEn}}</span>-->
+        </li>
+        <li @click.stop="onSearch(keyword)">查找“{{baseUtils.filterStringEllipsis(keyword, 30)}}”</li>
+      </ul>
       <div class="header">
+        <div class="search-content" @touchmove="preventTouchMove($event)">
+          <div class="main-search-header-controll clearfix">
+            <div style="display: flex;align-items: center;justify-content: space-between;width:100%;">
+              <div :class="ChooseTop === 'component' ? 'active' : ''" @click="setChangelistHander('component')"><a>型号</a></div>
+              <div :class="ChooseTop === 'kind' ? 'active' : ''" @click="setChangelistHander('kind')"><a>物料名称</a></div>
+              <div :class="ChooseTop === 'store' ? 'active' : ''" @click="setChangelistHander('store')"><a>卖家</a></div>
+              <div :class="ChooseTop === 'brand' ? 'active' : ''" @click="setChangelistHander('brand')"><a>品牌</a></div>
+            </div>
+          </div>
+          <input type="text" v-model="keyword" id="search-box" @keyup.13="onSearch()" :placeholder="placeholder">
+          <span @click="onSearch()">
+          <i class="iconfont icon-sousuo"></i>
+        </span>
+          <img src="/images/mobile/@2x/applyPurchase/home/phone.png" alt="" @click="showStoreInfo = true">
+        </div>
         <div v-swiper:mySwiper="swiperOption">
           <div class="swiper-wrapper">
             <div class="swiper-slide">
@@ -16,13 +42,6 @@
           </div>
           <div class="swiper-pagination swiper-pagination-bullets"></div>
         </div>
-        <div class="search-content">
-          <input type="text" placeholder="请输入您要查找的型号、品牌或店铺" @click="onHomeSearchClick()">
-          <span>
-          <i class="iconfont icon-sousuo"></i>
-        </span>
-          <img src="/images/mobile/@2x/applyPurchase/home/phone.png" alt="" @click="showStoreInfo = true">
-        </div>
       </div>
       <ul class="link-list">
         <li>
@@ -113,7 +132,12 @@
         isChange: false,
         isDataChange: false,
         url: '',
-        isValid: true
+        isValid: true,
+        ChooseTop: 'component',
+        keyword: '',
+        associate: {
+          show: false
+        }
       }
     },
     components: {
@@ -147,6 +171,12 @@
           }
         },
         immediate: true
+      },
+      'keyword': function (val, oldVal) {
+        let keywords = this.similarKeywords.data
+        if (!keywords || !keywords.length) {
+          this.onChange()
+        }
       }
 //      $route: {
 //        handler: function (val) {
@@ -155,6 +185,20 @@
 //      }
     },
     computed: {
+      similarKeywords () {
+        return this.$store.state.search.keywords.data
+      },
+      placeholder() {
+        if (this.ChooseTop === 'component') {
+          return '请输入您要搜索的型号'
+        } else if (this.ChooseTop === 'kind') {
+          return '请输入您要搜索的物料名称'
+        } else if (this.ChooseTop === 'store') {
+          return '请输入您要搜索的卖家名称'
+        } else if (this.ChooseTop === 'brand') {
+          return '请输入您要搜索的品牌'
+        }
+      },
       purchaseManList () {
         return this.$store.state.applyPurchase.purchaseManList.purchaseHomeList.data
       },
@@ -166,6 +210,58 @@
       }
     },
     methods: {
+      onSearch (item) {
+        if (item) {
+          this.keyword = item
+        }
+        if (this.keyword) {
+          this.$router.push(`/mobile/search/newkeycode?choosetype=${this.ChooseTop}&keyword=${encodeURIComponent(this.keyword)}`)
+        }
+      },
+      onChange () {
+        if (!this.keyword) {
+          this.associate.show = false
+          this.$store.dispatch('resetSearchKeywords')
+        } else {
+          this.searchKeywords()
+        }
+        if (this.click_flag) {
+          this.associate.show = false
+        }
+      },
+      setChangelistHander(str) {
+        this.ChooseTop = str
+        if (!this.keyword) return
+        this.$store.dispatch('searchKeywords', {keyword: this.keyword, type: this.ChooseTop})
+        this.associate.show = true
+      },
+      searchKeywords () {
+        this.$store.dispatch('searchKeywords', {keyword: this.keyword, type: this.ChooseTop})
+        this.associate.show = true
+      },
+      onAssociateClick (word) {
+        if (this.ChooseTop === 'component') {
+          this.keyword = word.code
+        } else if (this.ChooseTop === 'kind') {
+          this.keyword = word.nameCn
+        } else if (this.ChooseTop === 'store') {
+          this.keyword = word.name
+        } else if (this.ChooseTop === 'brand') {
+          this.keyword = word.nameEn
+        }
+        this.onSearch()
+      },
+      Getsimilar(word) {
+        if (this.ChooseTop === 'component') {
+          return word.code
+        } else if (this.ChooseTop === 'kind') {
+          return word.nameCn
+        } else if (this.ChooseTop === 'store') {
+          return word.name
+        } else if (this.ChooseTop === 'brand') {
+          return word.nameEn
+        }
+      },
 //      scroll: function () {
 //         let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
 //         if (Math.ceil(scrolled + window.screen.availHeight) >= document.body.scrollHeight && !this.isSearchSearchingMore && this.page < this.allPage) {
@@ -224,28 +320,118 @@
   }
 </script>
 <style lang="scss">
+  @mixin overFlowHidden {
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+  }
+  @mixin lineHeight($value) {
+    height: $value;
+    line-height: $value;
+  }
   @import '~assets/scss/mobileCommon';
+  .swiper-slide1 {
+    background: url('/images/mobile/@2x/applyPurchase/home/app-banner_01.jpg');
+    background-repeat: no-repeat;
+    background-size: cover;
+  }
   .home {
     padding-bottom: 1rem;
     background: #f3f3f7;
-    .header {
-      height: 3.26rem;
-      position: relative;
-      .home-bg {
-        height: 3.26rem;
-        width: 100%;
+    .search-content {
+      padding: 0.15rem 0;
+      position: absolute;
+      z-index: 11;
+      width: 100%;
+      input {
+        margin-top: -0.02rem;
+        outline: 0;
+        border: 0;
       }
-      .search-content {
-        position: absolute;
-        top: 0;
-        width: 100%;
+    }
+    .main-search-header-controll {
+      width: 5.48rem;
+      margin-left: 0.21rem;
+      transform: translateY(1px);
+      div {
+        div {
+          font-size: 0.28rem;
+          color: #fff;
+          margin: 0;
+          border-radius: 0;
+          padding: 0.1rem 0.1rem;
+          a {
+            font-size: .26rem;
+            color: #f1f1f1;
+          }
+          &.active {
+            background: #fff;
+            border-top-left-radius: 0.05rem;
+            border-top-right-radius: 0.05rem;
+          }
+          &.active a {
+            color: #40b6fc;
+          }
+        }
       }
+    }
+    .associate-list {
+      position: absolute;
+      width: 100%;
+      background: #fff;
+      top: 1.25rem;
+      border: 1px solid #dcdcdc;
+      z-index: 100;
+      height: 100%;
+      left: 0;
+      bottom: 0;
+      right: 0;
+      overflow-y: auto;
+      li {
+        height: 0.7rem;
+        line-height: .9rem;
+        margin: 0 .45rem;
+        border-bottom: .04rem solid #f1f0f0;
+        @include overFlowHidden();
+        i {
+          font-size: .36rem;
+          margin-right: .24rem;
+          color: #ddd;
+        }
+        span {
+          color: #999;
+          font-size: .28rem;
+          line-height: .58rem;
+          height: .58rem;
+          display: inline-block;
+        }
+        &:active, &:hover {
+          background: #eee;
+        }
+        &:last-child {
+          text-align: center;
+          font-size: .3rem;
+          color: #3976f4;
+          border-bottom: none;
+          &:active, &:hover {
+            background: #fff;
+          }
+        }
+      }
+    }
+    .header {
+      position: relative;
+      height: 4.08rem;
+      overflow: hidden;
       .swiper-container {
-        height: 3.26rem;
-        position: absolute;
-        top: 0;
         width: 100%;
         z-index: 0;
+        height: 4.08rem;
+        overflow: hidden;
+        img {
+          max-width: 100%;
+          /*height: 4.08rem;*/
+        }
       }
       .swiper-pagination-fraction, .swiper-pagination-custom, .swiper-container-horizontal > .swiper-pagination-bullets {
         bottom: .1rem !important;

+ 37 - 31
pages/mobile/search/newkeycode.vue

@@ -2,17 +2,17 @@
  <div class="search-wrapper">
    <!-- 头部搜索 -->
    <div class="main-search-header">
-     <input type="text" id="search-box" v-model="keyword" @keyup.13="onClickSearchHander()" :placeholder="placeholder" @input="changeKeyWord()">
-     <span @click="onClickSearchHander()">搜索</span>
-     <a @click="cancelSearchHander()">取消</a>
      <div class="main-search-header-controll clearfix">
        <div style="display: flex;align-items: center;justify-content: space-between;width:100%;">
          <div :class="ChooseTop === 'component' ? 'active' : ''" @click="setChangelistHander('component')"><a>型号</a></div>
-           <div :class="ChooseTop === 'kind' ? 'active' : ''" @click="setChangelistHander('kind')"><a>物料名称</a></div>
-           <div :class="ChooseTop === 'store' ? 'active' : ''" @click="setChangelistHander('store')"><a>卖家</a></div>
+         <div :class="ChooseTop === 'kind' ? 'active' : ''" @click="setChangelistHander('kind')"><a>物料名称</a></div>
+         <div :class="ChooseTop === 'store' ? 'active' : ''" @click="setChangelistHander('store')"><a>卖家</a></div>
          <div :class="ChooseTop === 'brand' ? 'active' : ''" @click="setChangelistHander('brand')"><a>品牌</a></div>
        </div>
      </div>
+     <input type="text" id="search-box" v-model="keyword" @keyup.13="onClickSearchHander()" :placeholder="placeholder" @input="changeKeyWord()">
+     <span @click="onClickSearchHander()">搜索</span>
+     <a @click="cancelSearchHander()" style="margin-top: 0.14rem;display: inline-block;">取消</a>
    </div>
    <ul class="associate-list" v-show="associate.show" @click="associate.show = false">
      <li @click.stop="onAssociateClick(similar)" v-for="similar in similarKeywords.result">
@@ -511,7 +511,7 @@
       // 搜索点击事件
       onClickSearchHander() {
         console.log(this.keyword)
-        if (!this.keyword) {this.setRemindText('请输入关键字')}
+        if (!this.keyword) { this.setRemindText('请输入关键字') }
         this.$router.push(`/mobile/search/newkeycode?choosetype=${this.ChooseTop}&keyword=${this.keyword}`)
         // this.setChangelistHander(this.ChooseTop)
         // window.location.href =
@@ -732,34 +732,34 @@
     .main-search-header {
       position: absolute;
       background: #3e82f5;
-      line-height: .88rem;
+      padding: .15rem 0;
       margin-top: 0;
       z-index: 1;
       width: 100%;
       input {
-        width: 4.88rem;
-        height: .62rem;
-        line-height: .62rem;
+        width: 5.1rem;
+        height: .58rem;
+        line-height: .58rem;
         font-size: .26rem;
         color: #333;
-        margin-left: 0.3rem;
+        margin-left: 0.11rem;
         /*padding-left: 1.26rem;*/
         border: .04rem solid #fff;
         background: #fff;
         outline: none;
         border-radius: 0;
         float: left;
-        margin-top: .12rem;
         -webkit-appearance: none;
         border-top-left-radius: .14rem;
         border-bottom-left-radius: .14rem;
+        padding-left: 0.21rem;
       }
       span {
         display: inline-block;
         width: 1.02rem;
         text-align: center;
-        height: .62rem;
-        line-height: .62rem;
+        height: .58rem;
+        line-height: .58rem;
         color: #366df3;
         font-size: .28rem;
         margin-left: .02rem;
@@ -767,7 +767,6 @@
         border-bottom-right-radius: .14rem;
         background: #fff;
         float: left;
-        margin-top: .12rem;
       }
       a {
         font-size: .28rem;
@@ -775,24 +774,31 @@
         margin-left: .2rem;
       }
       .main-search-header-controll {
-        background: #3e82f5;
-        width: 5.9rem;
-        margin-left: 0.3rem;
+        width: 5.48rem;
+        margin-left: 0.21rem;
+        transform: translateY(1px);
         div {
-          @include lineHeight(0.66rem);
-          font-size: 0.28rem;
-          color: #fff;
-          margin: 0;
-          background: rgba(0,0,0,0);
-          border-radius: 0;
-          &.active a {
-            color: #fff;
-            border-bottom: 0.02rem solid #fff;
-          }
-          a {
-            margin-left: 0 !important;
+          div {
+            color: #f1f1f1;
+            margin: 0;
+            background: rgba(0, 0, 0, 0);
+            border-radius: 0;
+            padding: 0.1rem 0.1rem;
+            &.active a {
+              color: #40b6fc;
+            }
+            &.active {
+              background: #fff;
+              border-top-left-radius: 0.05rem;
+              border-top-right-radius: 0.05rem;
+            }
+            a {
+              color: #f1f1f1;
+              font-size: 0.26rem;
+              margin-left: 0 !important;
+            }
           }
-       }
+        }
       }
     }
     .main-search-wrapper {

BIN
static/images/mobile/@2x/applyPurchase/home/app-banner_01.jpg


BIN
static/images/mobile/@2x/applyPurchase/home/app-banner_02.jpg