category.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="category-page">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header" :style="{paddingTop: statusBarHeight + 'px'}">
  5. <view class="header-content">
  6. <view class="back-btn" @click="goBack">
  7. <u-icon name="arrow-left" color="#fff" size="20"></u-icon>
  8. </view>
  9. <text class="title">商品分类</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 搜索栏 -->
  14. <view class="search-wrap" :style="{marginTop: (statusBarHeight + 44) + 'px'}">
  15. <view class="search-bar" @click="toSearch">
  16. <u-icon name="search" color="#999" size="20"></u-icon>
  17. <text class="placeholder-text">搜索药品名称</text>
  18. </view>
  19. </view>
  20. <view class="category-container">
  21. <!-- 左侧一级分类 -->
  22. <scroll-view scroll-y class="left-aside">
  23. <view v-for="(item, index) in cates" :key="index" class="f-item"
  24. :class="{active: item.cateId === cateSelect}" @click="choseCate(item)">
  25. {{item.cateName}}
  26. </view>
  27. </scroll-view>
  28. <!-- 右侧二级分类/商品 -->
  29. <scroll-view scroll-y class="right-aside">
  30. <view class="s-list">
  31. <view class="s-item" v-for="(item, index) in subCates" :key="index" @click="showProductList(item)">
  32. <image :src="item.pic" mode="aspectFit" class="cate-img"></image>
  33. <text>{{item.cateName}}</text>
  34. </view>
  35. <view v-if="subCates.length === 0" class="empty-tip">暂无子分类</view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. getProductCate
  44. } from '@/api/product'
  45. export default {
  46. data() {
  47. return {
  48. statusBarHeight: 20,
  49. allCates: [],
  50. cates: [],
  51. subCates: [],
  52. cateSelect: 0,
  53. }
  54. },
  55. created() {
  56. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  57. this.getProductCate();
  58. },
  59. methods: {
  60. goBack() {
  61. uni.showTabBar()
  62. uni.switchTab({
  63. url: '/pages_im/pages/conversation/conversationList/index'
  64. })
  65. },
  66. toSearch() {
  67. uni.navigateTo({
  68. url: '/pages/index/home/productSearch'
  69. })
  70. },
  71. getProductCate() {
  72. getProductCate({}).then(res => {
  73. if (res.code == 200) {
  74. this.allCates = res.data;
  75. this.cates = this.allCates.filter(item => item.pid == 0);
  76. if (this.cates && this.cates.length > 0) {
  77. this.cateSelect = this.cates[0].cateId;
  78. this.getSubCate();
  79. }
  80. }
  81. });
  82. },
  83. choseCate(item) {
  84. this.cateSelect = item.cateId;
  85. this.getSubCate();
  86. },
  87. getSubCate() {
  88. this.subCates = this.allCates.filter(item => item.pid == this.cateSelect);
  89. },
  90. showProductList(item) {
  91. uni.navigateTo({
  92. url: '/pages_mall/productList?cateId=' + item.cateId + "&pid=" + item.pid
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped lang="scss">
  99. .category-page {
  100. height: 100%;
  101. display: flex;
  102. flex-direction: column;
  103. background-color: #F5F7FA;
  104. }
  105. .custom-header {
  106. background: linear-gradient(to right, #2583EB, #4FACFE);
  107. position: fixed;
  108. top: 0;
  109. left: 0;
  110. right: 0;
  111. z-index: 100;
  112. .header-content {
  113. height: 44px;
  114. display: flex;
  115. align-items: center;
  116. justify-content: space-between;
  117. padding: 0 30rpx;
  118. .back-btn {
  119. width: 60rpx;
  120. height: 60rpx;
  121. display: flex;
  122. align-items: center;
  123. justify-content: flex-start;
  124. }
  125. .title {
  126. color: #fff;
  127. font-size: 36rpx;
  128. font-weight: bold;
  129. }
  130. .placeholder {
  131. width: 60rpx;
  132. }
  133. }
  134. }
  135. .search-wrap {
  136. padding: 20rpx 30rpx;
  137. background-color: #fff;
  138. border-bottom: 1rpx solid #f0f0f0;
  139. .search-bar {
  140. background-color: #F7F7F7;
  141. height: 72rpx;
  142. border-radius: 36rpx;
  143. display: flex;
  144. align-items: center;
  145. padding: 0 30rpx;
  146. .placeholder-text {
  147. font-size: 28rpx;
  148. color: #999;
  149. margin-left: 10rpx;
  150. }
  151. }
  152. }
  153. .category-container {
  154. flex: 1;
  155. display: flex;
  156. height: 0; // Fix flex scroll
  157. .left-aside {
  158. width: 200rpx;
  159. height: 100%;
  160. background-color: #F5F7FA;
  161. .f-item {
  162. height: 100rpx;
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. font-size: 28rpx;
  167. color: #606266;
  168. position: relative;
  169. &.active {
  170. color: #2583EB;
  171. background-color: #fff;
  172. font-weight: bold;
  173. &::before {
  174. content: '';
  175. position: absolute;
  176. left: 0;
  177. top: 30rpx;
  178. bottom: 30rpx;
  179. width: 8rpx;
  180. background-color: #2583EB;
  181. border-radius: 0 4rpx 4rpx 0;
  182. }
  183. }
  184. }
  185. }
  186. .right-aside {
  187. flex: 1;
  188. height: 100%;
  189. background-color: #fff;
  190. padding: 20rpx;
  191. .s-list {
  192. display: flex;
  193. flex-wrap: wrap;
  194. .s-item {
  195. width: 33.33%;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. margin-bottom: 40rpx;
  200. .cate-img {
  201. width: 120rpx;
  202. height: 120rpx;
  203. border-radius: 12rpx;
  204. background-color: #f5f5f5;
  205. margin-bottom: 16rpx;
  206. }
  207. text {
  208. font-size: 24rpx;
  209. color: #333;
  210. text-align: center;
  211. padding: 0 10rpx;
  212. }
  213. }
  214. .empty-tip {
  215. width: 100%;
  216. text-align: center;
  217. color: #999;
  218. font-size: 26rpx;
  219. padding-top: 100rpx;
  220. }
  221. }
  222. }
  223. }
  224. </style>