| 
									
										
										
										
											2022-04-06 16:08:26 +08:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |   <view class="container"> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |     <!-- 搜索框 --> | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |     <view class="search-wrap"> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |       <u-search placeholder="搜索" disabled height="32" bgColor="#f2f2f2" margin="0 20rpx" :show-action="false" | 
					
						
							|  |  |  |         @click="handleSearchClick"></u-search> | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |     </view> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     <!-- 分类内容 --> | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |     <view class="category-box"> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |       <!-- 左侧导航栏 --> | 
					
						
							|  |  |  |       <scroll-view scroll-y="true" class='box-left'> | 
					
						
							|  |  |  |         <view class="category-item" v-for="(item, index) in categoryList" :key="item.id"> | 
					
						
							|  |  |  |           <view class="item-title" :class="{ active: currentIndex === index }" @click="handleCategoryClick(index)"> | 
					
						
							|  |  |  |             <text>{{ item.name }}</text> | 
					
						
							| 
									
										
										
										
											2022-04-19 17:58:39 +08:00
										 |  |  |           </view> | 
					
						
							|  |  |  |         </view> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |       </scroll-view> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <!-- 右侧分类内容 --> | 
					
						
							|  |  |  |       <scroll-view scroll-y="true" class="box-right"> | 
					
						
							|  |  |  |         <view class="category-image"> | 
					
						
							| 
									
										
										
										
											2022-07-30 21:24:05 +08:00
										 |  |  |           <image :showLoading="true" :src="categoryList[currentIndex].picUrl" mode='widthFix' @click="click"></image> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |         </view> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-17 14:43:07 +08:00
										 |  |  |         <view class="sub-category-box" v-for="(item, index) in categoryList[currentIndex].children" :key="item.id"> | 
					
						
							|  |  |  |           <view class="sub-category-header"> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |             <view class="title">{{ item.name }}</view> | 
					
						
							|  |  |  |             <view class="more" @click="handleCategory(item, 0)">查看更多</view> | 
					
						
							|  |  |  |           </view> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <view class="sub-category-grid"> | 
					
						
							|  |  |  |             <u-grid col="3"> | 
					
						
							|  |  |  |               <u-grid-item v-for="(subItem, subIndex) in item.children" :key="subItem.id"> | 
					
						
							|  |  |  |                 <view class="sub-category-item" @click="handleCategory(item, subIndex)"> | 
					
						
							| 
									
										
										
										
											2022-07-30 21:24:05 +08:00
										 |  |  |                   <u-icon name="photo" :size="80" v-if="subItem.picUrl === null"></u-icon> | 
					
						
							| 
									
										
										
										
											2022-12-14 20:32:44 +08:00
										 |  |  |                   <image :src="subItem.picUrl" v-if="subItem.picUrl != null" mode='widthFix' /> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |                   <text class="sub-category-title">{{ subItem.name }}</text> | 
					
						
							|  |  |  |                 </view> | 
					
						
							|  |  |  |               </u-grid-item> | 
					
						
							|  |  |  |             </u-grid> | 
					
						
							| 
									
										
										
										
											2022-04-17 14:43:07 +08:00
										 |  |  |           </view> | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |         </view> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |       </scroll-view> | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |     </view> | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |   </view> | 
					
						
							| 
									
										
										
										
											2022-04-06 16:08:26 +08:00
										 |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |   import { categoryListData } from '../../api/category'; | 
					
						
							|  |  |  |   import { handleTree, convertTree } from '../../utils/tree.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   export default { | 
					
						
							|  |  |  |     data() { | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         currentIndex: 0, | 
					
						
							|  |  |  |         categoryList: [] | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |     onLoad() { | 
					
						
							|  |  |  |       this.handleCategoryList(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     methods: { | 
					
						
							|  |  |  |       // 点击搜索框
 | 
					
						
							|  |  |  |       handleSearchClick(e) { | 
					
						
							|  |  |  |         uni.$u.route('/pages/search/search') | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       // 点击左侧导航栏
 | 
					
						
							|  |  |  |       handleCategoryClick(index) { | 
					
						
							|  |  |  |         if (this.currentIndex !== index) { | 
					
						
							|  |  |  |           this.currentIndex = index | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       // 获取分类列表并构建树形结构
 | 
					
						
							|  |  |  |       handleCategoryList() { | 
					
						
							|  |  |  |         categoryListData().then(res => { | 
					
						
							|  |  |  |           this.categoryList = handleTree(res.data, "id", "parentId"); | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       handleCategory(item, index){ | 
					
						
							|  |  |  |         // console.log(item)
 | 
					
						
							|  |  |  |         // console.log(index)
 | 
					
						
							|  |  |  |         uni.navigateTo({ | 
					
						
							|  |  |  |           url:"./product-list?item="+encodeURIComponent(JSON.stringify(item))+"&index="+index | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-04-06 16:08:26 +08:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style lang="scss" scoped> | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |   .search-wrap { | 
					
						
							|  |  |  |     background: #ffffff; | 
					
						
							|  |  |  |     position: fixed; | 
					
						
							|  |  |  |     top: 0; | 
					
						
							|  |  |  |     left: 0; | 
					
						
							|  |  |  |     box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.07); | 
					
						
							|  |  |  |     padding: 20rpx 0; | 
					
						
							|  |  |  |     width: 100%; | 
					
						
							|  |  |  |     z-index: 3; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   .category-box { | 
					
						
							|  |  |  |     position: fixed; | 
					
						
							|  |  |  |     display: flex; | 
					
						
							|  |  |  |     overflow: hidden; | 
					
						
							|  |  |  |     margin-top: 100rpx; | 
					
						
							|  |  |  |     height: calc(100% - 100rpx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     .box-left { | 
					
						
							|  |  |  |       width: 200rpx; | 
					
						
							|  |  |  |       padding-top: 5rpx; | 
					
						
							|  |  |  |       overflow: scroll; | 
					
						
							|  |  |  |       z-index: 2; | 
					
						
							|  |  |  |       background-color: #f2f2f2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       .category-item { | 
					
						
							|  |  |  |         line-height: 80rpx; | 
					
						
							|  |  |  |         height: 80rpx; | 
					
						
							|  |  |  |         text-align: center; | 
					
						
							|  |  |  |         color: #777; | 
					
						
							| 
									
										
										
										
											2022-04-17 14:43:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |         .item-title { | 
					
						
							|  |  |  |           font-size: 28rpx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           &.active { | 
					
						
							|  |  |  |             font-size: 28rpx; | 
					
						
							|  |  |  |             font-weight: bold; | 
					
						
							|  |  |  |             position: relative; | 
					
						
							|  |  |  |             background: #fff; | 
					
						
							|  |  |  |             color: $u-primary; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           &.active::before { | 
					
						
							|  |  |  |             position: absolute; | 
					
						
							|  |  |  |             left: 0; | 
					
						
							|  |  |  |             content: ""; | 
					
						
							|  |  |  |             width: 8rpx; | 
					
						
							|  |  |  |             height: 32rpx; | 
					
						
							|  |  |  |             top: 25rpx; | 
					
						
							|  |  |  |             background: $u-primary; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |     .box-right { | 
					
						
							|  |  |  |       width: 550rpx; | 
					
						
							|  |  |  |       height: 100%; | 
					
						
							|  |  |  |       box-sizing: border-box; | 
					
						
							|  |  |  |       z-index: 1; | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |       .category-image { | 
					
						
							|  |  |  |         width: 510rpx; | 
					
						
							|  |  |  |         box-sizing: border-box; | 
					
						
							|  |  |  |         overflow: hidden; | 
					
						
							|  |  |  |         position: relative; | 
					
						
							|  |  |  |         margin: 30rpx 20rpx 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         image { | 
					
						
							|  |  |  |           width: 100%; | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-04-17 14:43:07 +08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |       .sub-category-box { | 
					
						
							|  |  |  |         .sub-category-header { | 
					
						
							|  |  |  |           @include flex-space-between; | 
					
						
							|  |  |  |           padding: 20rpx 20rpx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           .title { | 
					
						
							|  |  |  |             font-size: 28rpx; | 
					
						
							|  |  |  |             font-weight: bolder; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           .more { | 
					
						
							|  |  |  |             font-size: 22rpx; | 
					
						
							|  |  |  |             color: #939393; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         .sub-category-grid { | 
					
						
							|  |  |  |           padding: 0 15rpx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           .sub-category-item { | 
					
						
							|  |  |  |             @include flex-center(column); | 
					
						
							|  |  |  |             background: #fff; | 
					
						
							| 
									
										
										
										
											2022-04-17 14:43:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |             image { | 
					
						
							|  |  |  |               text-align: center; | 
					
						
							|  |  |  |               width: 150rpx; | 
					
						
							|  |  |  |               height: 150rpx; | 
					
						
							|  |  |  |               line-height: 150rpx; | 
					
						
							|  |  |  |               font-size: 0; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 12:05:48 +08:00
										 |  |  |             .sub-category-title { | 
					
						
							|  |  |  |               margin: 15rpx 0; | 
					
						
							|  |  |  |               font-size: 22rpx; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-04-11 23:02:08 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-04-06 16:08:26 +08:00
										 |  |  | </style> |