home.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. <template>
  2. <!-- 购物车条勿放在 inquiry-page 内:父级 overflow:hidden 会裁切角标;且 bottom 须与 tabBar 对齐 -->
  3. <view class="home-root client-theme">
  4. <view class="inquiry-page">
  5. <view v-if="isLoading" class="state">
  6. <ClientSkeleton variant="hero-list" :rows="3" />
  7. </view>
  8. <view v-else class="content-wrap">
  9. <!-- 顶栏:仅渐变背景 + 配送行 + 搜索条(与 sanqiang-client-ui-demo.html .top 一致) -->
  10. <view class="filter-top-wrap sq-hero-header sq-hero-header--client">
  11. <view class="hero-top-main">
  12. <view class="hero-top-text">
  13. <view class="hero-brand-row">
  14. <image class="hero-brand-logo" :src="IMG_LOGO_WATERMARK" mode="aspectFit" />
  15. <text class="hero-brand">陇耘鲜达</text>
  16. </view>
  17. <text class="hero-region-line">{{ deliveryLineLeft }}</text>
  18. </view>
  19. <ClientImageLoader
  20. class="hero-top-logo"
  21. :src="IMG_LOGO_WATERMARK"
  22. mode="aspectFit"
  23. />
  24. </view>
  25. <view class="search-bar">
  26. <input
  27. v-model="keyword"
  28. class="search-input"
  29. type="text"
  30. placeholder="请输入商品名称搜索"
  31. placeholder-class="search-placeholder"
  32. confirm-type="search"
  33. @confirm="onSearchClick"
  34. />
  35. <text class="search-action" @click="onSearchClick">搜索</text>
  36. </view>
  37. </view>
  38. <!-- 一级分类 + 侧栏/商品区:整体纵向滚动,触底加载商品分页(及侧栏分页) -->
  39. <scroll-view
  40. scroll-y
  41. class="home-bottom-scroll"
  42. :show-scrollbar="true"
  43. :enable-flex="true"
  44. :lower-threshold="80"
  45. @scrolltolower="onHomeBottomScrollToLower"
  46. >
  47. <view class="home-bottom-scroll-inner">
  48. <!-- 与顶栏一致:scroll-view 抵消 content-wrap 左右 32rpx;分类区单独缩进保持原视觉 -->
  49. <view class="home-bottom-category-pad">
  50. <!-- 一级分类及以下在灰底区域,独立白卡片(与 demo .section + .first-level 一致) -->
  51. <view class="category-section">
  52. <view class="section-head">
  53. <text class="section-title">商品分类</text>
  54. </view>
  55. <view class="first-category-wrap">
  56. <swiper
  57. class="first-category-swiper"
  58. :current="firstCategorySwiperIndex"
  59. :circular="false"
  60. :indicator-dots="false"
  61. @change="onFirstCategorySwiperChange"
  62. >
  63. <swiper-item v-for="(page, pageIdx) in firstCategoryPages" :key="`category-page-${pageIdx}`">
  64. <view class="first-category-grid">
  65. <view
  66. v-for="cat in page"
  67. :key="cat.id"
  68. class="first-category-card"
  69. :class="{ active: selectedFirstCategoryId === cat.id }"
  70. hover-class="first-category-card--hover"
  71. :hover-stay-time="120"
  72. @click="handleFirstCategoryClick(cat.id)"
  73. >
  74. <ClientImageLoader
  75. class="first-category-image"
  76. :src="cat.imageUrl || DEFAULT_PLACEHOLDER_IMAGE_URL"
  77. mode="aspectFill"
  78. radius="24rpx"
  79. />
  80. <text class="first-category-name">{{ cat.name }}</text>
  81. </view>
  82. </view>
  83. </swiper-item>
  84. </swiper>
  85. </view>
  86. <view v-if="firstCategoryPages.length > 0" class="first-level-indicator">
  87. <view
  88. v-for="(_, idx) in firstCategoryPages"
  89. :key="`dot-${idx}`"
  90. class="indicator-dot"
  91. :class="{ active: firstCategorySwiperIndex === idx }"
  92. @click="goFirstCategorySwiperPage(idx)"
  93. />
  94. </view>
  95. </view>
  96. </view>
  97. <view class="product-layout">
  98. <view class="product-body">
  99. <view class="category-pane">
  100. <view class="category-scroll-inner">
  101. <view
  102. v-for="cat in displaySidebarRows"
  103. :key="cat.id"
  104. class="category-item"
  105. :class="{ active: selectedSecondCategoryId === cat.id }"
  106. hover-class="category-item--hover"
  107. :hover-stay-time="120"
  108. @click="selectedSecondCategoryId = cat.id"
  109. >
  110. {{ cat.name }}
  111. </view>
  112. <view v-if="sidebarLoading && sidebarRows.length === 0" class="pane-footer-tip">加载中...</view>
  113. </view>
  114. </view>
  115. <view class="goods-pane">
  116. <view class="goods-scroll">
  117. <view class="goods-scroll-inner">
  118. <view
  119. v-for="product in products"
  120. :key="product.id"
  121. class="goods-card"
  122. hover-class="goods-card--pressed"
  123. :hover-stay-time="120"
  124. @click="goProductView(product.id)"
  125. >
  126. <ClientImageLoader
  127. class="goods-image"
  128. :src="product.imageUrl || IMG_DEFAULT_PRODUCT"
  129. mode="aspectFill"
  130. radius="16rpx"
  131. />
  132. <view class="goods-main">
  133. <text class="goods-name">{{ product.name || '-' }}</text>
  134. <text class="goods-spec">{{ formatMeasureText(product.measureValue, product.unitName) }}</text>
  135. <view class="bottom-row">
  136. <text class="goods-price">¥{{ formatPrice(product.price || 0) }}</text>
  137. <view class="bottom-row-actions">
  138. <view v-if="getCartQuantity(product.id) === 0" class="add-btn" @click.stop="addToCart(product)">
  139. <text class="add-btn-plus">+</text>
  140. </view>
  141. <view v-else class="quantity-control" @click.stop>
  142. <view class="qty-btn" @click.stop="updateQuantity(product.id, -1)">
  143. <text>-</text>
  144. </view>
  145. <text class="qty-num">{{ getCartQuantity(product.id) }}</text>
  146. <view class="qty-btn" @click.stop="updateQuantity(product.id, 1)">
  147. <text>+</text>
  148. </view>
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. </view>
  154. <view v-if="products.length === 0 && !productsLoadingMore" class="empty-list-tip">暂无匹配商品</view>
  155. <view v-if="productsLoadingMore" class="pane-footer-tip">加载中...</view>
  156. <view
  157. v-else-if="products.length > 0 && !productHasMore"
  158. class="pane-footer-tip pane-footer-tip--nomore"
  159. >
  160. 没有更多了
  161. </view>
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. </view>
  167. </view>
  168. </scroll-view>
  169. </view>
  170. </view>
  171. <view class="cart-bar" @click="goToCart">
  172. <view class="cart-inner">
  173. <view class="cart-left">
  174. <view class="cart-count">
  175. <text>{{ cartStore.totalCount > 99 ? '99+' : cartStore.totalCount }}</text>
  176. </view>
  177. <view class="cart-text-col">
  178. <text class="cart-items-label">已选商品</text>
  179. <text class="cart-total-money">¥{{ formatPrice(cartStore.totalAmount) }}</text>
  180. </view>
  181. </view>
  182. <view class="cart-settle">
  183. <text>去结算</text>
  184. </view>
  185. </view>
  186. </view>
  187. <ProductDetailOverlay
  188. :show="showProductOverlay"
  189. :product-id="overlayProductId"
  190. @close="closeProductOverlay"
  191. />
  192. <!-- #ifdef H5 -->
  193. <ClientTabBar active="home" />
  194. <!-- #endif -->
  195. </view>
  196. </template>
  197. <script setup>
  198. import { ref, computed, onMounted, watch } from 'vue'
  199. import { onShow } from '@dcloudio/uni-app'
  200. import { useUserStore } from '@/stores/user'
  201. import { useCartStore } from '@/stores/cart'
  202. import { TOKEN_KEY } from '@/config/api'
  203. import { request, parseResponseJson } from '@/utils/request'
  204. import { formatYuan } from '@/utils/format'
  205. import ProductDetailOverlay from '@/components/client/product-detail-overlay.vue'
  206. import ClientTabBar from '@/components/client/client-tab-bar.vue'
  207. import ClientSkeleton from '@/components/client/client-skeleton.vue'
  208. import ClientImageLoader from '@/components/client/client-image-loader.vue'
  209. import { DEFAULT_PLACEHOLDER_IMAGE_URL, IMG_DEFAULT_PRODUCT, IMG_LOGO_WATERMARK } from '@/utils/staticAsset'
  210. // Store
  211. const userStore = useUserStore()
  212. const cartStore = useCartStore()
  213. const SIDEBAR_PAGE_SIZE = 30
  214. const ROOT_CATEGORY_PAGE_SIZE = 20
  215. const PRODUCT_PAGE_SIZE = 20
  216. // 状态(一级分类由接口分页拉全;左侧栏 sidebar 按页循环拉全;顶为「全部」时为全部+一级,顶为某一级时为全部+二级,首行展示名由前端替换为一级名称)
  217. const rootCategoryList = ref([])
  218. const sidebarRows = ref([])
  219. const sidebarLoading = ref(false)
  220. const products = ref([])
  221. const selectedFirstCategoryId = ref('all')
  222. const selectedSecondCategoryId = ref('all')
  223. const keyword = ref('')
  224. // 初始为 true:避免先渲染 scroll-view 再被请求置为 loading 时卸载/重挂,
  225. // H5 上会触发 uni scroll-view 内部 _scrollTopChanged 对 null 设 scrollTop 的报错。
  226. const isLoading = ref(true)
  227. const productsLoadingMore = ref(false)
  228. const nextProductPage = ref(1)
  229. const productHasMore = ref(true)
  230. const initialized = ref(false)
  231. // 商品详情覆盖弹窗
  232. const showProductOverlay = ref(false)
  233. const overlayProductId = ref('')
  234. const firstCategoryCards = computed(() => {
  235. const mapped = rootCategoryList.value.map((c) => ({
  236. id: c.id,
  237. name: c.name,
  238. imageUrl: c.imageUrl || DEFAULT_PLACEHOLDER_IMAGE_URL
  239. }))
  240. return [{ id: 'all', name: '全部', imageUrl: DEFAULT_PLACEHOLDER_IMAGE_URL }, ...mapped]
  241. })
  242. /** 与 mobile-ui demo 一致:每页 5 列 × 2 行 = 10 个 */
  243. const FIRST_CATEGORY_PAGE_SIZE = 10
  244. const firstCategoryPages = computed(() => {
  245. const pages = []
  246. for (let i = 0; i < firstCategoryCards.value.length; i += FIRST_CATEGORY_PAGE_SIZE) {
  247. pages.push(firstCategoryCards.value.slice(i, i + FIRST_CATEGORY_PAGE_SIZE))
  248. }
  249. return pages
  250. })
  251. const firstCategorySwiperIndex = ref(0)
  252. const deliveryLineLeft = computed(() => {
  253. const name = userStore.userInfo?.regionName?.trim()
  254. return name ? `配送区域:${name}` : '配送区域:请选择区域'
  255. })
  256. function onFirstCategorySwiperChange(e) {
  257. const cur = e?.detail?.current
  258. if (typeof cur === 'number') firstCategorySwiperIndex.value = cur
  259. }
  260. function goFirstCategorySwiperPage(index) {
  261. firstCategorySwiperIndex.value = index
  262. }
  263. /** 左侧栏展示:顶为「全部」时为接口数据(全部+一级);顶为某一级时首行显示该一级名称,不显示「全部」文案(筛选用 id 仍为 all) */
  264. const displaySidebarRows = computed(() => {
  265. const rows = sidebarRows.value
  266. if (!rows.length) return rows
  267. if (selectedFirstCategoryId.value === 'all') return rows
  268. const firstMeta = firstCategoryCards.value.find((c) => c.id === selectedFirstCategoryId.value)
  269. const firstName = firstMeta?.name || '未分类'
  270. const head = rows[0]
  271. if (head && head.id === 'all') {
  272. return [{ id: 'all', name: firstName }, ...rows.slice(1)]
  273. }
  274. return rows
  275. })
  276. /** 与后端 list_products 的 categoryId / rootCategoryId 约定一致 */
  277. function buildProductRequestData(page) {
  278. const f = selectedFirstCategoryId.value
  279. const s = selectedSecondCategoryId.value
  280. const data = {
  281. page,
  282. pageSize: PRODUCT_PAGE_SIZE
  283. }
  284. const kw = keyword.value.trim()
  285. if (kw) {
  286. data.keyword = kw
  287. }
  288. if (f === 'all') {
  289. if (s !== 'all') {
  290. data.rootCategoryId = s
  291. }
  292. } else if (s === 'all') {
  293. data.rootCategoryId = f
  294. } else {
  295. data.categoryId = s
  296. }
  297. return data
  298. }
  299. async function fetchProductPage(page) {
  300. const res = await request({
  301. url: '/mini/client/products',
  302. method: 'GET',
  303. data: buildProductRequestData(page)
  304. })
  305. const body = parseResponseJson(res)
  306. if (body.code !== 200) {
  307. return { list: [], totalPages: 0 }
  308. }
  309. const payload = body.data || {}
  310. const list = payload.list || []
  311. const totalPages = Number(payload.totalPages) || 0
  312. return { list, totalPages }
  313. }
  314. async function reloadProducts() {
  315. const token = uni.getStorageSync(TOKEN_KEY)
  316. if (!token) {
  317. products.value = []
  318. productHasMore.value = false
  319. return
  320. }
  321. productsLoadingMore.value = true
  322. nextProductPage.value = 1
  323. productHasMore.value = true
  324. products.value = []
  325. try {
  326. const { list, totalPages } = await fetchProductPage(1)
  327. products.value = list
  328. productHasMore.value = totalPages > 1
  329. nextProductPage.value = 2
  330. } catch (error) {
  331. console.error('获取商品失败:', error)
  332. productHasMore.value = false
  333. } finally {
  334. productsLoadingMore.value = false
  335. }
  336. }
  337. async function loadMoreProducts() {
  338. const token = uni.getStorageSync(TOKEN_KEY)
  339. if (!token || productsLoadingMore.value || !productHasMore.value) return
  340. productsLoadingMore.value = true
  341. const page = nextProductPage.value
  342. try {
  343. const { list, totalPages } = await fetchProductPage(page)
  344. if (list.length) {
  345. products.value = [...products.value, ...list]
  346. }
  347. productHasMore.value = page < totalPages
  348. if (productHasMore.value) {
  349. nextProductPage.value = page + 1
  350. }
  351. } catch (error) {
  352. console.error('加载更多商品失败:', error)
  353. } finally {
  354. productsLoadingMore.value = false
  355. }
  356. }
  357. /** 下部分整体滚动触底:仅商品分页(侧栏二级分类在 reloadSidebar 时已一次性拉全) */
  358. function onHomeBottomScrollToLower() {
  359. void loadMoreProducts()
  360. }
  361. async function loadAllRootCategories() {
  362. rootCategoryList.value = []
  363. const token = uni.getStorageSync(TOKEN_KEY)
  364. if (!token) return
  365. let page = 1
  366. try {
  367. while (true) {
  368. const res = await request({
  369. url: '/mini/client/product-categories/first-level',
  370. method: 'GET',
  371. data: { page, pageSize: ROOT_CATEGORY_PAGE_SIZE }
  372. })
  373. const body = parseResponseJson(res)
  374. if (body.code !== 200) break
  375. const d = body.data || {}
  376. const list = d.list || []
  377. for (const c of list) {
  378. rootCategoryList.value.push({
  379. id: c.id,
  380. name: c.name,
  381. imageUrl: c.imageUrl || ''
  382. })
  383. }
  384. const totalPages = Number(d.totalPages) || 0
  385. if (page >= totalPages) break
  386. page += 1
  387. }
  388. } catch (error) {
  389. console.error('加载一级分类失败:', error)
  390. }
  391. }
  392. /** 侧栏(二级/筛选项)按接口分页循环拉全,与一级分类 loadAllRootCategories 策略一致 */
  393. async function reloadSidebar() {
  394. const token = uni.getStorageSync(TOKEN_KEY)
  395. if (!token) {
  396. sidebarRows.value = []
  397. return
  398. }
  399. if (sidebarLoading.value) return
  400. sidebarRows.value = []
  401. sidebarLoading.value = true
  402. try {
  403. let page = 1
  404. while (true) {
  405. const res = await request({
  406. url: '/mini/client/product-categories/sidebar',
  407. method: 'GET',
  408. data: {
  409. firstCategoryId: selectedFirstCategoryId.value,
  410. page,
  411. pageSize: SIDEBAR_PAGE_SIZE
  412. }
  413. })
  414. const body = parseResponseJson(res)
  415. if (body.code !== 200) break
  416. const d = body.data || {}
  417. const list = d.list || []
  418. for (const row of list) {
  419. sidebarRows.value.push(row)
  420. }
  421. const totalPages = Number(d.totalPages) || 0
  422. if (page >= totalPages || list.length === 0) break
  423. page += 1
  424. }
  425. } catch (error) {
  426. console.error('加载侧栏分类失败:', error)
  427. } finally {
  428. sidebarLoading.value = false
  429. }
  430. }
  431. let keywordDebounce = null
  432. watch(keyword, () => {
  433. if (keywordDebounce) clearTimeout(keywordDebounce)
  434. keywordDebounce = setTimeout(() => {
  435. void reloadProducts()
  436. }, 350)
  437. })
  438. watch([selectedFirstCategoryId, selectedSecondCategoryId], () => {
  439. void reloadProducts()
  440. })
  441. watch(selectedFirstCategoryId, () => {
  442. void reloadSidebar()
  443. })
  444. watch(
  445. () => firstCategoryPages.value.length,
  446. () => {
  447. firstCategorySwiperIndex.value = 0
  448. }
  449. )
  450. function handleFirstCategoryClick(categoryId) {
  451. selectedFirstCategoryId.value = categoryId
  452. selectedSecondCategoryId.value = 'all'
  453. }
  454. // 添加到购物车
  455. async function addToCart(product) {
  456. await cartStore.addToCart(product, 1)
  457. }
  458. // 商品数量变化
  459. async function updateQuantity(productId, delta) {
  460. const cartItem = cartStore.items.find(item => item.productId === productId)
  461. if (cartItem) {
  462. const newQuantity = cartItem.quantity + delta
  463. if (newQuantity <= 0) {
  464. await cartStore.removeItem(cartItem.id)
  465. } else {
  466. await cartStore.updateQuantity(cartItem.id, newQuantity)
  467. }
  468. } else {
  469. const product = products.value.find(p => p.id === productId)
  470. if (product && delta > 0) {
  471. await cartStore.addToCart(product, delta)
  472. }
  473. }
  474. }
  475. // 获取购物车商品数量
  476. function getCartQuantity(productId) {
  477. const item = cartStore.items.find(i => i.productId === productId)
  478. return item?.quantity || 0
  479. }
  480. // 跳转到购物车(tabBar 页须用 switchTab,不能用 navigateTo)
  481. function goToCart() {
  482. uni.switchTab({ url: '/pages/client/cart/cart' })
  483. }
  484. // 跳转到个人中心(Tab 页需 switchTab)
  485. function goToProfile() {
  486. uni.switchTab({ url: '/pages/client/profile/profile' })
  487. }
  488. function onSearchClick() {
  489. uni.hideKeyboard && uni.hideKeyboard()
  490. void reloadProducts()
  491. }
  492. function formatPrice(price) {
  493. return formatYuan(price)
  494. }
  495. function formatMeasureText(measureValue, unitName) {
  496. const unitText = (unitName || '').trim()
  497. if (measureValue == null || measureValue === '') {
  498. return unitText ? `- ${unitText}` : '-'
  499. }
  500. const num = Number(measureValue)
  501. if (!Number.isNaN(num)) {
  502. const measureText = String(num).replace(/\.?0+$/, '')
  503. return unitText ? `${measureText} ${unitText}` : measureText
  504. }
  505. const measureText = String(measureValue).trim()
  506. return unitText ? `${measureText} ${unitText}` : measureText || '-'
  507. }
  508. function goProductView(productId) {
  509. if (!productId) return
  510. overlayProductId.value = productId
  511. showProductOverlay.value = true
  512. }
  513. function closeProductOverlay() {
  514. showProductOverlay.value = false
  515. }
  516. // 初始化
  517. onMounted(async () => {
  518. userStore.checkLoginStatus()
  519. if (!userStore.isLoggedIn) {
  520. isLoading.value = false
  521. uni.reLaunch({ url: '/pages/login/login' })
  522. return
  523. }
  524. if (!userStore.isClient) {
  525. isLoading.value = false
  526. uni.showToast({ title: '请使用客户账号登录', icon: 'none' })
  527. setTimeout(() => userStore.navigateToHome(), 1500)
  528. return
  529. }
  530. isLoading.value = true
  531. try {
  532. await Promise.all([loadAllRootCategories(), cartStore.fetchCart(), reloadSidebar()])
  533. await reloadProducts()
  534. initialized.value = true
  535. } finally {
  536. isLoading.value = false
  537. }
  538. })
  539. onShow(() => {
  540. if (!initialized.value) return
  541. if (!userStore.isLoggedIn || !userStore.isClient) return
  542. void cartStore.fetchCart()
  543. void reloadProducts()
  544. })
  545. </script>
  546. <style lang="scss">
  547. /* 仅影响当前页:高度随 tab 内容区,禁止页面级纵向滚动(不写全局 body overflow,避免污染其它路由) */
  548. page {
  549. height: 100%;
  550. overflow: hidden;
  551. background-color: #f5f8f7;
  552. }
  553. /* input placeholder-class 在部分端需非 scoped 才能命中 */
  554. .search-placeholder {
  555. color: #8aa39a;
  556. }
  557. </style>
  558. <style lang="scss" scoped>
  559. .home-root {
  560. position: relative;
  561. width: 100%;
  562. min-height: 100%;
  563. /* 底部占位:略大于结算条+tab 占用高度即可;再大只会拉长「没有更多了」与结算条之间的灰区 */
  564. --home-goods-scroll-pad: calc(96rpx + constant(safe-area-inset-bottom));
  565. --home-goods-scroll-pad: calc(96rpx + env(safe-area-inset-bottom, 0px));
  566. }
  567. /* #ifdef H5 */
  568. .home-root {
  569. --home-goods-scroll-pad: calc(132rpx + constant(safe-area-inset-bottom));
  570. --home-goods-scroll-pad: calc(132rpx + env(safe-area-inset-bottom, 0px));
  571. }
  572. /* #endif */
  573. /* #ifdef H5 */
  574. /* 与 cart 等 tab 页一致:底部用 --window-bottom,避免手写 50px 与 tabBar 实际高度不一致产生缝 */
  575. .inquiry-page {
  576. position: fixed;
  577. left: 0;
  578. right: 0;
  579. top: 0;
  580. bottom: var(--window-bottom, calc(50px + env(safe-area-inset-bottom, 0px)));
  581. width: 100%;
  582. z-index: 1;
  583. min-height: 0;
  584. background: var(--c-bg);
  585. overflow: hidden;
  586. display: flex;
  587. flex-direction: column;
  588. box-sizing: border-box;
  589. }
  590. /* #endif */
  591. /* #ifndef H5 */
  592. .inquiry-page {
  593. height: 100%;
  594. max-height: 100%;
  595. min-height: 0;
  596. background: var(--c-bg);
  597. overflow: hidden;
  598. display: flex;
  599. flex-direction: column;
  600. box-sizing: border-box;
  601. }
  602. /* #endif */
  603. .state {
  604. text-align: center;
  605. color: var(--c-muted);
  606. padding: 40rpx;
  607. }
  608. .content-wrap {
  609. flex: 1;
  610. min-height: 0;
  611. /* demo .section 水平 16px → 32rpx */
  612. padding: 0 32rpx;
  613. display: flex;
  614. flex-direction: column;
  615. box-sizing: border-box;
  616. }
  617. /* 头部以下整块纵向滚动(需占满剩余高度 scroll-view 才能滚动) */
  618. /* 与 .filter-top-wrap 同理:先拉满 inquiry 内容宽,避免子级负 margin 在 scroll-view 内被裁切导致商品区变窄 */
  619. .home-bottom-scroll {
  620. flex: 1;
  621. min-height: 0;
  622. margin: 0 -32rpx;
  623. width: calc(100% + 64rpx);
  624. max-width: calc(100% + 64rpx);
  625. box-sizing: border-box;
  626. }
  627. .home-bottom-scroll-inner {
  628. width: 100%;
  629. padding-bottom: var(--home-goods-scroll-pad);
  630. box-sizing: border-box;
  631. }
  632. .home-bottom-category-pad {
  633. padding: 0 32rpx;
  634. box-sizing: border-box;
  635. }
  636. /* 对齐 mobile-ui/sanqiang-client-ui-demo.html .top */
  637. .filter-top-wrap {
  638. flex-shrink: 0;
  639. margin: 0 -32rpx 0;
  640. }
  641. .hero-top-main {
  642. display: flex;
  643. align-items: flex-end;
  644. justify-content: space-between;
  645. gap: 20rpx;
  646. margin-bottom: 20rpx;
  647. }
  648. .hero-top-text {
  649. flex: 1;
  650. min-width: 0;
  651. display: flex;
  652. flex-direction: column;
  653. align-items: flex-start;
  654. }
  655. .hero-brand-row {
  656. display: flex;
  657. align-items: center;
  658. gap: 12rpx;
  659. margin-bottom: 12rpx;
  660. }
  661. .hero-brand-logo {
  662. width: 88rpx;
  663. height: 88rpx;
  664. border-radius: 12rpx;
  665. flex-shrink: 0;
  666. }
  667. .hero-brand {
  668. color: #ffffff;
  669. font-size: 48rpx;
  670. font-weight: 700;
  671. line-height: 1.25;
  672. letter-spacing: 0.5rpx;
  673. }
  674. .hero-region-line {
  675. color: #ffffff;
  676. font-size: 28rpx;
  677. line-height: 1.35;
  678. width: 100%;
  679. overflow: hidden;
  680. text-overflow: ellipsis;
  681. white-space: nowrap;
  682. }
  683. /* 与供应商首页 header-watermark 同源素材,置于顶栏右侧底部对齐 */
  684. .hero-top-logo {
  685. flex-shrink: 0;
  686. width: 168rpx;
  687. height: 168rpx;
  688. opacity: 0.4;
  689. pointer-events: none;
  690. }
  691. /* demo .search:白底圆角条 + 占位灰绿字 */
  692. .search-bar {
  693. display: flex;
  694. align-items: center;
  695. height: 72rpx;
  696. background: #ffffff;
  697. border: 1rpx solid #d9e9e1;
  698. border-radius: 36rpx;
  699. padding: 0 8rpx 0 24rpx;
  700. box-sizing: border-box;
  701. }
  702. .search-input {
  703. flex: 1;
  704. min-width: 0;
  705. height: 72rpx;
  706. font-size: 28rpx;
  707. color: var(--c-text);
  708. background: transparent;
  709. border: none;
  710. padding: 0;
  711. }
  712. .search-placeholder {
  713. color: #8aa39a;
  714. }
  715. .search-action {
  716. flex-shrink: 0;
  717. padding: 0 16rpx 0 8rpx;
  718. font-size: 24rpx;
  719. color: var(--c-brand-green);
  720. font-weight: 600;
  721. }
  722. /* demo .section 内:标题 + 一级分类白卡片 */
  723. .category-section {
  724. flex-shrink: 0;
  725. /* demo .section margin 12px 0 顶 */
  726. margin-top: 24rpx;
  727. }
  728. .section-head {
  729. display: flex;
  730. align-items: center;
  731. justify-content: space-between;
  732. margin-bottom: 20rpx;
  733. }
  734. .section-title {
  735. /* demo h3 17px */
  736. font-size: 34rpx;
  737. font-weight: 600;
  738. color: var(--c-text);
  739. }
  740. .first-category-wrap {
  741. background: #ffffff;
  742. border: 1rpx solid var(--c-border);
  743. border-radius: 28rpx;
  744. padding: 8rpx;
  745. box-sizing: border-box;
  746. overflow: hidden;
  747. }
  748. .first-category-swiper {
  749. /* 收紧一级分类区高度,避免短文案卡片出现大块空白 */
  750. height: 336rpx;
  751. }
  752. .first-category-grid {
  753. display: grid;
  754. grid-template-columns: repeat(5, 1fr);
  755. gap: 16rpx;
  756. padding: 8rpx;
  757. box-sizing: border-box;
  758. width: 100%;
  759. height: 100%;
  760. align-content: start;
  761. }
  762. .first-category-grid--single {
  763. min-height: auto;
  764. }
  765. .first-category-card {
  766. display: flex;
  767. flex-direction: column;
  768. align-items: center;
  769. justify-content: flex-start;
  770. min-height: 152rpx;
  771. padding: 8rpx 4rpx 8rpx;
  772. border-radius: 28rpx;
  773. background: transparent;
  774. border: none;
  775. box-sizing: border-box;
  776. transition: opacity 0.15s ease, transform 0.15s ease;
  777. &.active {
  778. background: linear-gradient(145deg, #e7f8f0, #f1fbf6);
  779. color: var(--c-brand-green);
  780. font-weight: 600;
  781. box-shadow: 0 4rpx 8rpx rgba(10, 159, 109, 0.12);
  782. }
  783. }
  784. .first-category-card--hover {
  785. opacity: 0.88;
  786. }
  787. .first-category-image {
  788. /* demo .first-chip::before 42×42,圆角 12px */
  789. width: 84rpx;
  790. height: 84rpx;
  791. border-radius: 24rpx;
  792. background: linear-gradient(145deg, #dff1e8, #cdebdc);
  793. flex-shrink: 0;
  794. }
  795. .first-category-card.active .first-category-image {
  796. box-shadow: 0 4rpx 14rpx rgba(10, 159, 109, 0.35);
  797. }
  798. .first-category-name {
  799. /* demo .first-chip gap 8px + font 11px */
  800. margin-top: 8rpx;
  801. width: 100%;
  802. font-size: 22rpx;
  803. line-height: 1.2;
  804. color: #4f665d;
  805. text-align: center;
  806. overflow: hidden;
  807. text-overflow: ellipsis;
  808. white-space: nowrap;
  809. }
  810. .first-category-card.active .first-category-name {
  811. color: var(--c-brand-green);
  812. }
  813. .first-level-indicator {
  814. display: flex;
  815. justify-content: center;
  816. align-items: center;
  817. gap: 16rpx;
  818. margin: 16rpx auto 0;
  819. }
  820. .indicator-dot {
  821. width: 36rpx;
  822. height: 8rpx;
  823. border-radius: 999rpx;
  824. background: #dbe9e2;
  825. transition: width 0.2s ease, background 0.2s ease;
  826. }
  827. .indicator-dot.active {
  828. width: 56rpx;
  829. background: linear-gradient(145deg, var(--c-brand-green-2), var(--c-brand-green));
  830. }
  831. .product-layout {
  832. /* 随下部分 scroll 内容增高,不再单独占满一屏 */
  833. /* demo .category-layout margin-top 10px */
  834. margin-top: 20rpx;
  835. /* 宽度已由 .home-bottom-scroll 拉满,此处不再用负 margin(在 scroll-view 内易失效) */
  836. width: 100%;
  837. box-sizing: border-box;
  838. }
  839. .product-body {
  840. display: flex;
  841. align-items: stretch;
  842. /* demo .category-layout min-height 440px */
  843. min-height: 880rpx;
  844. border: 1rpx solid var(--c-border);
  845. border-radius: var(--c-radius-lg);
  846. overflow: hidden;
  847. background: var(--c-card);
  848. }
  849. .category-pane {
  850. /* demo grid 92px 侧栏 */
  851. width: 184rpx;
  852. flex-shrink: 0;
  853. align-self: stretch;
  854. background: #f8fcfa;
  855. border-right: 1rpx solid #edf5f1;
  856. border-top-left-radius: var(--c-radius-lg);
  857. border-bottom-left-radius: var(--c-radius-lg);
  858. }
  859. .category-scroll-inner {
  860. box-sizing: border-box;
  861. }
  862. .category-item {
  863. min-height: 84rpx;
  864. display: flex;
  865. align-items: center;
  866. justify-content: center;
  867. padding: 0 16rpx;
  868. font-size: 24rpx;
  869. color: #5f726a;
  870. text-align: center;
  871. border-left: 6rpx solid transparent;
  872. background: transparent;
  873. box-sizing: border-box;
  874. &.active {
  875. color: var(--c-brand-green);
  876. background: #ffffff;
  877. border-left-color: var(--c-brand-green);
  878. font-weight: 600;
  879. }
  880. }
  881. .category-item--hover {
  882. opacity: 0.88;
  883. }
  884. .goods-pane {
  885. flex: 1;
  886. min-width: 0;
  887. background: #ffffff;
  888. /* 对齐设计图 goods-area padding:10px */
  889. padding: 16rpx 0 0;
  890. display: flex;
  891. flex-direction: column;
  892. align-self: stretch;
  893. border-top-right-radius: var(--c-radius-lg);
  894. border-bottom-right-radius: var(--c-radius-lg);
  895. }
  896. .goods-scroll {
  897. flex: 1;
  898. min-width: 0;
  899. }
  900. /* 内层包裹:各端对 scroll-view 直接 padding 支持不一致,用内层垫高更稳 */
  901. .goods-scroll-inner {
  902. padding-left: 20rpx;
  903. padding-right: 20rpx;
  904. box-sizing: border-box;
  905. }
  906. .pane-footer-tip {
  907. text-align: center;
  908. color: #9ba8a2;
  909. font-size: 24rpx;
  910. padding: 20rpx 12rpx 12rpx;
  911. }
  912. /* 列表结束文案:收紧与下方滚动留白的间距 */
  913. .pane-footer-tip--nomore {
  914. padding-top: 12rpx;
  915. padding-bottom: 4rpx;
  916. }
  917. .empty-list-tip {
  918. text-align: center;
  919. color: #909399;
  920. font-size: 28rpx;
  921. padding: 40rpx 0;
  922. }
  923. .goods-card {
  924. display: grid;
  925. /* 窄屏:缩略图列随屏宽比例收缩;宽屏仍接近 demo 约 92px/侧 */
  926. grid-template-columns: minmax(112rpx, 36%) minmax(0, 1fr);
  927. gap: min(16rpx, 2.5vw);
  928. align-items: stretch;
  929. background: #fff;
  930. padding: 0;
  931. border: 1rpx solid var(--c-border);
  932. border-radius: var(--c-radius-md);
  933. margin-bottom: 16rpx;
  934. overflow: hidden;
  935. box-sizing: border-box;
  936. }
  937. .goods-card--pressed {
  938. opacity: 0.96;
  939. }
  940. .goods-image {
  941. width: 100%;
  942. align-self: start;
  943. aspect-ratio: 1 / 1;
  944. height: auto;
  945. min-height: 112rpx;
  946. max-height: 208rpx;
  947. border-radius: 16rpx;
  948. background: linear-gradient(145deg, #f4fbf8, #e4f6ef);
  949. flex-shrink: 0;
  950. }
  951. .goods-main {
  952. padding: 10rpx 12rpx 10rpx 0;
  953. min-width: 0;
  954. display: flex;
  955. flex-direction: column;
  956. justify-content: space-between;
  957. }
  958. .goods-name {
  959. display: -webkit-box;
  960. -webkit-box-orient: vertical;
  961. -webkit-line-clamp: 2;
  962. overflow: hidden;
  963. font-size: clamp(22rpx, 3.4vw, 26rpx);
  964. line-height: 1.35;
  965. min-height: 0;
  966. color: var(--c-text);
  967. font-weight: 400;
  968. word-break: break-word;
  969. }
  970. .goods-spec {
  971. display: block;
  972. margin: 6rpx 0 12rpx;
  973. font-size: clamp(20rpx, 3vw, 22rpx);
  974. color: var(--c-muted);
  975. overflow: hidden;
  976. text-overflow: ellipsis;
  977. white-space: nowrap;
  978. }
  979. .bottom-row {
  980. /* 栅格:左侧价格区可收缩省略,右侧操作区独占一列,避免 flex 与 text 组件叠在一起 */
  981. display: grid;
  982. grid-template-columns: minmax(0, 1fr) auto;
  983. align-items: center;
  984. column-gap: 12rpx;
  985. row-gap: 8rpx;
  986. margin-top: auto;
  987. min-width: 0;
  988. }
  989. .goods-price {
  990. min-width: 0;
  991. max-width: 100%;
  992. display: block;
  993. overflow: hidden;
  994. text-overflow: ellipsis;
  995. white-space: nowrap;
  996. font-size: clamp(24rpx, 3.8vw, 32rpx);
  997. color: var(--c-danger);
  998. font-weight: 700;
  999. }
  1000. .bottom-row-actions {
  1001. display: flex;
  1002. align-items: center;
  1003. justify-content: flex-end;
  1004. flex-shrink: 0;
  1005. padding-right: 12rpx;
  1006. }
  1007. .add-btn {
  1008. flex-shrink: 0;
  1009. width: clamp(36rpx, 7.5vw, 48rpx);
  1010. height: clamp(36rpx, 7.5vw, 48rpx);
  1011. background: var(--c-brand-green);
  1012. border-radius: 50%;
  1013. display: flex;
  1014. align-items: center;
  1015. justify-content: center;
  1016. color: #ffffff;
  1017. font-size: clamp(22rpx, 4.5vw, 30rpx);
  1018. font-weight: 700;
  1019. box-sizing: border-box;
  1020. padding: 0;
  1021. line-height: 1;
  1022. }
  1023. /* 「+」在圆内几何居中:抵消 text 默认行高/基线导致的视觉偏移 */
  1024. .add-btn-plus {
  1025. line-height: 1;
  1026. font-size: inherit;
  1027. font-weight: inherit;
  1028. color: inherit;
  1029. text-align: center;
  1030. display: block;
  1031. transform: translateY(-2rpx);
  1032. }
  1033. .quantity-control {
  1034. display: flex;
  1035. align-items: center;
  1036. gap: 6rpx;
  1037. flex-shrink: 0;
  1038. }
  1039. .qty-btn {
  1040. width: clamp(32rpx, 6.5vw, 42rpx);
  1041. height: clamp(32rpx, 6.5vw, 42rpx);
  1042. border: 1rpx solid #b9decf;
  1043. border-radius: 50%;
  1044. display: flex;
  1045. align-items: center;
  1046. justify-content: center;
  1047. color: var(--c-brand-green);
  1048. font-size: clamp(18rpx, 3.2vw, 24rpx);
  1049. font-weight: 700;
  1050. background: #fff;
  1051. box-sizing: border-box;
  1052. }
  1053. .qty-num {
  1054. min-width: 40rpx;
  1055. max-width: 64rpx;
  1056. text-align: center;
  1057. font-size: clamp(18rpx, 3vw, 24rpx);
  1058. color: #303133;
  1059. overflow: hidden;
  1060. text-overflow: ellipsis;
  1061. }
  1062. // 底部购物车:对齐 demo .cart-bar / .cart-inner / .settle
  1063. .cart-bar {
  1064. position: fixed;
  1065. left: 50%;
  1066. transform: translateX(-50%);
  1067. z-index: 10010;
  1068. width: 100%;
  1069. max-width: 840rpx;
  1070. padding: 0 24rpx;
  1071. box-sizing: border-box;
  1072. overflow: visible;
  1073. /* 紧贴 tab 上沿:略留一点避免与底栏视觉粘连(H5 原 +44rpx 空隙偏大) */
  1074. /* #ifdef H5 */
  1075. bottom: calc(var(--window-bottom, calc(50px + env(safe-area-inset-bottom, 0px))) + 2rpx);
  1076. /* #endif */
  1077. /* #ifndef H5 */
  1078. bottom: 10px;
  1079. /* #endif */
  1080. }
  1081. .cart-inner {
  1082. min-height: 96rpx;
  1083. border-radius: 36rpx;
  1084. background: linear-gradient(145deg, #ffffff, #f5fbf8);
  1085. border: 1rpx solid #d9ebe3;
  1086. color: var(--c-text);
  1087. display: flex;
  1088. align-items: center;
  1089. justify-content: space-between;
  1090. padding: 12rpx;
  1091. box-shadow: 0 16rpx 36rpx rgba(10, 159, 109, 0.12);
  1092. box-sizing: border-box;
  1093. }
  1094. .cart-left {
  1095. display: flex;
  1096. align-items: center;
  1097. gap: 20rpx;
  1098. padding-left: 8rpx;
  1099. flex: 1;
  1100. min-width: 0;
  1101. }
  1102. .cart-count {
  1103. min-width: 52rpx;
  1104. height: 52rpx;
  1105. padding: 0 8rpx;
  1106. border-radius: 26rpx;
  1107. background: linear-gradient(145deg, var(--c-brand-green), var(--c-brand-green-2));
  1108. display: inline-flex;
  1109. align-items: center;
  1110. justify-content: center;
  1111. box-sizing: border-box;
  1112. text {
  1113. font-size: 24rpx;
  1114. font-weight: 700;
  1115. color: #fff;
  1116. }
  1117. }
  1118. .cart-text-col {
  1119. display: flex;
  1120. flex-direction: column;
  1121. gap: 2rpx;
  1122. min-width: 0;
  1123. }
  1124. .cart-items-label {
  1125. font-size: 22rpx;
  1126. color: #6f8179;
  1127. }
  1128. .cart-total-money {
  1129. font-size: 32rpx;
  1130. font-weight: 700;
  1131. letter-spacing: 0.4rpx;
  1132. color: #1f2a26;
  1133. }
  1134. .cart-settle {
  1135. flex-shrink: 0;
  1136. min-height: 72rpx;
  1137. padding: 0 32rpx;
  1138. border-radius: 28rpx;
  1139. background: linear-gradient(145deg, var(--c-barley-yellow), #e4b458);
  1140. color: #fff;
  1141. display: inline-flex;
  1142. align-items: center;
  1143. justify-content: center;
  1144. font-size: 28rpx;
  1145. font-weight: 700;
  1146. box-shadow: inset 0 -2rpx 0 rgba(0, 0, 0, 0.1);
  1147. text {
  1148. color: #fff;
  1149. }
  1150. }
  1151. // 加载状态
  1152. .loading-state {
  1153. display: flex;
  1154. align-items: center;
  1155. justify-content: center;
  1156. padding: 40rpx 0;
  1157. color: #909399;
  1158. font-size: 28rpx;
  1159. }
  1160. </style>