瀏覽代碼

修改品牌搜索联想词逻辑

yangc 7 年之前
父節點
當前提交
bad218668f
共有 2 個文件被更改,包括 30 次插入26 次删除
  1. 29 25
      components/mobile/base/SearchHeader.vue
  2. 1 1
      components/mobile/brand/BrandCenter.vue

+ 29 - 25
components/mobile/base/SearchHeader.vue

@@ -19,15 +19,15 @@
     </ul>
     <ul v-if="emptyStatus && type == 'default' && keyword && keyword !== '' && showSimilarWord">
       <template v-if="similarList.brand && similarList.brand.length && (similarType == 'all' || similarType == 'brand')">
-        <li class="title text-ellipse">品牌</li>
+        <li class="title text-ellipse" v-if="similarType == 'all'">品牌</li>
         <li class="text-ellipse" v-for="brand in similarList.brand.slice(0, 4)" @click="onSearch(brand.nameEn, 'brand', $event)">{{brand.nameEn}}</li>
       </template>
       <template v-if="similarList.kind && similarList.kind.length && (similarType == 'all' || similarType == 'kind')">
-        <li class="title text-ellipse">类目(产品名称)</li>
+        <li class="title text-ellipse" v-if="similarType == 'all'">类目(产品名称)</li>
         <li class="text-ellipse" v-for="kind in similarList.kind.slice(0, 4)" @click="onSearch(kind.nameCn, 'kind', $event)">{{kind.nameCn}}</li>
       </template>
       <template v-if="similarList.component && similarList.component.length && (similarType == 'all' || similarType == 'code')">
-        <li class="title text-ellipse">型号</li>
+        <li class="title text-ellipse" v-if="similarType == 'all'">型号</li>
         <li class="text-ellipse" v-for="code in similarList.component.slice(0, 4)" @click="onSearch(code.code, 'code', $event)">{{code.code}}</li>
       </template>
     </ul>
@@ -53,13 +53,17 @@
         type: Boolean,
         default: true
       },
-      outerKeyword: {
+      outerKeyword: { // 提示keyword
         type: String,
         default: ''
       },
-      similarType: {
+      similarType: { // 选择出现的联想词类型
         type: String,
         default: 'all'
+      },
+      useMatchRule: {
+        type: Boolean,
+        default: true
       }
     },
     data () {
@@ -108,55 +112,55 @@
 //        if (key === this.searchKeyword || this.keyword === this.searchKeyword) {
 //          return
 //        }
-        if (key) {
-          this.keyword = key
+        if (key || !this.useMatchRule) {
+          this.keyword = key || this.keyword
           this.$emit('searchAction', {
             keyword: this.keyword,
             type: type
           })
         } else {
           let sType = null
-          if (this.type === 'default' && this.keyword && this.keyword !== '' && this.similarList.component) {
-            if (this.similarList.component[0] && this.keyword === this.similarList.component[0].code) {
-              sType = 'code'
-            } else if (this.similarList.brand[0] && this.keyword === this.similarList.brand[0].nameEn) {
+          if (this.type === 'default' && this.keyword && this.keyword !== '' && this.similarList.brand) { // 防止接口报错无法搜索
+            if (this.similarList.brand[0] && this.keyword === this.similarList.brand[0].nameEn) {
               sType = 'brand'
             } else if (this.similarList.kind[0] && this.keyword === this.similarList.kind[0].nameCn) {
               sType = 'kind'
+            } else if (this.similarList.component[0] && this.keyword === this.similarList.component[0].code) {
+              sType = 'code'
             } else {
-              let arr = [...this.similarList.component, ...this.similarList.brand, ...this.similarList.kind]
+              let arr = [...this.similarList.brand, ...this.similarList.kind, ...this.similarList.component]
               if (arr[0]) {
-                if (arr[0].code) {
-                  this.keyword = arr[0].code
-                  sType = 'code'
-                } else if (arr[0].nameEn) {
+                if (arr[0].nameEn) {
                   this.keyword = arr[0].nameEn
                   sType = 'brand'
                 } else if (arr[0].nameCn) {
                   this.keyword = arr[0].nameCn
                   sType = 'kind'
+                } else if (arr[0].code) {
+                  this.keyword = arr[0].code
+                  sType = 'code'
                 }
               }
             }
-          } else if (this.type === 'supplier' && this.keyword && this.keyword !== '' && this.similarList.pCmpCode) {
-            if (this.similarList.pCmpCode[0] && this.keyword === this.similarList.pCmpCode[0].pCmpCode) {
-              sType = 'pCmpCode'
-            } else if (this.similarList.pBrandEn[0] && this.keyword === this.similarList.pBrandEn[0].nameEn) {
+          } else if (this.type === 'supplier' && this.keyword && this.keyword !== '' && this.similarList.pBrandEn) { // 防止接口报错无法搜索
+            if (this.similarList.pBrandEn[0] && this.keyword === this.similarList.pBrandEn[0].nameEn) {
               sType = 'pBrandEn'
             } else if (this.similarList.kind[0] && this.keyword === this.similarList.kind[0].kind) {
               sType = 'kind'
+            } else if (this.similarList.pCmpCode[0] && this.keyword === this.similarList.pCmpCode[0].pCmpCode) {
+              sType = 'pCmpCode'
             } else {
-              let arr = [...this.similarList.pCmpCode, ...this.similarList.pBrandEn, ...this.similarList.kind]
+              let arr = [...this.similarList.pBrandEn, ...this.similarList.kind, ...this.similarList.pCmpCode]
               if (arr[0]) {
-                if (arr[0].pCmpCode) {
-                  this.keyword = arr[0].pCmpCode
-                  sType = 'pCmpCode'
-                } else if (arr[0].nameEn) {
+                if (arr[0].nameEn) {
                   this.keyword = arr[0].nameEn
                   sType = 'pBrandEn'
                 } else if (arr[0].kind) {
                   this.keyword = arr[0].kind
                   sType = 'kind'
+                } else if (arr[0].pCmpCode) {
+                  this.keyword = arr[0].pCmpCode
+                  sType = 'pCmpCode'
                 }
               }
             }

+ 1 - 1
components/mobile/brand/BrandCenter.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <search-header @searchAction="onSearch" :placeholder="'请输入品牌名称'" :similarType="'brand'"></search-header>
+    <search-header @searchAction="onSearch" :placeholder="'请输入品牌名称'" :similarType="'brand'" :useMatchRule="false"></search-header>
     <div class="mobile-brand-center mobile-content">
       <div class="mobile-brand-wrap" :class="{'is-search': isSearch}">
         <div class="mobile-brand-header" v-if="!isSearch">