index.vue 9.7 KB

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