category.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="container">
  3. <view class="search-wrap">
  4. <u-search placeholder="搜索" disabled height="32" :show-action="false" @click="handleSearchClick"></u-search>
  5. </view>
  6. <view class="category-box">
  7. <view class="box-left">
  8. <view>
  9. <view class="category-item" v-for="(item, index) in categoryList" :key="item.id">
  10. <view class="item-title" :class="{ active: currentIndex === index }" @click="handleCategoryClick(index)">
  11. <text>{{ item.name }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="box-right">
  17. <image class="category-image" :showLoading="true" :src="categoryList[currentIndex].image" width="530rpx" height="160rpx" @click="click"></image>
  18. <view class="sub-category-box" v-for="(item, index) in categoryList[currentIndex].children" :key="item.id">
  19. <view class="sub-category-header">
  20. <view class="title">{{ item.title }}</view>
  21. <view class="more">查看更多</view>
  22. </view>
  23. <u-grid class="sub-category-grid" col="3">
  24. <u-grid-item v-for="(subItem, subIndex) in item.category" :key="subItem.id">
  25. <view class="sub-category-item">
  26. <u-icon name="photo" :size="80"></u-icon>
  27. <text class="sub-category-title">{{ subItem.title }}</text>
  28. </view>
  29. </u-grid-item>
  30. </u-grid>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. currentIndex: 0,
  41. categoryList: []
  42. }
  43. },
  44. onLoad() {
  45. for (let i = 0; i < 10; i++) {
  46. this.categoryList.push({
  47. id: i,
  48. image: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  49. name: '商品分类' + i,
  50. children: [
  51. {
  52. id: 0,
  53. title: '分类' + i + '-1',
  54. category: [
  55. {
  56. id: 0,
  57. image: '',
  58. title: '分类' + i + '-1-1'
  59. },
  60. {
  61. id: 2,
  62. image: '',
  63. title: '分类' + i + '-1-2'
  64. },
  65. {
  66. id: 3,
  67. image: '',
  68. title: '分类' + i + '-1-3'
  69. }
  70. ]
  71. },
  72. {
  73. id: 1,
  74. title: '分类' + i + '-2',
  75. category: [
  76. {
  77. id: 0,
  78. image: '',
  79. title: '分类' + i + '-2-1'
  80. },
  81. {
  82. id: 2,
  83. image: '',
  84. title: '分类' + i + '-2-2'
  85. },
  86. {
  87. id: 3,
  88. image: '',
  89. title: '分类' + i + '-2-3'
  90. }
  91. ]
  92. }
  93. ]
  94. })
  95. }
  96. },
  97. methods: {
  98. handleSearchClick(e) {
  99. uni.$u.route('/pages/search/search')
  100. },
  101. handleCategoryClick(index) {
  102. if (this.currentIndex !== index) {
  103. this.currentIndex = index
  104. }
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .search-wrap {
  111. background: $custom-bg-color;
  112. padding: 20rpx;
  113. }
  114. .category-box {
  115. display: flex;
  116. .box-left {
  117. width: 200rpx;
  118. padding-top: 20rpx;
  119. border-right: $custom-border-style;
  120. .category-item {
  121. border-bottom: $custom-border-style;
  122. padding: 20rpx 0;
  123. .item-title {
  124. padding-left: 30rpx;
  125. font-size: 28rpx;
  126. &.active {
  127. border-left: 6rpx solid $u-primary;
  128. font-weight: 700;
  129. }
  130. }
  131. }
  132. }
  133. .box-right {
  134. flex: 1;
  135. .category-image {
  136. width: 510rpx;
  137. height: 160rpx;
  138. padding: 20rpx;
  139. }
  140. .sub-category-box {
  141. .sub-category-header {
  142. @include flex-space-between;
  143. padding: 30rpx 20rpx;
  144. .title {
  145. font-size: 28rpx;
  146. font-weight: 700;
  147. }
  148. .more {
  149. font-size: 22rpx;
  150. color: #939393;
  151. }
  152. }
  153. .sub-category-grid {
  154. padding: 0 15rpx;
  155. .sub-category-item {
  156. @include flex-center(column);
  157. background: #fff;
  158. .sub-category-title {
  159. margin: 15rpx 0;
  160. font-size: 24rpx;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </style>