one-catgory.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 class="type-list u-ellipsis-1" :class="[{ 'list-active': listId == index }]" v-for="(item, index) in categoryData" :key="index" @tap="onType(index)">
  7. <view class="line" :class="[{ 'line-active': listId == index }]"></view>
  8. {{ item.name }}
  9. </view>
  10. <view class="hack-tabbar"></view>
  11. </scroll-view>
  12. </view>
  13. <view style="height: 100%;width: 100%;">
  14. <scroll-view @scrolltolower="loadMore" scroll-y class="scroll-box" enable-back-to-top scroll-with-animation>
  15. <view class="right" v-if="categoryData.length">
  16. <image class="type-img" v-if="categoryData[listId].image" :src="categoryData[listId].image" mode="aspectFill"></image>
  17. <view class="item-list">
  18. <view class="item-box u-flex">
  19. <view
  20. class="u-flex-col u-col-center goods-item"
  21. @tap="jump('/pages/goods/detail', { id: goods.id })"
  22. v-for="(goods, index1) in goodsList"
  23. :key="goods.id"
  24. >
  25. <image class="item-img" lazy-load :src="goods.image" mode="aspectFill"></image>
  26. <text class="item-title u-ellipsis-1 ">{{ goods.title }}</text>
  27. <view class="item-price">{{ goods.price }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 缺省页 -->
  32. <shopro-empty
  33. v-if="isEmpty"
  34. marginTop="200rpx"
  35. :image="$IMG_URL + '/imgs/empty/empty_goods.png'"
  36. tipText="暂无该商品,还有更多好货等着你噢~"
  37. ></shopro-empty>
  38. <!-- 加载更多 -->
  39. <u-loadmore v-if="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc" />
  40. <view class="hack-tabbar"></view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
  49. export default {
  50. components: {},
  51. data() {
  52. return {
  53. listId: 0,
  54. categoryData: {},
  55. categoryID: 0, //分类id
  56. isEmpty: false,
  57. currentPage: 1,
  58. lastPage: 1,
  59. loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
  60. goodsList: [] //商品数据
  61. };
  62. },
  63. props: {
  64. categoryStyleId: {
  65. //分类样式ID
  66. type: Number,
  67. default: 0
  68. }
  69. },
  70. computed: {},
  71. created() {
  72. console.log('%c当前分类:一级分类', 'color:green;background:yellow');
  73. this.getCategory();
  74. },
  75. methods: {
  76. // 获取分类
  77. getCategory() {
  78. this.$http('category.detail', {
  79. id: this.categoryStyleId
  80. }).then(res => {
  81. if (res.code === 1) {
  82. this.categoryData = res.data.children;
  83. this.categoryID = res.data.children[0].id;
  84. this.getGoodsList();
  85. }
  86. });
  87. },
  88. // 获取分类商品
  89. getGoodsList() {
  90. let that = this;
  91. that.$http('goods.lists', {
  92. category_id: that.categoryID,
  93. page: that.currentPage
  94. }, '加载中...').then(res => {
  95. if (res.code === 1) {
  96. that.goodsList = [...that.goodsList, ...res.data.data];
  97. that.isEmpty = !that.goodsList.length;
  98. that.lastPage = res.data.last_page;
  99. that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
  100. }
  101. });
  102. },
  103. // 商品底部
  104. loadMore() {
  105. if (this.currentPage < this.lastPage) {
  106. this.currentPage += 1;
  107. this.getGoodsList();
  108. }
  109. },
  110. onType(index) {
  111. this.listId = index;
  112. this.categoryID = this.categoryData[index].id;
  113. this.goodsList = [];
  114. this.currentPage = 1;
  115. this.getGoodsList();
  116. },
  117. // 路由跳转
  118. jump(path, parmas) {
  119. this.$Router.push({
  120. path: path,
  121. query: parmas
  122. });
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss">
  128. .hack-tabbar {
  129. height: calc(100rpx + env(safe-area-inset-bottom) / 2);
  130. width: 100%;
  131. }
  132. .content_box {
  133. margin-top: 1upx;
  134. display: flex;
  135. flex-direction: column;
  136. overflow: hidden;
  137. height: 100%;
  138. }
  139. .wrapper-box {
  140. flex: 1;
  141. margin-top: 1upx;
  142. height: 100%;
  143. }
  144. .scroll-box {
  145. height: 100%;
  146. flex: 1;
  147. background: #fff;
  148. }
  149. .left {
  150. width: 200upx;
  151. height: 100%;
  152. flex: 1;
  153. .list-active {
  154. background: #fff;
  155. color: #333333 !important;
  156. font-weight: bold !important;
  157. }
  158. .line-active {
  159. background: #e6b873;
  160. }
  161. .type-list {
  162. height: 84upx;
  163. position: relative;
  164. width: 200rpx;
  165. padding-left: 16rpx;
  166. line-height: 84rpx;
  167. font-size: 28upx;
  168. font-weight: 400;
  169. color: rgba(102, 102, 102, 1);
  170. .line {
  171. width: 10upx;
  172. height: 100%;
  173. position: absolute;
  174. left: 0;
  175. }
  176. }
  177. }
  178. .right {
  179. padding: 0 30upx;
  180. flex: 1;
  181. height: 100%;
  182. .type-img {
  183. width: 505rpx;
  184. height: 150rpx;
  185. background: #ccc;
  186. margin: 20rpx 0;
  187. border-radius: 10rpx;
  188. }
  189. .item-list {
  190. .type-box {
  191. height: 84rpx;
  192. .type-title {
  193. font-size: 28rpx;
  194. font-weight: bold;
  195. }
  196. .more {
  197. font-size: 26rpx;
  198. color: #999;
  199. }
  200. }
  201. .item-box {
  202. flex-wrap: wrap;
  203. width: 504rpx;
  204. .goods-item {
  205. margin-right: 12rpx;
  206. margin-bottom: 12rpx;
  207. background: #ffffff;
  208. box-shadow: 0px 0px 20rpx 4rpx rgba(199, 199, 199, 0.22);
  209. border-radius: 10rpx;
  210. &:nth-child(2n) {
  211. margin-right: 0;
  212. }
  213. .item-img {
  214. width: 245rpx;
  215. height: 246rpx;
  216. border-radius: 10rpx 10rpx 0px 0px;
  217. background: #f5f5f5;
  218. }
  219. .item-title {
  220. font-size: 24rpx;
  221. line-height: 24rpx;
  222. margin-top: 10rpx;
  223. width: 200rpx;
  224. text-align: left;
  225. margin: 20rpx;
  226. }
  227. .item-price {
  228. font-size: 28rpx;
  229. font-weight: 500;
  230. color: #ff3000;
  231. text-align: left;
  232. width: 200rpx;
  233. margin: 0 20rpx 20rpx;
  234. &::before {
  235. content: '¥';
  236. font-size: 22rpx;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. }
  243. </style>