Ver código fonte

店铺搜索接口 点击切换代理经销和原厂最后一页后数据不会返回第一页

huangb 7 anos atrás
pai
commit
c4e93837fe

+ 25 - 11
components/common/PcSearchHeader.vue

@@ -59,9 +59,14 @@
       useMatchRule: {
         type: Boolean,
         default: false
+      },
+      storeTypes: {
+        type: String,
+        default: ''
       }
+      // storeTypes  ''
     },
-    data () {
+    data() {
       return {
         keyword: '',
         similarList: {},
@@ -78,7 +83,7 @@
         immediate: true
       }
     },
-    mounted () {
+    mounted() {
       this.$nextTick(() => {
         document.onclick = () => {
           this.showSimilarWord = false
@@ -86,7 +91,7 @@
       })
     },
     computed: {
-      emptyStatus () {
+      emptyStatus() {
         let similarList = this.similarList
         return (similarList.component && similarList.component.length) ||
           (similarList.brand && similarList.brand.length) ||
@@ -120,7 +125,7 @@
             } else if (this.similarList.component[0] && this.keyword === this.similarList.component[0].code) {
               sType = 'code'
             } else {
-              let arr = [ ...this.similarList.store, ...this.similarList.brand, ...this.similarList.kind, ...this.similarList.component]
+              let arr = [...this.similarList.store, ...this.similarList.brand, ...this.similarList.kind, ...this.similarList.component]
               if (arr[0]) {
                 if (arr[0].name) {
                   this.keyword = arr[0].name
@@ -147,7 +152,7 @@
         this.showSimilarWord = false
       },
       onKeywordInput: function () {
-        this.clickCount ++
+        this.clickCount++
         let count = this.clickCount
         let timer = setTimeout(() => {
           this.getSimilarList(count, timer)
@@ -156,12 +161,21 @@
       getSimilarList: function (clickCount, timer) {
         clearTimeout(timer)
         if (this.showSimilar && this.keyword && this.keyword !== '' && clickCount === this.clickCount) {
-          this.$http.get(this.similarUrl, {params: {keyword: this.keyword}}).then(
-            res => {
-              this.similarList = res.data
-              this.showSimilarWord = true
-            }
-          )
+          if (this.storeTypes === '') { // 供应商和求购
+            this.$http.get(this.similarUrl, {params: {keyword: this.keyword}}).then(
+              res => {
+                this.similarList = res.data
+                this.showSimilarWord = true
+              }
+            )
+          } else { // 走店铺
+            this.$http.get(this.similarUrl, {params: {keyword: this.keyword, storeTypes:this.storeTypes, type:'all'}}).then(
+              res => {
+                this.similarList = res.data
+                this.showSimilarWord = true
+              }
+            )
+          }
         }
       }
     }

+ 29 - 11
components/provider/Suppliers.vue

@@ -15,7 +15,7 @@
         <!--<tr>{{$data}}</tr>-->
         <tr style="height: 50px;">
           <td colspan="5">
-            <search-header :outerKeyword="keyword" @searchAction="search" :placeholder="'店铺名/品牌/物料名称/型号'"></search-header>
+            <search-header :storeTypes="storeTypes" :outerKeyword="keyword" :similarUrl="similarUrl" @searchAction="search" :placeholder="'店铺名/品牌/物料名称/型号'"></search-header>
             <a @click="goStoreApply" class="btn-sure"><button class="btn btn-primary">立即入驻</button></a>
           </td>
         </tr>
@@ -80,18 +80,16 @@ export default {
         keyword: '',
         type: 'ORIGINAL_FACTORY',
         field: ''
-      }
+      },
+      similarUrl: '/search/similarKeywords/goods',
+      storeTypes: 'ORIGINAL_FACTORY'
     }
   },
   computed: {
     storeType () {
-      if (this.pageParams) {
-        this.pageParams.page = 1
-      }
       return this.$route.params.type
     },
     stores () {
-      console.log(this.$store.state.provider.stores.storeList.data)
       return this.$store.state.provider.stores.storeList.data
     },
     user () {
@@ -137,15 +135,35 @@ export default {
 //      })
     },
     handleCurrentChange (page) {
-      this.pageParams.type = this.storeType === 'factory' ? 'ORIGINAL_FACTORY' : 'AGENCY-DISTRIBUTION'
-      this.pageParams.page = page
-      this.pageParams.keyword = this.keyword === '' ? null : this.keyword
-
-      this.pageCommodity(this.pageParams)
+      // this.$nextTick(() => {
+      if (localStorage.getItem('pageChange') === 'true') {
+        this.pageParams.type = this.storeType === 'factory' ? 'ORIGINAL_FACTORY' : 'AGENCY-DISTRIBUTION'
+        this.pageParams.page = page
+        this.pageParams.keyword = this.keyword === '' ? null : this.keyword
+        this.pageCommodity(this.pageParams)
+      }
+      // })
     },
     goStoreDetail (store) {
       window.open('/store/' + store.uuid)
     }
+  },
+  watch: {
+    '$route' (to, from) {
+      if (to.params.type === "factory") {
+        this.storeTypes = 'ORIGINAL_FACTORY'
+      } else if (to.params.type === "origin") {
+        this.storeTypes = 'AGENCY,DISTRIBUTION'
+      } else {
+        this.storeTypes = ''
+      }
+      localStorage.setItem('pageChange', 'true')
+      this.handleCurrentChange(1)
+      // if (to.fullPath)
+      // this.keyword = to.query.keyword
+      // this.displayKeyword = to.query.keyword
+      // this.setChangelistHander(to.query.choosetype)
+    }
   }
 }
 </script>

+ 1 - 0
components/provider/ToggleStore.vue

@@ -121,6 +121,7 @@ export default {
     // 切换Store
     toggleStore (type) {
       if (type === this.storeType) return
+      localStorage.setItem('pageChange', 'false')
       this.$store.dispatch('loadBanners', {type: type + '_banner_carousel'})
       this.$store.dispatch('provider/findSimilarStoreList', { page: 1, count: 10, type: type === 'factory' ? 'ORIGINAL_FACTORY' : 'AGENCY-DISTRIBUTION' })
       if (type === 'brand') {

+ 3 - 0
pages/eCommerce/home/_type.vue

@@ -42,6 +42,9 @@
         store.dispatch('provider/loadAgencyCount'),
         store.dispatch('loadStoreStatus', { op: 'check' }),
       ]) : []
+    },
+    created() {
+      localStorage.setItem('pageChange', 'true')
     }
   }
 </script>