样式
This commit is contained in:
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import Taro, { useDidShow } from '@tarojs/taro'
|
||||
import { View, Text, Image, Textarea, ScrollView } from '@tarojs/components'
|
||||
import { Button, Empty, Icon, Popup, Stepper } from '@antmjs/vantui'
|
||||
import useAuthStore from '@/stores/auth/useAuthStore'
|
||||
import useCartStore from '@/stores/cart/useCartStore'
|
||||
import { createOrderApi } from '@/services/order'
|
||||
import { getStoreInfoApi } from '@/services/store'
|
||||
@@ -12,6 +13,7 @@ import type { StoreDetail } from '@/types/store'
|
||||
import './index.less'
|
||||
|
||||
export default function CartPage() {
|
||||
const token = useAuthStore(s => s.token)
|
||||
const items = useCartStore(s => s.items)
|
||||
const totalQuantity = useCartStore(s => s.totalQuantity)
|
||||
const totalAmount = useCartStore(s => s.totalAmount)
|
||||
@@ -39,6 +41,12 @@ export default function CartPage() {
|
||||
const purchasable = items.filter(item => item.status === 1)
|
||||
const hasInvalid = items.length > 0 && purchasable.length < items.length
|
||||
|
||||
const loggedIn = !!token
|
||||
|
||||
const goLogin = useCallback(() => {
|
||||
Taro.navigateTo({ url: '/pages/login/index' })
|
||||
}, [])
|
||||
|
||||
/** 拉取门店配送信息 */
|
||||
const fetchStoreInfo = useCallback(() => {
|
||||
setStoreLoading(true)
|
||||
@@ -49,6 +57,8 @@ export default function CartPage() {
|
||||
}, [])
|
||||
|
||||
useDidShow(() => {
|
||||
// 未登录不请求接口,直接展示去登录空态(参考消息页)
|
||||
if (!loggedIn) return
|
||||
fetchCart().catch(() => {})
|
||||
// 从门店信息编辑页返回且弹层仍打开时 → 刷新配送信息
|
||||
if (showOrder) fetchStoreInfo()
|
||||
@@ -177,13 +187,17 @@ export default function CartPage() {
|
||||
{/* ========== 头部 ========== */}
|
||||
<View className='cart-header'>
|
||||
<Text className='cart-header__title'>购物车</Text>
|
||||
{items.length > 0 && (
|
||||
{loggedIn && items.length > 0 && (
|
||||
<Text className='cart-header__clear' onClick={handleClear}>清空</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* ========== 列表 ========== */}
|
||||
{items.length === 0 ? (
|
||||
{!loggedIn ? (
|
||||
<Empty description='登录后查看购物车' className='cart-empty'>
|
||||
<View className='cart-empty__btn' onClick={goLogin}>去登录</View>
|
||||
</Empty>
|
||||
) : items.length === 0 ? (
|
||||
loading ? (
|
||||
<View className='cart-loading'><Text>加载中...</Text></View>
|
||||
) : (
|
||||
@@ -238,14 +252,14 @@ export default function CartPage() {
|
||||
))
|
||||
)}
|
||||
|
||||
{hasInvalid && (
|
||||
{loggedIn && hasInvalid && (
|
||||
<View className='cart-invalid-hint'>
|
||||
<Text>部分商品已下架或未设置您所在等级的价格,不可下单</Text>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* ========== 底部结算栏 ========== */}
|
||||
{items.length > 0 && (
|
||||
{loggedIn && items.length > 0 && (
|
||||
<View className='cart-footer'>
|
||||
<View className='cart-footer__total'>
|
||||
<Text className='cart-footer__label'>合计(可购{totalQuantity}件)</Text>
|
||||
|
||||
Reference in New Issue
Block a user