Showing
1 changed file
with
12 additions
and
44 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:25:29 | 4 | + * @LastEditTime: 2024-10-29 14:48:43 |
| 5 | * @FilePath: /hager/src/views/product/index.vue | 5 | * @FilePath: /hager/src/views/product/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
| 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="'与“' + search_keyword + '”相关的搜索结果'" :sub="''" style="margin: 2rem 0;"></hager-h1> | 19 | + <hager-h1 v-else :title="'与“' + 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"> |
| ... | @@ -65,38 +65,21 @@ export default { | ... | @@ -65,38 +65,21 @@ export default { |
| 65 | mixins: [mixin.init], | 65 | mixins: [mixin.init], |
| 66 | data () { | 66 | data () { |
| 67 | return { | 67 | return { |
| 68 | - search_keyword: this.$route.query.search_keyword, | 68 | + search_keyword: '', |
| 69 | + keyword: '', | ||
| 69 | activeNames: [], | 70 | activeNames: [], |
| 70 | parent_name: '', | 71 | parent_name: '', |
| 71 | category_name: '', | 72 | category_name: '', |
| 72 | category_name_en: '', | 73 | category_name_en: '', |
| 73 | - cate_list: [{ | 74 | + cate_list: [], |
| 74 | - title: '低压主配电', | ||
| 75 | - name: '1', | ||
| 76 | - list: [{ | ||
| 77 | - id: '', | ||
| 78 | - name: 'acb hw01 空气断路器' | ||
| 79 | - }] | ||
| 80 | - }, { | ||
| 81 | - title: '分配电', | ||
| 82 | - name: '2', | ||
| 83 | - list: [{ | ||
| 84 | - id: '', | ||
| 85 | - name: 'acb hw01 空气断路器' | ||
| 86 | - }] | ||
| 87 | - }], | ||
| 88 | product_list: [], | 75 | product_list: [], |
| 89 | no_product_img: 'https://cdn.ipadbiz.cn/hager/img/no-product-img.png', | 76 | no_product_img: 'https://cdn.ipadbiz.cn/hager/img/no-product-img.png', |
| 77 | + is_search: false, | ||
| 90 | } | 78 | } |
| 91 | }, | 79 | }, |
| 92 | async mounted () { | 80 | async mounted () { |
| 93 | this.getMain(); | 81 | this.getMain(); |
| 94 | }, | 82 | }, |
| 95 | - computed: { | ||
| 96 | - is_search () { | ||
| 97 | - return this.$route.query.search_keyword; | ||
| 98 | - } | ||
| 99 | - }, | ||
| 100 | watch: { | 83 | watch: { |
| 101 | // 监听路由参数变化时,更新输入框的值 | 84 | // 监听路由参数变化时,更新输入框的值 |
| 102 | async '$route.query.id' (val, old) { | 85 | async '$route.query.id' (val, old) { |
| ... | @@ -123,11 +106,8 @@ export default { | ... | @@ -123,11 +106,8 @@ export default { |
| 123 | this.parent_name = info.parent_name; | 106 | this.parent_name = info.parent_name; |
| 124 | this.category_name = info.category_name; | 107 | this.category_name = info.category_name; |
| 125 | this.category_name_en = info.category_name_en; | 108 | this.category_name_en = info.category_name_en; |
| 126 | - if (!this.search_keyword) { | ||
| 127 | this.product_list = info.list; | 109 | this.product_list = info.list; |
| 128 | - } else { | 110 | + this.search_keyword = ''; |
| 129 | - this.goToSearch() | ||
| 130 | - } | ||
| 131 | // 获取当前类别的内容 | 111 | // 获取当前类别的内容 |
| 132 | this.getCurrentCate(info.category_parent); | 112 | this.getCurrentCate(info.category_parent); |
| 133 | } | 113 | } |
| ... | @@ -143,29 +123,17 @@ export default { | ... | @@ -143,29 +123,17 @@ export default { |
| 143 | } | 123 | } |
| 144 | }, | 124 | }, |
| 145 | async goToSearch () { | 125 | async goToSearch () { |
| 126 | + if (this.search_keyword) { // 产品有值时操作 | ||
| 146 | const { code, data } = await getProductSearchAPI({ keyword: this.search_keyword }); | 127 | const { code, data } = await getProductSearchAPI({ keyword: this.search_keyword }); |
| 147 | if (code) { | 128 | if (code) { |
| 148 | this.product_list = data; | 129 | this.product_list = data; |
| 130 | + this.is_search = true; | ||
| 131 | + this.keyword = this.search_keyword; | ||
| 149 | } | 132 | } |
| 150 | - if (this.search_keyword) { // 产品有值时操作 | ||
| 151 | - // | ||
| 152 | - this.$router.replace({ | ||
| 153 | - path: this.$route.path, | ||
| 154 | - query: { | ||
| 155 | - ...this.$route.query, | ||
| 156 | - search_keyword: this.search_keyword | ||
| 157 | - } | ||
| 158 | - }); | ||
| 159 | } else { // 清空搜索值,还原 | 133 | } else { // 清空搜索值,还原 |
| 160 | this.getMain(); | 134 | this.getMain(); |
| 161 | - // 清空搜索值 | 135 | + this.is_search = false; |
| 162 | - this.$router.replace({ | 136 | + this.keyword = ''; |
| 163 | - path: this.$route.path, | ||
| 164 | - query: { | ||
| 165 | - ...this.$route.query, | ||
| 166 | - search_keyword: '' | ||
| 167 | - } | ||
| 168 | - }); | ||
| 169 | } | 137 | } |
| 170 | }, | 138 | }, |
| 171 | } | 139 | } | ... | ... |
-
Please register or login to post a comment