category.vue 4.4 KB

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