classify.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <!-- 自定义导航栏-->
  3. <view class="page" :style="{height:windowHeight}">
  4. <!-- 侧栏 -->
  5. <scroll-view class="aside" scroll-y="true">
  6. <view
  7. class="item acea-row row-center-wrapper"
  8. :class="categoryDivindex === sideIndex ? 'on' : ''"
  9. v-for="(item, categoryDivindex) in classifyList"
  10. :key="categoryDivindex"
  11. @click="changeSide(categoryDivindex)"
  12. >
  13. {{ item.name }}
  14. </view>
  15. </scroll-view>
  16. <!-- 主内容 -->
  17. <scroll-view class="conter" scroll-y="true">
  18. <view v-if="classifyList[sideIndex]">
  19. <view class="title">{{ classifyList[sideIndex].name }}</view>
  20. <view class="list">
  21. <view class="item" v-for="(child, childIndex) in classifyList[sideIndex].children" :key="childIndex" @click="goGoodsList(child)">
  22. <!-- <u-image height="120rpx" width="120rpox" mode="widthFix" :src="child.pic"></u-image> -->
  23. <view class="name">{{ child.name }}</view>
  24. </view>
  25. </view>
  26. <NoData height="50vh" v-if="classifyList[sideIndex].children.length==0"></NoData>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. const app = getApp();
  35. return {
  36. windowHeight:app.globalData.windowHeight + 'px',
  37. // 分类数据
  38. classifyList: [],
  39. // 分类索引
  40. sideIndex: 0,
  41. // 传参id
  42. queryClassifyId: ''
  43. };
  44. },
  45. onLoad(options) {
  46. if (options.id) {
  47. this.queryClassifyId = options.id;
  48. }
  49. this.getClassifyList();
  50. },
  51. methods: {
  52. // 动态切换分类
  53. changeClassifyById() {
  54. let nowClassifyIndex = 0;
  55. if (!this.queryClassifyId) return;
  56. this.classifyList.forEach((item, index) => {
  57. if (item.id === this.queryClassifyId) nowClassifyIndex = index;
  58. });
  59. if (nowClassifyIndex !== this.navActive) {
  60. this.changeSide(index);
  61. }
  62. },
  63. // 查询分类列表
  64. getClassifyList() {
  65. this.$u.api.getCateListAjax().then(({code,data})=>{
  66. if(code==1){
  67. this.classifyList = data;
  68. }
  69. }).catch();
  70. // this.changeClassifyById();
  71. },
  72. // 切换分类
  73. changeSide(index) {
  74. this.sideIndex = index;
  75. },
  76. // 跳转商品列表页
  77. goGoodsList(child) {
  78. this.$u.route('/pages/search-result', { cateInfo: encodeURIComponent(JSON.stringify(child)) });
  79. }
  80. }
  81. };
  82. </script>
  83. <style lang="scss" scoped>
  84. .page {
  85. display: flex;
  86. justify-content: space-between;
  87. align-items: flex-start;
  88. background: $app-theme-bg-color;
  89. // background-color: red;
  90. .aside {
  91. width: 270rpx;
  92. background: $app-theme-bg-gray-color;
  93. height: 100%;
  94. .item {
  95. height: 100rpx;
  96. // line-height: 100rpx;
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. text-align: center;
  101. font-size: 28rpx;
  102. font-weight: 500;
  103. color: $app-theme-text-black-color;
  104. transition: all 0.3s ease-in-out;
  105. box-sizing: border-box;
  106. padding: 0 20rpx;
  107. &.on {
  108. color: #fff;
  109. position: relative;
  110. background-color: $app-theme-color;
  111. transition: all 0.3s ease-in-out;
  112. }
  113. }
  114. }
  115. .conter {
  116. padding-left: 20rpx;
  117. box-sizing: border-box;
  118. height: 100%;
  119. .title {
  120. font-size: 36rpx;
  121. font-weight: bold;
  122. // color: $app-theme-color;
  123. padding: 30rpx 0;
  124. border-bottom: 1rpx solid $app-theme-border-color;
  125. }
  126. .list {
  127. display: flex;
  128. justify-content: flex-start;
  129. align-items: flex-start;
  130. flex-wrap: wrap;
  131. .item {
  132. // width: 120rpx;
  133. margin:20rpx 15rpx 0;
  134. // &:nth-child(3n) {
  135. // margin-right: 0;
  136. // }
  137. .picture {
  138. }
  139. .name {
  140. font-size: 32rpx;
  141. color: $app-theme-color;
  142. text-align: center;
  143. margin-top: 12rpx;
  144. padding: 10rpx 20rpx;
  145. border: 1rpx solid $app-theme-color;
  146. border-radius: 2em;
  147. }
  148. }
  149. }
  150. }
  151. }
  152. </style>