two-catgory.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="content_box">
  3. <view class="u-flex u-col-center wrapper-box">
  4. <view class="scroll-box" style="background-color: #F6F6F6;">
  5. <scroll-view class="left u-flex-col u-col-center" enable-flex enable-back-to-top scroll-y>
  6. <view
  7. class="type-list u-flex u-col-center"
  8. :class="[{ 'list-active': listId == index }]"
  9. v-for="(item, index) in categoryData"
  10. :key="index"
  11. @tap="onType(index)"
  12. >
  13. <view class="u-ellipsis-1 list-item" :class="[{ 'line-active': listId == index }]">{{ item.name }}</view>
  14. </view>
  15. <view class="hack-tabbar"></view>
  16. </scroll-view>
  17. </view>
  18. <view style="height: 100%;width: 100%;">
  19. <scroll-view scroll-y class="scroll-box" enable-back-to-top scroll-with-animation>
  20. <view class="right" v-if="categoryData.length">
  21. <image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image" lazy-load mode="aspectFill"></image>
  22. <view class="type-box u-flex u-col-center u-row-center">
  23. <view class="u-iconfont uicon-minus" style="color: #d3d3d3;font-size: 28rpx;"></view>
  24. <text class="type-title">{{ categoryData[listId].name }}</text>
  25. <view class="u-iconfont uicon-minus" style="color: #d3d3d3;font-size: 28rpx;"></view>
  26. </view>
  27. <view class="item-list">
  28. <view class="item-box u-flex">
  29. <view
  30. class="u-flex-col u-col-center goods-item"
  31. @tap="jump('/pages/goods/list', { id: list.id })"
  32. v-for="(list, index1) in categoryData[listId].children"
  33. :key="index1"
  34. >
  35. <image class="item-img" lazy-load :src="list.image" mode="aspectFill"></image>
  36. <view class="item-title u-ellipsis-1 ">{{ list.name }}</view>
  37. </view>
  38. </view>
  39. <!-- 缺省页 -->
  40. <shopro-empty
  41. v-show="!categoryData[listId].children.length"
  42. :image="$IMG_URL + '/imgs/empty/empty_goods.png'"
  43. marginTop="200rpx"
  44. tipText="暂无该商品,还有更多好货等着你噢~"
  45. ></shopro-empty>
  46. <view class="hack-tabbar"></view>
  47. </view>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
  56. export default {
  57. components: {},
  58. data() {
  59. return {
  60. listId: 0,
  61. categoryData: {}
  62. };
  63. },
  64. computed: {},
  65. props: {
  66. categoryStyleId: {
  67. type: Number,
  68. default: 0
  69. }
  70. },
  71. created() {
  72. console.log('%c当前分类:二级分类', 'color:green;background:yellow');
  73. this.getCategory();
  74. },
  75. methods: {
  76. getCategory() {
  77. this.$http('category.detail', {
  78. id: this.categoryStyleId
  79. }).then(res => {
  80. if (res.code === 1) {
  81. this.categoryData = res.data.children;
  82. }
  83. });
  84. },
  85. onType(id) {
  86. this.listId = id;
  87. },
  88. // 路由跳转
  89. jump(path, parmas) {
  90. this.$Router.push({
  91. path: path,
  92. query: parmas
  93. });
  94. }
  95. }
  96. };
  97. </script>
  98. <style lang="scss">
  99. .hack-tabbar {
  100. height: calc(100rpx + env(safe-area-inset-bottom) / 2);
  101. width: 100%;
  102. }
  103. .content_box {
  104. display: flex;
  105. flex-direction: column;
  106. overflow: hidden;
  107. height: 100%;
  108. }
  109. .wrapper-box {
  110. flex: 1;
  111. margin-top: 1upx;
  112. height: 100%;
  113. }
  114. .scroll-box {
  115. height: 100%;
  116. flex: 1;
  117. background: #fff;
  118. }
  119. .left {
  120. width: 200upx;
  121. height: 100%;
  122. flex: 1;
  123. .list-active {
  124. background: #fff;
  125. color: #ffff !important;
  126. }
  127. .list-item {
  128. width: 180rpx;
  129. height: 64rpx;
  130. line-height: 64rpx;
  131. padding-left: 14rpx;
  132. }
  133. .line-active {
  134. width: 180rpx;
  135. height: 64rpx;
  136. background: #e6b873;
  137. border-radius: 0rpx 32rpx 32rpx 0rpx;
  138. color: #fff;
  139. }
  140. .type-list {
  141. height: 100rpx;
  142. position: relative;
  143. width: 200rpx;
  144. font-size: 28upx;
  145. font-weight: 400;
  146. color: rgba(102, 102, 102, 1);
  147. }
  148. }
  149. .right {
  150. padding: 0 30upx;
  151. flex: 1;
  152. height: 100%;
  153. .type-img {
  154. width: 505rpx;
  155. height: 150rpx;
  156. background: #ccc;
  157. margin-top: 30rpx;
  158. border-radius: 10rpx;
  159. }
  160. .type-box {
  161. height: 84rpx;
  162. .type-title {
  163. font-size: 28rpx;
  164. font-weight: bold;
  165. padding: 0 16rpx;
  166. }
  167. .more {
  168. font-size: 26rpx;
  169. color: #999;
  170. }
  171. }
  172. .item-list {
  173. .item-box {
  174. flex-wrap: wrap;
  175. .goods-item {
  176. margin-right: 20rpx;
  177. margin-bottom: 20rpx;
  178. &:nth-child(3n) {
  179. margin-right: 0;
  180. }
  181. .item-img {
  182. width: 150rpx;
  183. height: 150rpx;
  184. border-radius: 6rpx;
  185. background: #f5f5f5;
  186. }
  187. .item-title {
  188. font-size: 24rpx;
  189. margin-top: 10rpx;
  190. width: 150rpx;
  191. text-align: center;
  192. }
  193. }
  194. }
  195. }
  196. }
  197. </style>