Showing
1 changed file
with
33 additions
and
27 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-09-27 16:53:09 | 2 | * @Date: 2024-09-27 16:53:09 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-29 14:03:32 | 4 | + * @LastEditTime: 2024-10-29 14:25:29 |
| 5 | * @FilePath: /hager/src/views/product/index.vue | 5 | * @FilePath: /hager/src/views/product/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -16,12 +16,12 @@ | ... | @@ -16,12 +16,12 @@ |
| 16 | </el-breadcrumb> | 16 | </el-breadcrumb> |
| 17 | </div> | 17 | </div> |
| 18 | <hager-h1 v-if="!is_search" :title="category_name" :sub="category_name_en" style="margin: 2rem 0;"></hager-h1> | 18 | <hager-h1 v-if="!is_search" :title="category_name" :sub="category_name_en" style="margin: 2rem 0;"></hager-h1> |
| 19 | - <hager-h1 v-else :title="'与“' + keyword + '”相关的搜索结果'" :sub="''" style="margin: 2rem 0;"></hager-h1> | 19 | + <hager-h1 v-else :title="'与“' + search_keyword + '”相关的搜索结果'" :sub="''" style="margin: 2rem 0;"></hager-h1> |
| 20 | <el-row v-if="!is_xs" :gutter="0" style="margin: 1rem 0;"> | 20 | <el-row v-if="!is_xs" :gutter="0" style="margin: 1rem 0;"> |
| 21 | <el-col :span="6"> | 21 | <el-col :span="6"> |
| 22 | <div class="product-nav-wrapper"> | 22 | <div class="product-nav-wrapper"> |
| 23 | <div class="product-nav-title">按产品类别查找</div> | 23 | <div class="product-nav-title">按产品类别查找</div> |
| 24 | - <el-input style="margin-bottom: 0.5rem;" placeholder="请输入产品" prefix-icon="el-icon-search" v-model="keyword" @change="goToSearch"></el-input> | 24 | + <el-input style="margin-bottom: 0.5rem;" placeholder="请输入产品" prefix-icon="el-icon-search" v-model="search_keyword" @change="goToSearch"></el-input> |
| 25 | <el-collapse v-model="activeNames" @change="handleChange"> | 25 | <el-collapse v-model="activeNames" @change="handleChange"> |
| 26 | <el-collapse-item v-for="(item, index) in cate_list" :key="index" :title="item.category_name" :name="item.category_name"> | 26 | <el-collapse-item v-for="(item, index) in cate_list" :key="index" :title="item.category_name" :name="item.category_name"> |
| 27 | <div @click="goToDetail(c)" v-for="(c, idx) in item.list" :key="idx" class="p-item">{{ c.product_name }}</div> | 27 | <div @click="goToDetail(c)" v-for="(c, idx) in item.list" :key="idx" class="p-item">{{ c.product_name }}</div> |
| ... | @@ -65,7 +65,7 @@ export default { | ... | @@ -65,7 +65,7 @@ export default { |
| 65 | mixins: [mixin.init], | 65 | mixins: [mixin.init], |
| 66 | data () { | 66 | data () { |
| 67 | return { | 67 | return { |
| 68 | - keyword: '', | 68 | + search_keyword: this.$route.query.search_keyword, |
| 69 | activeNames: [], | 69 | activeNames: [], |
| 70 | parent_name: '', | 70 | parent_name: '', |
| 71 | category_name: '', | 71 | category_name: '', |
| ... | @@ -94,7 +94,7 @@ export default { | ... | @@ -94,7 +94,7 @@ export default { |
| 94 | }, | 94 | }, |
| 95 | computed: { | 95 | computed: { |
| 96 | is_search () { | 96 | is_search () { |
| 97 | - return this.$route.query.keyword; | 97 | + return this.$route.query.search_keyword; |
| 98 | } | 98 | } |
| 99 | }, | 99 | }, |
| 100 | watch: { | 100 | watch: { |
| ... | @@ -103,7 +103,7 @@ export default { | ... | @@ -103,7 +103,7 @@ export default { |
| 103 | if (old !== val) { | 103 | if (old !== val) { |
| 104 | this.getMain(); | 104 | this.getMain(); |
| 105 | } | 105 | } |
| 106 | - } | 106 | + }, |
| 107 | }, | 107 | }, |
| 108 | methods: { | 108 | methods: { |
| 109 | handleChange(val) { | 109 | handleChange(val) { |
| ... | @@ -117,14 +117,18 @@ export default { | ... | @@ -117,14 +117,18 @@ export default { |
| 117 | }); | 117 | }); |
| 118 | }, | 118 | }, |
| 119 | async getMain () { | 119 | async getMain () { |
| 120 | - const { code, data } = await getProductCateAPI( {cid: this.$route.query.id}); | 120 | + const { code, data } = await getProductCateAPI( {cid: this.$route.query.id }); |
| 121 | if (code) { | 121 | if (code) { |
| 122 | let info = data[0]; | 122 | let info = data[0]; |
| 123 | this.parent_name = info.parent_name; | 123 | this.parent_name = info.parent_name; |
| 124 | this.category_name = info.category_name; | 124 | this.category_name = info.category_name; |
| 125 | this.category_name_en = info.category_name_en; | 125 | this.category_name_en = info.category_name_en; |
| 126 | - this.product_list = info.list; | 126 | + if (!this.search_keyword) { |
| 127 | - // | 127 | + this.product_list = info.list; |
| 128 | + } else { | ||
| 129 | + this.goToSearch() | ||
| 130 | + } | ||
| 131 | + // 获取当前类别的内容 | ||
| 128 | this.getCurrentCate(info.category_parent); | 132 | this.getCurrentCate(info.category_parent); |
| 129 | } | 133 | } |
| 130 | }, | 134 | }, |
| ... | @@ -139,28 +143,30 @@ export default { | ... | @@ -139,28 +143,30 @@ export default { |
| 139 | } | 143 | } |
| 140 | }, | 144 | }, |
| 141 | async goToSearch () { | 145 | async goToSearch () { |
| 142 | - if (this.keyword) { // 产品有值时操作 | 146 | + const { code, data } = await getProductSearchAPI({ keyword: this.search_keyword }); |
| 143 | - const { code, data } = await getProductSearchAPI({ keyword: this.keyword }); | 147 | + if (code) { |
| 144 | - if (code) { | 148 | + this.product_list = data; |
| 145 | - this.product_list = data; | 149 | + } |
| 146 | - // | 150 | + if (this.search_keyword) { // 产品有值时操作 |
| 147 | - this.$router.replace({ | 151 | + // |
| 148 | - path: this.$route.path, | 152 | + this.$router.replace({ |
| 149 | - query: { | 153 | + path: this.$route.path, |
| 150 | - ...this.$route.query, | 154 | + query: { |
| 151 | - keyword: this.keyword | 155 | + ...this.$route.query, |
| 152 | - } | 156 | + search_keyword: this.search_keyword |
| 153 | - }); | 157 | + } |
| 154 | - } | 158 | + }); |
| 155 | } else { // 清空搜索值,还原 | 159 | } else { // 清空搜索值,还原 |
| 156 | - this.$router.push({ | 160 | + this.getMain(); |
| 157 | - path: '/product/index', | 161 | + // 清空搜索值 |
| 162 | + this.$router.replace({ | ||
| 163 | + path: this.$route.path, | ||
| 158 | query: { | 164 | query: { |
| 159 | - id: this.$route.query.id, | 165 | + ...this.$route.query, |
| 166 | + search_keyword: '' | ||
| 160 | } | 167 | } |
| 161 | - }) | 168 | + }); |
| 162 | } | 169 | } |
| 163 | - | ||
| 164 | }, | 170 | }, |
| 165 | } | 171 | } |
| 166 | } | 172 | } | ... | ... |
-
Please register or login to post a comment