classfiy.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <script setup lang="ts">
  2. import { StaticUrl } from '@/config'
  3. const { statusBarHeight, MenuButtonHeight } = storeToRefs(useSysStore())
  4. const classfiylist = ref([
  5. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  6. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  7. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  8. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  9. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  10. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  11. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  12. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  13. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  14. { title: '蔬菜豆品', icon: `${StaticUrl}/shu.png` },
  15. ])
  16. const topNavActive = ref(0)
  17. const sortClassBtn = ref(1)
  18. const show = ref(false)
  19. definePage({
  20. name: 'xsb-classfiy',
  21. islogin: false,
  22. style: {
  23. navigationStyle: 'custom',
  24. navigationBarTitleText: '星闪豹分类',
  25. disableScroll: true,
  26. },
  27. })
  28. const navHeight = computed(() => {
  29. return (`${Number(MenuButtonHeight.value) + Number(statusBarHeight.value)}px`)
  30. })
  31. function handleTopNavChange(idx: number) {
  32. topNavActive.value = idx
  33. }
  34. function handleOpen() {
  35. show.value = true
  36. console.log(navHeight.value, '打开')
  37. }
  38. const active = ref<number>(1)
  39. const scrollTop = ref<number>(0)
  40. const itemScrollTop = ref<number[]>([])
  41. const subCategories = Array.from({ length: 24 }).fill({ title: '标题文字', label: '这是描述这是描述' }, 0, 24)
  42. const categories = ref([
  43. {
  44. label: '分类一',
  45. title: '标题一',
  46. items: subCategories,
  47. },
  48. {
  49. label: '分类二',
  50. title: '标题二',
  51. items: subCategories,
  52. },
  53. {
  54. label: '分类三',
  55. title: '标题三',
  56. items: subCategories.slice(0, 18),
  57. },
  58. {
  59. label: '分类四',
  60. title: '标题四',
  61. items: subCategories.slice(0, 21),
  62. },
  63. {
  64. label: '分类五',
  65. title: '标题五',
  66. items: subCategories,
  67. },
  68. {
  69. label: '分类六',
  70. title: '标题六',
  71. items: subCategories.slice(0, 18),
  72. },
  73. {
  74. label: '分类七',
  75. title: '标题七',
  76. items: subCategories,
  77. },
  78. ])
  79. function handleChange({ value }) {
  80. active.value = value
  81. scrollTop.value = itemScrollTop.value[value]
  82. }
  83. function onScroll(e) {
  84. const { scrollTop } = e.detail
  85. const threshold = 50 // 下一个标题与顶部的距离
  86. if (scrollTop < threshold) {
  87. active.value = 0
  88. return
  89. }
  90. const index = itemScrollTop.value.findIndex(top => top > scrollTop && top - scrollTop <= threshold)
  91. if (index > -1) {
  92. active.value = index
  93. }
  94. }
  95. </script>
  96. <template>
  97. <view class="page-xsb">
  98. <wd-navbar
  99. title="" custom-style="background-color:#F4FFD1" :bordered="false" :z-index="99" safe-area-inset-top
  100. fixed
  101. >
  102. <template #left>
  103. <view class="flex items-center">
  104. <view class="h60rpx w-474rpx flex items-center justify-between border-2rpx border-[var(--them-color)] rounded-40rpx border-solid bg-white pr6rpx">
  105. <view class="flex items-center pb14rpx pl24rpx pt16rpx">
  106. <wd-icon name="search" size="14" color="#ccc" />
  107. <view class="search ml12rpx h-full w-full overflow-hidden">
  108. <wd-notice-bar :text="['霸王茶姬', '牛奶', '洗衣机']" custom-class="notice-bar" color="#ccc" background-color="#fff" direction="vertical" />
  109. </view>
  110. </view>
  111. <view class="flex items-center pr28rpx">
  112. <wd-divider vertical />
  113. <view class="ml6rpx text-28rpx text-[var(--them-color)] font-semibold">
  114. 搜索
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. </wd-navbar>
  121. <view
  122. class="h162rpx flex items-center justify-between bg-#F4FFD1 pl24rpx"
  123. :style="{ paddingTop: `${(Number(statusBarHeight) || 44) + MenuButtonHeight + 12}px` }"
  124. >
  125. <scroll-view scroll-x class="scrollx w-90% flex-shrink-0 whitespace-nowrap">
  126. <view class="flex items-end pb10rpx">
  127. <view v-for="item, idx in classfiylist" :key="idx" class="mr24rpx flex flex-col items-center justify-center" @click="handleTopNavChange(idx)">
  128. <image
  129. :src="item.icon"
  130. :class="[topNavActive == idx ? 'overflow-hidden border-solid border-[var(--them-color)] border-2rpx rounded-26rpx h84rpx w-84rpx' : 'h72rpx w-72rpx']"
  131. />
  132. <view class="mt16rpx text-22rpx" :class="[topNavActive == idx ? 'bg-[var(--them-color)] rounded-18rpx px-8rpx py2rpx text-white text-24rpx' : '']">
  133. {{ item.title }}
  134. </view>
  135. </view>
  136. </view>
  137. </scroll-view>
  138. <view class="right-nav box-border h144rpx w64rpx flex flex-shrink-0 flex-col items-center justify-center px20rpx text-24rpx font-semibold" @click="handleOpen">
  139. 展开
  140. <image
  141. :src="`${StaticUrl}/xia.png`"
  142. class="mt20rpx h20rpx w20rpx"
  143. />
  144. </view>
  145. <wd-popup v-model="show" position="top" custom-style="border-radius:32rpx;">
  146. <view class="box-border bg-#F4FFD1 p24rpx" :style="{ paddingTop: `${(Number(statusBarHeight) || 44) + MenuButtonHeight + 12}px` }">
  147. <view class="mb24rpx mt24rpx text-28rpx font-semibold">
  148. 全部一级分类
  149. </view>
  150. <view class="h400rpx overflow-y-scroll">
  151. <view class="grid grid-cols-5 box-border gap-x-24rpx gap-y-24rpx">
  152. <view v-for="item, idx in classfiylist" :key="idx" class="box-border h150rpx w114rpx flex flex-col items-center justify-center" @click="handleTopNavChange(idx)">
  153. <image
  154. :src="item.icon"
  155. :class="[topNavActive == idx ? 'overflow-hidden border-solid border-[var(--them-color)] border-2rpx rounded-26rpx h88rpx w-88rpx' : 'h76rpx w-76rpx']"
  156. />
  157. <view class="mt16rpx whitespace-nowrap text-nowrap text-22rpx" :class="[topNavActive == idx ? 'bg-[var(--them-color)] rounded-18rpx px-8rpx py2rpx text-white text-24rpx' : '']">
  158. {{ item.title }}
  159. </view>
  160. </view>
  161. </view>
  162. </view>
  163. <view class="mt24rpx w-full flex items-center justify-center" @click="show = false">
  164. <view class="mr8rpx text-24rpx">
  165. 点击收起
  166. </view>
  167. <wd-icon name="arrow-down" size="18px" />
  168. </view>
  169. </view>
  170. </wd-popup>
  171. </view>
  172. <view class="wraper">
  173. <wd-sidebar v-model="active" @change="handleChange">
  174. <wd-sidebar-item v-for="(item, index) in categories" :key="index" :value="index" :label="item.label" />
  175. </wd-sidebar>
  176. <view class="content">
  177. <view class="p20rpx">
  178. <image
  179. :src="`${StaticUrl}/class.png`"
  180. class="h144rpx w-full"
  181. />
  182. <view class="my20rpx flex items-center justify-end rounded-16rpx bg-#F6F6F6 px20rpx py8rpx">
  183. <view class="mr40rpx text-24rpx">
  184. 销量
  185. </view>
  186. <wd-sort-button v-model="sortClassBtn" :line="false" title="价格" />
  187. </view>
  188. </view>
  189. <scroll-view :style="{ height: `calc(100vh - ${navHeight} - 600rpx)` }" scroll-y scroll-with-animation :scroll-top="scrollTop" :throttle="false" @scroll="onScroll">
  190. <view class="p20rpx">
  191. <view v-for="item in 20" :key="item">
  192. <view class="flex">
  193. <view class="mr20rpx h172rpx w172rpx flex-shrink-0 rounded-16rpx bg-#F6F6F6" />
  194. <view>
  195. <view class="text-left text-28rpx font-semibold">
  196. <view v-for="i in 2" :key="i" class="mr5px inline-block">
  197. <wd-tag type="primary">
  198. 新品{{ i }}
  199. </wd-tag>
  200. </view>
  201. 海湾高盐特大白虾200g
  202. </view>
  203. <view class="text-22rpx text-#AAAAAA">
  204. <view class="mt10rpx flex items-center">
  205. <view>一年一季</view>
  206. <wd-divider vertical />
  207. <view>新鲜翠绿</view>
  208. </view>
  209. <view class="mt6rpx">
  210. 已售3.6万+
  211. </view>
  212. </view>
  213. <view class="flex items-center justify-between">
  214. <view class="text-#FF4D3A font-semibold">
  215. <text class="text-24rpx">
  216. </text> <text class="text-36rpx">
  217. 9.99
  218. </text>
  219. </view>
  220. <view>
  221. <image
  222. :src="`${StaticUrl}/cart-yes.png`"
  223. class="h52rpx w52rpx"
  224. />
  225. </view>
  226. </view>
  227. </view>
  228. </view>
  229. <view class="line">
  230. <wd-divider color="#F0F0F0" />
  231. </view>
  232. </view>
  233. <view class="h60rpx" />
  234. </view>
  235. </scroll-view>
  236. </view>
  237. </view>
  238. </view>
  239. </template>
  240. <style scoped lang="scss">
  241. .right-nav{
  242. background: linear-gradient( 180deg, #FAFFEC 0%, #F6FFDE 11%, #E7FFA5 100%);
  243. box-shadow: -10rpx 0rpx 12rpx 2rpx rgba(0,0,0,0.07);
  244. }
  245. .wraper {
  246. display: flex;
  247. height: calc(100vh - var(--window-top) - v-bind(navHeight) - 290rpx);
  248. height: calc(100vh - var(--window-top) - constant(safe-area-inset-bottom) - v-bind(navHeight) - 290rpx);
  249. height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom) - v-bind(navHeight) - 290rpx);
  250. }
  251. .content {
  252. flex: 1;
  253. background: #fff;
  254. }
  255. </style>