home.vue 33 KB

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