category.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. url: "/pages/index/index"
  65. })
  66. },
  67. toSearch() {
  68. uni.navigateTo({
  69. url: '/pages/index/home/productSearch'
  70. })
  71. },
  72. getProductCate() {
  73. getProductCate({}).then(res => {
  74. if (res.code == 200) {
  75. this.allCates = res.data;
  76. this.cates = this.allCates.filter(item => item.pid == 0);
  77. if (this.cates && this.cates.length > 0) {
  78. this.cateSelect = this.cates[0].cateId;
  79. this.getSubCate();
  80. }
  81. }
  82. });
  83. },
  84. choseCate(item) {
  85. this.cateSelect = item.cateId;
  86. this.getSubCate();
  87. },
  88. getSubCate() {
  89. this.subCates = this.allCates.filter(item => item.pid == this.cateSelect);
  90. },
  91. showProductList(item) {
  92. uni.navigateTo({
  93. url: '/pages_mall/productList?cateId=' + item.cateId + "&pid=" + item.pid
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .category-page {
  101. height: 100%;
  102. display: flex;
  103. flex-direction: column;
  104. background-color: #F5F7FA;
  105. }
  106. .custom-header {
  107. background: linear-gradient(to right, #FF233C, #4FACFE);
  108. position: fixed;
  109. top: 0;
  110. left: 0;
  111. right: 0;
  112. z-index: 100;
  113. .header-content {
  114. height: 44px;
  115. display: flex;
  116. align-items: center;
  117. justify-content: space-between;
  118. padding: 0 30rpx;
  119. .back-btn {
  120. width: 60rpx;
  121. height: 60rpx;
  122. display: flex;
  123. align-items: center;
  124. justify-content: flex-start;
  125. }
  126. .title {
  127. color: #fff;
  128. font-size: 36rpx;
  129. font-weight: bold;
  130. }
  131. .placeholder {
  132. width: 60rpx;
  133. }
  134. }
  135. }
  136. .search-wrap {
  137. padding: 20rpx 30rpx;
  138. background-color: #fff;
  139. border-bottom: 1rpx solid #f0f0f0;
  140. .search-bar {
  141. background-color: #F7F7F7;
  142. height: 72rpx;
  143. border-radius: 36rpx;
  144. display: flex;
  145. align-items: center;
  146. padding: 0 30rpx;
  147. .placeholder-text {
  148. font-size: 28rpx;
  149. color: #999;
  150. margin-left: 10rpx;
  151. }
  152. }
  153. }
  154. .category-container {
  155. flex: 1;
  156. display: flex;
  157. height: 0; // Fix flex scroll
  158. .left-aside {
  159. width: 200rpx;
  160. height: 100%;
  161. background-color: #F5F7FA;
  162. .f-item {
  163. height: 100rpx;
  164. display: flex;
  165. align-items: center;
  166. justify-content: center;
  167. font-size: 28rpx;
  168. color: #606266;
  169. position: relative;
  170. &.active {
  171. color: #FF233C;
  172. background-color: #fff;
  173. font-weight: bold;
  174. &::before {
  175. content: '';
  176. position: absolute;
  177. left: 0;
  178. top: 30rpx;
  179. bottom: 30rpx;
  180. width: 8rpx;
  181. background-color: #FF233C;
  182. border-radius: 0 4rpx 4rpx 0;
  183. }
  184. }
  185. }
  186. }
  187. .right-aside {
  188. flex: 1;
  189. height: 100%;
  190. background-color: #fff;
  191. padding: 20rpx;
  192. .s-list {
  193. display: flex;
  194. flex-wrap: wrap;
  195. .s-item {
  196. width: 33.33%;
  197. display: flex;
  198. flex-direction: column;
  199. align-items: center;
  200. margin-bottom: 40rpx;
  201. .cate-img {
  202. width: 120rpx;
  203. height: 120rpx;
  204. border-radius: 12rpx;
  205. background-color: #f5f5f5;
  206. margin-bottom: 16rpx;
  207. }
  208. text {
  209. font-size: 24rpx;
  210. color: #333;
  211. text-align: center;
  212. padding: 0 10rpx;
  213. }
  214. }
  215. .empty-tip {
  216. width: 100%;
  217. text-align: center;
  218. color: #999;
  219. font-size: 26rpx;
  220. padding-top: 100rpx;
  221. }
  222. }
  223. }
  224. }
  225. </style>