category.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. style: 'first_one'
  82. };
  83. }
  84. }
  85. const onMenu = (val) => {
  86. state.activeMenu = val;
  87. if (state.categoryList.style === 'first_one' || state.categoryList.style === 'first_two') {
  88. state.pagination = {
  89. data: [],
  90. current_page: 1,
  91. total: 1,
  92. last_page: 1,
  93. };
  94. getGoodsList(state.categoryList.children[val].id);
  95. }
  96. // 这段代码本来是在判断里的
  97. // getGoodsList(state.categoryList.children[val].id);
  98. };
  99. async function getGoodsList(id, page = 1, list_rows = 6) {
  100. state.loadStatus = 'loading';
  101. const res = await sheep.$api.goods.list({
  102. categoryId: id,
  103. pageSize: list_rows,
  104. pageNo: page,
  105. });
  106. if (res.code === 0) {
  107. let couponList = _.concat(state.pagination.data, res.data.list);
  108. state.pagination = {
  109. ...res.data,
  110. data: couponList,
  111. };
  112. console.log(state.pagination)
  113. if (state.pagination.current_page < state.pagination.last_page) {
  114. state.loadStatus = 'more';
  115. } else {
  116. state.loadStatus = 'noMore';
  117. }
  118. }
  119. }
  120. // 加载更多
  121. function loadmore() {
  122. if (state.loadStatus !== 'noMore') {
  123. getGoodsList(
  124. state.categoryList.children[state.activeMenu].id,
  125. state.pagination.current_page + 1,
  126. );
  127. }
  128. }
  129. onLoad(async (options) => {
  130. await getList(options);
  131. if (state.categoryList.style === 'first_one' || state.categoryList.style === 'first_two') {
  132. getGoodsList(state.categoryList.children[0].id);
  133. }
  134. });
  135. onReachBottom(() => {
  136. loadmore();
  137. });
  138. </script>
  139. <style lang="scss" scoped>
  140. .s-category {
  141. :deep() {
  142. .side-menu-wrap {
  143. width: 200rpx;
  144. height: 100%;
  145. padding-left: 12rpx;
  146. background-color: #f6f6f6;
  147. .menu-item {
  148. width: 100%;
  149. height: 88rpx;
  150. position: relative;
  151. transition: all linear 0.2s;
  152. .menu-title {
  153. line-height: 32rpx;
  154. font-size: 30rpx;
  155. font-weight: 400;
  156. color: #333;
  157. margin-left: 28rpx;
  158. position: relative;
  159. z-index: 0;
  160. &::before {
  161. content: '';
  162. width: 64rpx;
  163. height: 12rpx;
  164. background: linear-gradient(90deg,
  165. var(--ui-BG-Main-gradient),
  166. var(--ui-BG-Main-light)) !important;
  167. position: absolute;
  168. left: -64rpx;
  169. bottom: 0;
  170. z-index: -1;
  171. transition: all linear 0.2s;
  172. }
  173. }
  174. &.menu-item-active {
  175. background-color: #fff;
  176. border-radius: 20rpx 0 0 20rpx;
  177. &::before {
  178. content: '';
  179. position: absolute;
  180. right: 0;
  181. bottom: -20rpx;
  182. width: 20rpx;
  183. height: 20rpx;
  184. background: radial-gradient(circle at 0 100%, transparent 20rpx, #fff 0);
  185. }
  186. &::after {
  187. content: '';
  188. position: absolute;
  189. top: -20rpx;
  190. right: 0;
  191. width: 20rpx;
  192. height: 20rpx;
  193. background: radial-gradient(circle at 0% 0%, transparent 20rpx, #fff 0);
  194. }
  195. .menu-title {
  196. font-weight: 600;
  197. &::before {
  198. left: 0;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. .goods-list-box {
  205. background-color: #fff;
  206. width: calc(100vw - 100px);
  207. padding: 10px;
  208. }
  209. .banner-img {
  210. width: calc(100vw - 130px);
  211. border-radius: 5px;
  212. margin-bottom: 20rpx;
  213. }
  214. }
  215. }
  216. </style>