category.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="category-wrap">
  3. <u-navbar class="navbar" :is-back="false">
  4. <div class="title"> 商品分类</div>
  5. <u-search class="nav-search" disabled @click.native="search" placeholder="搜索商品" :show-action="false"></u-search>
  6. </u-navbar>
  7. <view class="content">
  8. <scroll-view scroll-y scroll-with-animation class="left-aside">
  9. <view v-for="(item, index) in tabList" :key="item.id" class="f-item b-b" :class="{ active: item.id === currentId }" @click="tabtap(item, index)">
  10. {{ item.name }}
  11. </view>
  12. </scroll-view>
  13. <scroll-view scroll-with-animation scroll-y class="right-aside" :upper-threshold="-100" :lower-threshold="-100">
  14. <!-- 头部图片 -->
  15. <view class="top-img" id="main-top">
  16. <u-image width="500rpx" height="230rpx" @click="navigateToList(topImg.id,topImg.id)" :src="topImg.image" mode="">
  17. </u-image>
  18. </view>
  19. <view v-for="item in categoryList" :key="item.id" class="s-list" :id="'main-' + item.id">
  20. <!-- 分类标题 -->
  21. <text class="s-item">{{ item.name }}</text>
  22. <!-- 分类详情 -->
  23. <view class="t-list">
  24. <view @click="navigateToList(item.id, children.id)" v-if="children.parentId === item.id" class="t-item" v-for="(children, cIndex) in item.children" :key="children.id"
  25. :class="{ 'margin-right': (cIndex + 1) % 3 == 0 }">
  26. <u-image width="70px" height="70px" :src="children.image" :lazy-load="true">
  27. </u-image>
  28. <text>{{ children.name }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { getCategoryList } from "@/api/goods.js";
  38. export default {
  39. data() {
  40. return {
  41. currentId: 0,
  42. tabList: [], //左侧标题列表
  43. categoryList: [], //右侧分类数据列表
  44. topImg: "", //顶部图片
  45. };
  46. },
  47. onLoad() {
  48. this.loadData();
  49. },
  50. methods: {
  51. /**
  52. * 查询
  53. */
  54. search() {
  55. uni.navigateTo({
  56. url: "/pages/navigation/search/searchPage",
  57. });
  58. },
  59. /**
  60. * 加载图片
  61. */
  62. async loadData() {
  63. let list = await getCategoryList(0);
  64. this.tabList = list.data.result;
  65. this.currentId = list.data.result[0].id;
  66. this.loadListContent(0);
  67. },
  68. /**
  69. * 加载列表内容
  70. */
  71. loadListContent(index) {
  72. this.topImg = this.tabList[index];
  73. this.categoryList = this.tabList[index].children;
  74. },
  75. /**
  76. * 一级分类点击
  77. */
  78. tabtap(item, i) {
  79. if (item.id != this.currentId) {
  80. this.currentId = item.id;
  81. this.loadListContent(i);
  82. }
  83. },
  84. navigateToList(sid, tid) {
  85. uni.navigateTo({
  86. url: `/pages/navigation/search/searchPage?category=${tid}`,
  87. });
  88. },
  89. },
  90. };
  91. </script>
  92. <style lang="scss" scoped>
  93. page {
  94. height: 100%;
  95. background-color: #fdfaff;
  96. }
  97. /* 解决小程序和app滚动条的问题 */
  98. /* #ifdef MP-WEIXIN || APP-PLUS */
  99. ::-webkit-scrollbar {
  100. display: none;
  101. }
  102. /* #endif */
  103. /* 解决H5 的问题 */
  104. /* #ifdef H5 */
  105. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  106. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  107. display: none;
  108. }
  109. /* #endif */
  110. .s-list{
  111. box-shadow: 0 4rpx 12rpx 0 rgba(0, 0, 0, 0.05);
  112. }
  113. .nav-search {
  114. padding-left: 30rpx !important;
  115. padding-right: 20rpx !important;
  116. }
  117. .title {
  118. display: block;
  119. width: 200rpx;
  120. text-align: center;
  121. font-size: 34rpx;
  122. letter-spacing: 2rpx;
  123. // #ifdef MP-WEIXIN
  124. margin-left: 26rpx;
  125. // #endif
  126. }
  127. .category-wrap {
  128. height: 100%;
  129. .content {
  130. height: calc(100vh - 94px);
  131. display: flex;
  132. color: #333;
  133. font-size: 28rpx;
  134. background: #fff;
  135. }
  136. .left-aside {
  137. flex-shrink: 0;
  138. width: 200rpx;
  139. height: 100%;
  140. background-color: #f7f7f7;
  141. }
  142. .f-item {
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. width: 100%;
  147. height: 97rpx;
  148. position: relative;
  149. &.active {
  150. font-weight: bold;
  151. color: $light-color;
  152. background: #fff;
  153. }
  154. }
  155. .right-aside {
  156. flex: 1;
  157. overflow: hidden;
  158. padding: 40rpx 0 0 30rpx;
  159. }
  160. .top-img {
  161. width: 500rpx;
  162. height: 230rpx;
  163. border-radius: 8px;
  164. overflow: hidden;
  165. image {
  166. width: 100%;
  167. height: 100%;
  168. }
  169. }
  170. .s-item {
  171. display: flex;
  172. align-items: center;
  173. height: 70rpx;
  174. padding-top: 16rpx;
  175. font-weight: 500;
  176. }
  177. .t-list {
  178. display: flex;
  179. flex-wrap: wrap;
  180. width: 100%;
  181. padding-top: 12rpx;
  182. }
  183. .margin-right {
  184. margin-right: 0 !important;
  185. }
  186. .t-item {
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. flex-direction: column;
  191. width: 150rpx;
  192. margin-right: 25rpx;
  193. font-size: 24rpx;
  194. padding-bottom: 20rpx;
  195. image {
  196. width: 140rpx;
  197. height: 140rpx;
  198. border-radius: 8px;
  199. margin-bottom: 20rpx;
  200. }
  201. /deep/ .u-image {
  202. width: 140rpx !important;
  203. height: 140rpx !important;
  204. border-radius: 8px !important;
  205. margin-bottom: 20rpx !important;
  206. }
  207. }
  208. }
  209. </style>