Przeglądaj źródła

feat: 移动端搜索后,保存上次搜索条件

cuiyalong 1 rok temu
rodzic
commit
d500d38996

+ 0 - 1
apps/mobile/src/components/search/bidding/filters.vue

@@ -1084,7 +1084,6 @@ export default {
     onChange(value) {
       const filters = {}
       Object.assign(filters, this.filters, value)
-      console.log('----', filters.area)
       this.$emit('change', filters)
     },
     popupState(type, state = false) {

+ 3 - 0
apps/mobile/src/utils/constant/others.js

@@ -5,3 +5,6 @@ export const customerServiceTel = '400-108-6670'
 
 // 用于存储的key, 用于判断是否访问过引导页
 export const GUIDE_CACHE_KEY = 'READ_GUIDE'
+
+// 标讯搜索-上次搜索筛选项缓存key
+export const BIDDING_SEARCH_LAST_FILTERS_CACHE_KEY = 'bidding-search-last-filters'

+ 2 - 2
apps/mobile/src/views/search/filter-history/bidding.vue

@@ -165,7 +165,7 @@
                 </span>
               </div>
               <div
-                class="header-left-sub-title card-item sub-text"
+                class="header-left-sub-title sub-text"
                 v-if="history.searchModeText"
               >
                 <span class="item-label">搜索模式:</span>
@@ -852,7 +852,7 @@ export default {
   }
 
   .card-content {
-    padding-right: 58px;
+    padding-right: 66px;
   }
 }
 

+ 47 - 9
apps/mobile/src/views/search/middle/bidding/index.vue

@@ -37,6 +37,7 @@ import {
   filterHistoryNotEmptyFormat
 } from '@/utils/'
 import { mixinPoints } from '@/utils/mixins/modules/points'
+import { BIDDING_SEARCH_LAST_FILTERS_CACHE_KEY } from '@/utils/constant'
 import { mapActions, mapGetters } from 'vuex'
 
 export default {
@@ -54,18 +55,29 @@ export default {
   data() {
     return {
       searchGroup: '',
-      filterHistory: []
+      filterHistory: [],
+      lastFilters: {},
+      lastFiltersFormatted: {}
     }
   },
   computed: {
-    ...mapGetters('user', ['isFree', 'isLogin']),
+    ...mapGetters('user', ['isFree', 'isLogin', 'isMember', 'isSuper']),
     ...mapGetters('search', ['biddingSearchHistory'])
   },
   async created() {
     this.getQueryString()
     if (this.isLogin) {
       this.loadList()
-      this.getFilterHistoryList()
+      try {
+        await this.getFilterHistoryList()
+      } catch (error) {
+        console.log(error)        
+      } finally {
+        if (this.isMember || this.isSuper) {
+          // 获取默认筛选项
+          this.getLastFilters()
+        }
+      }
     }
   },
   methods: {
@@ -83,12 +95,32 @@ export default {
         this.searchGroup = searchGroup
       }
     },
-    submit(params) {
+    getLastFilters() {
+      const lastFilters = this.$storage.get(BIDDING_SEARCH_LAST_FILTERS_CACHE_KEY, false)
+      if (lastFilters) {
+        this.lastFilters = lastFilters
+        const card = this.formatFilterItems(lastFilters)
+        this.lastFiltersFormatted = card
+        this.syncInput(card.keywordsText)
+      } else {
+        // 获取已存筛选列表第一个
+        const list = this.filterHistory
+        if (Array.isArray(list) && list.length > 0) {
+          const card = list[0]
+          this.lastFiltersFormatted = card
+          this.syncInput(card.keywordsText)
+        }
+      }
+    },
+    syncInput(text = '') {
+      this.topSearch.input = text
+    },
+    submit(e, p) {
       // 历史记录新增
       this.setHistory({
         type: 'bidding',
         item: {
-          label: this.topSearch.input
+          label: e || this.topSearch.input
         }
       })
       const query = {
@@ -97,6 +129,11 @@ export default {
       if (this.searchGroup) {
         query.searchGroup = this.searchGroup
       }
+
+      const params = p || {
+        filters: this.lastFiltersFormatted
+      }
+
       this.$nextTick(() => {
         this.$router.push({
           name: 'search-bidding',
@@ -138,17 +175,18 @@ export default {
      * 可全局搜索 <restoreFilter> 函数
      */
     restoreFilter(card) {
-      this.topSearch.input = card.keywordsText
+      this.syncInput(card.keywordsText)
       this.$nextTick(() => {
-        this.submit({
+        this.submit(card.keywordsText, {
           filters: card
         })
       })
     },
     goPage(data) {
-      this.topSearch.input = data.label
+      const keyword = data.label || ''
+      this.syncInput(keyword)
       this.$nextTick(() => {
-        this.submit()
+        this.submit(keyword)
       })
     },
     async getFilterHistoryList() {

+ 26 - 9
apps/mobile/src/views/search/result/bidding/index.vue

@@ -404,6 +404,7 @@ import { AppIcon, AppEmpty, ProjectCell } from '@/ui'
 import { setUserSubInfo, getFreeSubscribeInfo } from '@/api/modules/public'
 import { leadGetDate } from '@/api/modules/leadGeneration'
 import { LINKS } from '@/data'
+import { BIDDING_SEARCH_LAST_FILTERS_CACHE_KEY } from '@/utils/constant'
 import { throttle } from 'lodash'
 import toLogin from '@/utils/mixins/modules/to-login'
 import { mixinPoints } from '@/utils/mixins/modules/points'
@@ -1056,13 +1057,14 @@ export default {
       const { searchFilters = {} } = this.$refs
       let { filters } = this.$route.params
       if (!filters) {
+        // 取标讯详情页-推荐项目模块-查看更多 跳转过来带的筛选条件
         filters = this.$storage.get('bidding-search-filters-restore', false, {
           storage: sessionStorage,
           login: true
         })
       }
       console.log(filters)
-      if (!filters) return
+      if (!filters || Object.keys(filters).length === 0) return
       const { getScopeOptions = [], getTimeOptions = [] } = searchFilters
       this.topSearch.input = filters.keywords.join(' ')
       // 恢复searchGroup
@@ -1204,6 +1206,7 @@ export default {
     },
     doSearch(conf = {}) {
       const { from } = conf
+      this.saveFilterToLocal()
       if (from === 'searchModeAutoChangedSearch') {
         // 当前搜索来自 自动切换搜索模式
         // do something...
@@ -2036,8 +2039,8 @@ export default {
         console.warn(error)
       }
     },
-    // 保存筛选条件
-    async saveFilterToHistory() {
+    // 获取已存筛选的参数
+    getSaveFilterToHistoryParams() {
       const params = this.getFilterParams2()
 
       delete params.scope
@@ -2045,6 +2048,15 @@ export default {
       if (params.subtype) {
         params.subtype = params.subtype.replace('拟建项目', '拟建')
       }
+      return {
+        ...params,
+        regionMap: this.filters.area
+      }
+    },
+    // 保存筛选条件
+    async saveFilterToHistory() {
+      const params = this.getSaveFilterToHistoryParams()
+
       // if (!params.searchvalue) {
       //   return this.$toast('请先输入关键词')
       // }
@@ -2053,10 +2065,7 @@ export default {
         return this.$toast(`对不起,最多可保存${maxCount}个筛选条件。`)
       }
       const loading = this.$toast.loading({ duration: 0 })
-      const resultParams = {
-        ...params,
-        regionMap: this.filters.area
-      }
+      const resultParams = params
       try {
         const {
           data: id,
@@ -2087,13 +2096,12 @@ export default {
     },
     async beforeFilterHistoryDialogClose(action, done) {
       if (action === 'confirm') {
-        const params = this.getFilterParams2()
+        const params = this.getSaveFilterToHistoryParams()
         const { currentFilterParamsKey } = this.pageState
         try {
           const { error_code: code = 0, error_msg: msg } =
             await addBiddingFilter({
               ...params,
-              regionMap: this.filters.area,
               inkey: currentFilterParamsKey
             })
           if (code === 0) {
@@ -2307,6 +2315,15 @@ export default {
       }
       this.doSearch()
     },
+    // 保存筛选条件到本地
+    saveFilterToLocal() {
+      // 将已存筛选的筛选条件保存到本地,恢复时候可以走已存筛选的恢复
+      const params = this.getSaveFilterToHistoryParams()
+      this.$storage.set(
+        BIDDING_SEARCH_LAST_FILTERS_CACHE_KEY,
+        params
+      )
+    },
     beforeTabActiveChange(name) {
       if (name === 'detailedList') {
         if (this.noLoginOrFree) {