category.vue 6.9 KB

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