category.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. // #ifdef MP-WEIXIN
  50. // 小程序默认分享
  51. uni.showShareMenu({ withShareTicket: true });
  52. // #endif
  53. },
  54. methods: {
  55. /**
  56. * 查询
  57. */
  58. search() {
  59. uni.navigateTo({
  60. url: "/pages/navigation/search/searchPage",
  61. });
  62. },
  63. /**
  64. * 加载图片
  65. */
  66. async loadData() {
  67. let list = await getCategoryList(0);
  68. this.tabList = list.data.result;
  69. this.currentId = list.data.result[0].id;
  70. this.loadListContent(0);
  71. },
  72. /**
  73. * 加载列表内容
  74. */
  75. loadListContent(index) {
  76. this.topImg = this.tabList[index];
  77. this.categoryList = this.tabList[index].children;
  78. },
  79. /**
  80. * 一级分类点击
  81. */
  82. tabtap(item, i) {
  83. if (item.id != this.currentId) {
  84. this.currentId = item.id;
  85. this.loadListContent(i);
  86. }
  87. },
  88. navigateToList(sid, tid) {
  89. uni.navigateTo({
  90. url: `/pages/navigation/search/searchPage?category=${tid}`,
  91. });
  92. },
  93. },
  94. };
  95. </script>
  96. <style lang="scss" scoped>
  97. page {
  98. height: 100%;
  99. background-color: #fdfaff;
  100. }
  101. /* 解决小程序和app滚动条的问题 */
  102. /* #ifdef MP-WEIXIN || APP-PLUS */
  103. ::-webkit-scrollbar {
  104. display: none;
  105. }
  106. /* #endif */
  107. /* 解决H5 的问题 */
  108. /* #ifdef H5 */
  109. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  110. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  111. display: none;
  112. }
  113. /* #endif */
  114. .s-list {
  115. box-shadow: 0 4rpx 12rpx 0 rgba(0, 0, 0, 0.05);
  116. }
  117. .nav-search {
  118. padding-left: 30rpx !important;
  119. padding-right: 20rpx !important;
  120. }
  121. .title {
  122. display: block;
  123. width: 200rpx;
  124. text-align: center;
  125. font-size: 34rpx;
  126. letter-spacing: 2rpx;
  127. // #ifdef MP-WEIXIN
  128. margin-left: 26rpx;
  129. // #endif
  130. }
  131. .category-wrap {
  132. height: 100%;
  133. .content {
  134. height: calc(100vh - 94px);
  135. display: flex;
  136. color: #333;
  137. font-size: 28rpx;
  138. background: #fff;
  139. }
  140. .left-aside {
  141. flex-shrink: 0;
  142. width: 200rpx;
  143. height: 100%;
  144. background-color: #f7f7f7;
  145. }
  146. .f-item {
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. width: 100%;
  151. height: 97rpx;
  152. position: relative;
  153. &.active {
  154. font-weight: bold;
  155. color: $light-color;
  156. background: #fff;
  157. }
  158. }
  159. .right-aside {
  160. flex: 1;
  161. overflow: hidden;
  162. padding: 40rpx 0 0 30rpx;
  163. }
  164. .top-img {
  165. width: 500rpx;
  166. height: 230rpx;
  167. border-radius: 8px;
  168. overflow: hidden;
  169. image {
  170. width: 100%;
  171. height: 100%;
  172. }
  173. }
  174. .s-item {
  175. display: flex;
  176. align-items: center;
  177. height: 70rpx;
  178. padding-top: 16rpx;
  179. font-weight: 500;
  180. }
  181. .t-list {
  182. display: flex;
  183. flex-wrap: wrap;
  184. width: 100%;
  185. padding-top: 12rpx;
  186. }
  187. .margin-right {
  188. margin-right: 0 !important;
  189. }
  190. .t-item {
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. flex-direction: column;
  195. width: 150rpx;
  196. margin-right: 25rpx;
  197. font-size: 24rpx;
  198. padding-bottom: 20rpx;
  199. image {
  200. width: 140rpx;
  201. height: 140rpx;
  202. border-radius: 8px;
  203. margin-bottom: 20rpx;
  204. }
  205. /deep/ .u-image {
  206. width: 140rpx !important;
  207. height: 140rpx !important;
  208. border-radius: 8px !important;
  209. margin-bottom: 20rpx !important;
  210. }
  211. }
  212. }
  213. </style>