category.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <s-layout title="分类" tabbar="/pages/index/category" :bgStyle="{ color: '#fff' }">
  3. <view class="s-category">
  4. <view class="three-level-wrap ss-flex ss-col-top" :style="[{ height: pageHeight + 'px' }]">
  5. <scroll-view class="side-menu-wrap" scroll-y :style="[{ height: pageHeight + 'px' }]">
  6. <view class="menu-item ss-flex" v-for="(item, index) in state.categoryList?.children" :key="item.id"
  7. :class="[{ 'menu-item-active': index == state.activeMenu }]" @tap="onMenu(index)">
  8. <view class="menu-title ss-line-1">
  9. {{ item.name }}
  10. </view>
  11. </view>
  12. </scroll-view>
  13. <scroll-view class="goods-list-box" scroll-y :style="[{ height: pageHeight + 'px' }]"
  14. v-if="state.categoryList?.children?.length">
  15. <image v-if="state.categoryList.children[state.activeMenu].image" class="banner-img"
  16. :src="sheep.$url.cdn(state.categoryList.children[state.activeMenu].image)" mode="widthFix">
  17. </image>
  18. <first-one v-if="state.categoryList.style === 'first_one'" :data="state.categoryList"
  19. :activeMenu="state.activeMenu" :pagination="state.pagination" />
  20. <first-two v-if="state.categoryList.style === 'first_two'" :data="state.categoryList"
  21. :activeMenu="state.activeMenu" :pagination="state.pagination" />
  22. <second-one v-if="state.categoryList.style === 'second_one'" :data="state.categoryList"
  23. :activeMenu="state.activeMenu" :pagination="state.pagination" />
  24. <third-one v-if="state.categoryList.style === 'third_one'" :data="state.categoryList"
  25. :activeMenu="state.activeMenu" :pagination="state.pagination" />
  26. <uni-load-more v-if="
  27. (state.categoryList.style === 'first_one' ||
  28. state.categoryList.style === 'first_two') &&
  29. state.pagination.total > 0
  30. " :status="state.loadStatus" :content-text="{
  31. contentdown: '点击查看更多',
  32. }" @tap="loadmore" />
  33. </scroll-view>
  34. </view>
  35. </view>
  36. </s-layout>
  37. </template>
  38. <script setup>
  39. import secondOne from './components/second-one.vue';
  40. import thirdOne from './components/third-one.vue';
  41. import firstOne from './components/first-one.vue';
  42. import firstTwo from './components/first-two.vue';
  43. import sheep from '@/sheep';
  44. import {
  45. onLoad,
  46. onReachBottom
  47. } from '@dcloudio/uni-app';
  48. import {
  49. computed,
  50. reactive
  51. } from 'vue';
  52. import _ from 'lodash';
  53. const state = reactive({
  54. categoryList: [],
  55. activeMenu: '0',
  56. pagination: {
  57. data: [],
  58. current_page: 1,
  59. total: 1,
  60. last_page: 1,
  61. },
  62. loadStatus: '',
  63. });
  64. const {
  65. screenHeight,
  66. safeAreaInsets,
  67. screenWidth,
  68. safeArea
  69. } = sheep.$platform.device;
  70. const pageHeight = computed(() => safeArea.height - 44 - 50);
  71. async function getList(options) {
  72. const {
  73. code,
  74. data
  75. } = await sheep.$api.category.list({
  76. id: options.id,
  77. });
  78. if (code === 0) {
  79. state.categoryList = {
  80. children: data
  81. };
  82. }
  83. }
  84. const onMenu = (val) => {
  85. state.activeMenu = val;
  86. if (state.categoryList.style === 'first_one' || state.categoryList.style === 'first_two') {
  87. state.pagination = {
  88. data: [],
  89. current_page: 1,
  90. total: 1,
  91. last_page: 1,
  92. };
  93. }
  94. // 这段代码本来是在判断里的
  95. getGoodsList(state.categoryList.children[val].id);
  96. };
  97. async function getGoodsList(id, page = 1, list_rows = 6) {
  98. state.loadStatus = 'loading';
  99. const res = await sheep.$api.goods.list({
  100. categoryId: id,
  101. pageSize:list_rows,
  102. pageNo:page,
  103. });
  104. if (res.code === 0) {
  105. let couponList = _.concat(state.pagination.data, res.data.list);
  106. state.pagination = {
  107. ...res.data,
  108. data: couponList,
  109. };
  110. console.log(state.pagination)
  111. if (state.pagination.current_page < state.pagination.last_page) {
  112. state.loadStatus = 'more';
  113. } else {
  114. state.loadStatus = 'noMore';
  115. }
  116. }
  117. }
  118. // 加载更多
  119. function loadmore() {
  120. if (state.loadStatus !== 'noMore') {
  121. getGoodsList(
  122. state.categoryList.children[state.activeMenu].id,
  123. state.pagination.current_page + 1,
  124. );
  125. }
  126. }
  127. onLoad(async (options) => {
  128. await getList(options);
  129. if (state.categoryList.style === 'first_one' || state.categoryList.style === 'first_two') {
  130. getGoodsList(state.categoryList.children[0].id);
  131. }
  132. });
  133. onReachBottom(() => {
  134. loadmore();
  135. });
  136. </script>
  137. <style lang="scss" scoped>
  138. .s-category {
  139. :deep() {
  140. .side-menu-wrap {
  141. width: 200rpx;
  142. height: 100%;
  143. padding-left: 12rpx;
  144. background-color: #f6f6f6;
  145. .menu-item {
  146. width: 100%;
  147. height: 88rpx;
  148. position: relative;
  149. transition: all linear 0.2s;
  150. .menu-title {
  151. line-height: 32rpx;
  152. font-size: 30rpx;
  153. font-weight: 400;
  154. color: #333;
  155. margin-left: 28rpx;
  156. position: relative;
  157. z-index: 0;
  158. &::before {
  159. content: '';
  160. width: 64rpx;
  161. height: 12rpx;
  162. background: linear-gradient(90deg,
  163. var(--ui-BG-Main-gradient),
  164. var(--ui-BG-Main-light)) !important;
  165. position: absolute;
  166. left: -64rpx;
  167. bottom: 0;
  168. z-index: -1;
  169. transition: all linear 0.2s;
  170. }
  171. }
  172. &.menu-item-active {
  173. background-color: #fff;
  174. border-radius: 20rpx 0 0 20rpx;
  175. &::before {
  176. content: '';
  177. position: absolute;
  178. right: 0;
  179. bottom: -20rpx;
  180. width: 20rpx;
  181. height: 20rpx;
  182. background: radial-gradient(circle at 0 100%, transparent 20rpx, #fff 0);
  183. }
  184. &::after {
  185. content: '';
  186. position: absolute;
  187. top: -20rpx;
  188. right: 0;
  189. width: 20rpx;
  190. height: 20rpx;
  191. background: radial-gradient(circle at 0% 0%, transparent 20rpx, #fff 0);
  192. }
  193. .menu-title {
  194. font-weight: 600;
  195. &::before {
  196. left: 0;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. .goods-list-box {
  203. background-color: #fff;
  204. width: calc(100vw - 100px);
  205. padding: 10px;
  206. }
  207. .banner-img {
  208. width: calc(100vw - 130px);
  209. border-radius: 5px;
  210. margin-bottom: 20rpx;
  211. }
  212. }
  213. }
  214. </style>