category.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view>
  3. <view class="category-list">
  4. <!-- 左侧分类导航 -->
  5. <scroll-view scroll-y="true" class="left">
  6. <view class="row" v-for="(category, index) in categoryList" :key="index" :class="[index == showCategoryIndex ? 'on' : '']"
  7. @click="showCategory(index)">
  8. <view class="text">
  9. <view class="block"></view>
  10. {{ category.name }}
  11. </view>
  12. </view>
  13. </scroll-view>
  14. <!-- 右侧子导航 -->
  15. <scroll-view scroll-y="true" class="right">
  16. <view class="category" v-for="(category, index) in categoryList" :key="index" v-if="index == showCategoryIndex">
  17. <view style="text-align: left">
  18. <text style="color: #000000;margin-right: 8px;margin-left: 8px;font-weight: bold;">{{ categoryList[showCategoryIndex].name }}</text>
  19. </view>
  20. <view class="list" v-if="category.children.length > 0">
  21. <view class="box" v-for="(item, i1) in category.children" :key="i1">
  22. <image @click="toCategory(item.id,item.name)" :src="item.img" lazy-load="true" fade-show="true"></image>
  23. <view class="text">{{ item.name }}</view>
  24. </view>
  25. </view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. showCategoryIndex: 0,
  36. headerPosition: 'fixed',
  37. categoryList: []
  38. };
  39. },
  40. onPageScroll(e) {
  41. //兼容iOS端下拉时顶部漂移
  42. if (e.scrollTop >= 0) {
  43. this.headerPosition = 'fixed';
  44. } else {
  45. this.headerPosition = 'absolute';
  46. }
  47. },
  48. onLoad() {
  49. this.$queue.showLoading('加载中...');
  50. this.$Request.getT('/goodsType/list').then(res => {
  51. if (res.status === 0) {
  52. this.categoryList = [];
  53. res.data.forEach(d => {
  54. this.categoryList.push(d);
  55. });
  56. }
  57. uni.hideLoading();
  58. });
  59. },
  60. methods: {
  61. //分类切换显示
  62. showCategory(index) {
  63. this.showCategoryIndex = index;
  64. },
  65. toCategory(id, name) {
  66. uni.navigateTo({
  67. url: '/package/pages/zysc/categray/search?cid=' + id + '&name=' + name
  68. });
  69. }
  70. }
  71. };
  72. </script>
  73. <style lang="scss">
  74. .status {
  75. width: 100%;
  76. height: 0;
  77. position: fixed;
  78. z-index: 10;
  79. background-color: #fff;
  80. top: 0;
  81. /* #ifdef APP-PLUS */
  82. height: var(--status-bar-height); //覆盖样式
  83. /* #endif */
  84. }
  85. .category-list {
  86. width: 100%;
  87. margin-top: 20upx;
  88. display: flex;
  89. .left,
  90. .right {
  91. top: 88upx;
  92. bottom: 0upx;
  93. }
  94. .left {
  95. position: fixed;
  96. width: 24%;
  97. /* #ifndef H5 */
  98. top: 20upx;
  99. /* #endif */
  100. /* #ifdef H5 */
  101. top: 110upx;
  102. /* #endif */
  103. left: 0upx;
  104. background-color: #FFFFFF;
  105. .row {
  106. width: 100%;
  107. height: 90upx;
  108. display: flex;
  109. align-items: center;
  110. .text {
  111. width: 100%;
  112. position: relative;
  113. font-size: 28upx;
  114. display: flex;
  115. justify-content: center;
  116. color: #333333;
  117. text-overflow: ellipsis;
  118. overflow: hidden;
  119. white-space: nowrap;
  120. .block {
  121. position: absolute;
  122. width: 0upx;
  123. left: 0;
  124. }
  125. }
  126. &.on {
  127. height: 100upx;
  128. background-color: #F2F2F2;
  129. .text {
  130. font-size: 30upx;
  131. font-weight: 600;
  132. color: #FC2C1F;
  133. .block {
  134. width: 8upx;
  135. height: 100upx;
  136. top: -72%;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. .right {
  143. margin-left: 27%;
  144. width: 70%;
  145. left: 24%;
  146. background-color: #FFFFFF;
  147. border-radius: 30upx;
  148. .category {
  149. width: 94%;
  150. padding: 20upx 3%;
  151. .banner {
  152. width: 100%;
  153. height: 24.262vw;
  154. border-radius: 10upx;
  155. overflow: hidden;
  156. box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);
  157. image {
  158. width: 100%;
  159. height: 24.262vw;
  160. }
  161. }
  162. .list {
  163. margin-top: 40upx;
  164. width: 100%;
  165. display: flex;
  166. flex-wrap: wrap;
  167. .box {
  168. width: calc(61.44vw / 3);
  169. margin-bottom: 30upx;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. flex-wrap: wrap;
  174. image {
  175. width: 60%;
  176. height: calc(71.44vw / 3 * 0.6);
  177. }
  178. .text {
  179. margin-top: 5upx;
  180. width: 100%;
  181. text-align: center;
  182. font-size: 26upx;
  183. text-overflow: ellipsis;
  184. overflow: hidden;
  185. white-space: nowrap;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. </style>