You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.0 KiB

4 years ago
  1. <template>
  2. <view class="app column">
  3. <!-- 顶部栏 -->
  4. <page-header></page-header>
  5. <view class="content row">
  6. <scroll-view class="left-side" scroll-y>
  7. <view class="item center" :class="{active: item._id === current._id}" v-for="item in list" :key="item._id" @click="changeCate(item)">
  8. <text>{{ item.name }}</text>
  9. </view>
  10. </scroll-view>
  11. <scroll-view class="right-side" scroll-y>
  12. <image class="cate-image" :src="current.image" mode="aspectFill"></image>
  13. <view class="wrap">
  14. <view class="item column" v-for="item in current.child" :key="item._id" @click="navToList(item)">
  15. <image class="icon" :src="item.image" mode="aspectFill"></image>
  16. <text class="tit">{{ item.name }}</text>
  17. </view>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import tabbarMixin from './mixin/tabbar'
  25. import pageHeader from './components/page-header.vue'
  26. export default {
  27. components: {
  28. pageHeader
  29. },
  30. mixins: [tabbarMixin],
  31. data() {
  32. return {
  33. list: [],
  34. current: {}
  35. }
  36. },
  37. onLoad() {
  38. this.loadData();
  39. },
  40. methods: {
  41. async loadData(){
  42. //获取分类 缓存1小时
  43. const res = await this.$request('product', 'getCategory', {}, {
  44. cache: 60*60*0,
  45. });
  46. this.current = res[0];
  47. this.list = res;
  48. },
  49. changeCate(item){
  50. this.current = item;
  51. },
  52. navToList(item){
  53. const arr = [];
  54. this.current.child.forEach(cate=>{
  55. arr.push({
  56. _id: cate._id,
  57. name: cate.name
  58. })
  59. })
  60. this.navTo(`/pages/product/list?cateId=${item._id}&firstCateId=${item.parent_id}`)
  61. }
  62. }
  63. }
  64. </script>
  65. <style>
  66. page{
  67. height: 100%;
  68. }
  69. </style>
  70. <style scoped lang="scss">
  71. .app{
  72. height: 100%;
  73. }
  74. .content{
  75. flex: 1;
  76. padding-top: 12rpx;
  77. overflow: hidden;
  78. }
  79. .left-side{
  80. flex-shrink: 0;
  81. width: 180rpx;
  82. height: 100%;
  83. overflow-y: hidden;
  84. background-color: #f2f2f2;
  85. .item{
  86. height: 90rpx;
  87. font-size: 26rpx;
  88. color: #555;
  89. }
  90. .active{
  91. font-size: 28rpx;
  92. color: $base-color;
  93. font-weight: 700;
  94. background-color: #fff;
  95. position: relative;
  96. &::before{
  97. content: '';
  98. position: absolute;
  99. left: 0;
  100. top: 30rpx;
  101. width: 6rpx;
  102. height: 30rpx;
  103. background-color: $base-color;
  104. border-radius: 0 4rpx 4rpx 0;
  105. }
  106. }
  107. }
  108. .right-side{
  109. flex: 1;
  110. height: 100%;
  111. .cate-image{
  112. width: calc(100% - 40rpx);
  113. height: 200rpx;
  114. margin: 0 20rpx;
  115. border-radius: 8rpx;
  116. }
  117. .wrap{
  118. display: flex;
  119. flex-wrap: wrap;
  120. padding: 0 20rpx 20rpx;
  121. }
  122. .item{
  123. flex-shrink: 0;
  124. justify-content: flex-start;
  125. align-items: center;
  126. width: 30%;
  127. padding: 30rpx 0 0;
  128. &:nth-child(3n-1){
  129. width: 40%;
  130. }
  131. }
  132. .icon{
  133. width: 108rpx;
  134. height: 108rpx;
  135. margin-bottom: 16rpx;
  136. }
  137. .tit{
  138. width: 140rpx;
  139. font-size: 24rpx;
  140. color: #333;
  141. text-align: center;
  142. line-height: 1.4;
  143. }
  144. }
  145. </style>