Compare commits

...

17 Commits

Author SHA1 Message Date
xinadmin 8f9b54ce76 运营报表优化 2026-09-07 23:09:44 +08:00
xinadmin a85da7a5d1 账单备注调整 2026-09-07 22:37:53 +08:00
xinadmin 1b9e505feb 调整样式 2026-09-06 23:15:13 +08:00
xinadmin 74aee003e7 H5支付 2026-09-04 21:54:10 +08:00
xinadmin e2926b0c70 H5适配 2026-09-04 14:10:33 +08:00
xinadmin 1701169c9d 账单样式 2026-09-03 20:47:55 +08:00
xinadmin e97cc128ec 首页推荐修改 2026-09-03 19:37:42 +08:00
xinadmin 9d893b4ed4 小程序样式更新 2026-08-31 15:43:01 +08:00
xinadmin 130ef2c949 优化金额显示等 2026-08-29 13:52:57 +08:00
xinadmin 2317c9d973 支付 2026-08-27 21:18:01 +08:00
xinadmin 260d8086bf 购物车悬浮加减 2026-08-27 18:08:14 +08:00
xinadmin 78c787d207 协议 2026-08-27 14:25:03 +08:00
xinadmin 4bbe92d8e8 样式 2026-08-21 12:41:15 +08:00
xinadmin 8a7bdca6b1 远程地址 2026-08-21 12:06:55 +08:00
xinadmin 69b72a9c1c 运营报表 2026-08-21 12:04:39 +08:00
xinadmin ffe983b9da 显示格式优化 2026-08-21 11:35:05 +08:00
xinadmin f0d8f6bac4 账户密码登录 2026-08-21 11:01:37 +08:00
63 changed files with 2599 additions and 975 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"miniprogramRoot": "./", "miniprogramRoot": "./",
"projectname": "pure-project-vantui", "projectname": "pure-project-vantui",
"description": "", "description": "",
"appid": "wx7ed74d60503b5ee3", "appid": "wx8f48874e3bf1dccd",
"setting": { "setting": {
"urlCheck": false, "urlCheck": false,
"es6": true, "es6": true,
+4 -1
View File
@@ -7,6 +7,7 @@ export default defineAppConfig({
'pages/message/index', 'pages/message/index',
'pages/profile/index', 'pages/profile/index',
'pages/order-list/index', 'pages/order-list/index',
'pages/report/index',
'pages/bill/index', 'pages/bill/index',
'pages/bill-detail/index', 'pages/bill-detail/index',
'pages/payment/index', 'pages/payment/index',
@@ -14,7 +15,9 @@ export default defineAppConfig({
'pages/payment-detail/index', 'pages/payment-detail/index',
'pages/settings/index', 'pages/settings/index',
'pages/login/index', 'pages/login/index',
'pages/register/index', 'pages/agreement/index',
'pages/privacy/index',
'pages/change-password/index',
'pages/store-info/index', 'pages/store-info/index',
], ],
window: { window: {
+57
View File
@@ -0,0 +1,57 @@
// 购物车悬浮球:右下角,底部避让自定义 tabBar(110rpx + 安全区)
.cart-ball {
position: fixed;
left: 24rpx;
bottom: calc(150rpx + env(safe-area-inset-bottom));
z-index: 998;
display: flex;
align-items: center;
height: 88rpx;
padding: 0 32rpx 0 8rpx;
background: #fff;
border-radius: 999rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.15);
box-sizing: border-box;
&__icon {
position: relative;
width: 72rpx;
height: 72rpx;
border-radius: 50%;
background: linear-gradient(135deg, #ee0a24, #ff6034);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
&__badge {
position: absolute;
top: -8rpx;
right: -16rpx;
min-width: 32rpx;
height: 32rpx;
padding: 0 8rpx;
box-sizing: border-box;
background: #fff;
border: 2rpx solid #ee0a24;
border-radius: 999rpx;
display: flex;
align-items: center;
justify-content: center;
}
&__badge-text {
color: #ee0a24;
font-size: 20rpx;
font-weight: 600;
line-height: 1;
}
&__amount {
margin-left: 16rpx;
color: #ee0a24;
font-size: 32rpx;
font-weight: 700;
}
}
+38
View File
@@ -0,0 +1,38 @@
import { useCallback } from 'react'
import Taro from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { Icon } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore'
import useCartStore from '@/stores/cart/useCartStore'
import { formatQuantity } from '@/utils/format'
import './index.less'
/**
* 购物车悬浮球(首页 / 商品列表页右下角,位于自定义 tabBar 上方):
* 展示可购总数量徽标与总金额,点击跳转购物车页;
* 未登录或购物车为空(total_count = 0)时隐藏
*/
export default function CartBall() {
const token = useAuthStore(s => s.token)
const totalCount = useCartStore(s => s.totalCount)
const totalQuantity = useCartStore(s => s.totalQuantity)
const totalAmount = useCartStore(s => s.totalAmount)
const goCart = useCallback(() => {
Taro.switchTab({ url: '/pages/cart/index' })
}, [])
if (!token || totalCount <= 0) return null
return (
<View className='cart-ball' onClick={goCart}>
<View className='cart-ball__icon'>
<Icon name='shopping-cart-o' size='40rpx' color='#ffffff' />
<View className='cart-ball__badge'>
<Text className='cart-ball__badge-text'>{formatQuantity(totalQuantity)}</Text>
</View>
</View>
<Text className='cart-ball__amount'>¥{totalAmount}</Text>
</View>
)
}
+42
View File
@@ -0,0 +1,42 @@
.cart-stepper {
display: flex;
align-items: center;
flex-shrink: 0;
&__btn {
width: 42rpx;
height: 42rpx;
border-radius: 50%;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
background: #fff;
border: 2rpx solid #ee0a24;
&--plus {
background: linear-gradient(135deg, #ee0a24, #ff6034);
border: none;
}
}
&__btn-icon {
font-size: 30rpx;
line-height: 1;
color: #ee0a24;
}
&__btn--plus &__btn-icon {
color: #fff;
}
&__qty {
min-width: 64rpx;
padding: 0 4rpx;
box-sizing: border-box;
text-align: center;
font-size: 28rpx;
color: #323233;
font-weight: 500;
}
}
+121
View File
@@ -0,0 +1,121 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { View, Text } from '@tarojs/components'
import { addCartApi, deleteCartItemApi, updateCartItemApi } from '@/services/cart'
import useCartStore from '@/stores/cart/useCartStore'
import { formatQuantity } from '@/utils/format'
import type { Product, ProductCartPatch } from '@/types/product'
import './index.less'
/** 加减防抖间隔(ms):连续点击合并为一次提交 */
const DEBOUNCE_MS = 400
interface CartStepperProps {
/** 商品行(使用 id / price / cart_id / cart_quantity */
product: Product
/** 服务端确认后的行数据回写(父组件更新列表项的 cart_id/cart_quantity */
onSync: (productId: number, patch: ProductCartPatch) => void
}
/**
* 商品行内购物车加减(商品列表 / 首页推荐共用,仅在 cart_quantity > 0 时由父组件渲染):
* - 点击即时更新本地数量与悬浮球(乐观展示),防抖后提交服务端
* - 不在购物车(cart_id=0)→ POST /mini/cart 合并加购;已存在 → PUT 绝对数量;减到 0 → DELETE
* (数量为 0 不能调 PUT,后端校验数量必须 > 0)
* - 同一商品的提交串行执行,避免并发导致数量错乱
* - 失败回滚本地数量(请求层已 toast),并立即整体校准悬浮球
*/
export default function CartStepper({ product, onSync }: CartStepperProps) {
const applyDelta = useCartStore(s => s.applyDelta)
const fetchSummary = useCartStore(s => s.fetchSummary)
/** 本地编辑数量(乐观值;null = 展示服务端确认值) */
const [draft, setDraft] = useState<number | null>(null)
/** 最新待提交的目标数量 */
const targetRef = useRef<number | null>(null)
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
/** 提交串行队列 */
const chainRef = useRef<Promise<void>>(Promise.resolve())
/** 最新商品行快照(供防抖/串行回调读取服务端确认值,避免闭包过期) */
const productRef = useRef(product)
productRef.current = product
/** 卸载时清理防抖定时器 */
useEffect(
() => () => {
if (timerRef.current) clearTimeout(timerRef.current)
},
[],
)
/** 提交目标数量(串行执行;与服务器一致时跳过) */
const runSubmit = useCallback(
async (target: number) => {
const p = productRef.current
const confirmed = Number(p.cart_quantity ?? 0)
if (target === confirmed) return
try {
if (target <= 0) {
if (p.cart_id) await deleteCartItemApi(p.cart_id)
onSync(p.id, { cart_id: 0, cart_quantity: '0.00' })
} else if (p.cart_id) {
const res = await updateCartItemApi(p.cart_id, target)
onSync(p.id, { cart_id: p.cart_id, cart_quantity: res.data.quantity })
} else {
// 未加购过:POST 合并加购,用返回的行 id 回写本地 cart_id
const res = await addCartApi({ product_id: p.id, quantity: target })
onSync(p.id, { cart_id: res.data.id, cart_quantity: res.data.quantity })
}
// 提交期间用户未再改动 → 本地数量落回服务端确认值(onSync 已回写,展示不变)
setDraft(prev => (prev === target ? null : prev))
} catch {
// 失败(超上限等,请求层已 toast):放弃后续目标,回滚本地展示并校准悬浮球
targetRef.current = null
setDraft(null)
fetchSummary().catch(() => {})
}
},
[onSync, fetchSummary],
)
/** 点击加/减:乐观更新本地数量与悬浮球,防抖后入队提交 */
const handleTap = useCallback(
(delta: 1 | -1) => {
const before = draft ?? Number(productRef.current.cart_quantity ?? 0)
const after = Math.round(Math.max(0, before + delta) * 100) / 100
if (after === before) return
setDraft(after)
targetRef.current = after
// 悬浮球乐观增减(金额按行内售价估算,防抖结束后由服务端汇总校准);
// 数量跨过 0 时同步增减商品种数
const price = Number(productRef.current.price ?? 0)
applyDelta({
quantity: delta,
amount: Math.round(price * delta * 100) / 100,
count: before === 0 && after > 0 ? 1 : before > 0 && after === 0 ? -1 : 0,
})
if (timerRef.current) clearTimeout(timerRef.current)
timerRef.current = setTimeout(() => {
timerRef.current = null
const target = targetRef.current
if (target === null) return
targetRef.current = null
chainRef.current = chainRef.current.then(() => runSubmit(target))
}, DEBOUNCE_MS)
},
[draft, applyDelta, runSubmit],
)
const shown = draft ?? Number(product.cart_quantity ?? 0)
return (
<View className='cart-stepper' onClick={e => e.stopPropagation()}>
<View className='cart-stepper__btn' onClick={() => handleTap(-1)}>
<Text className='cart-stepper__btn-icon'></Text>
</View>
<Text className='cart-stepper__qty'>{formatQuantity(shown)}</Text>
<View className='cart-stepper__btn cart-stepper__btn--plus' onClick={() => handleTap(1)}>
<Text className='cart-stepper__btn-icon'></Text>
</View>
</View>
)
}
@@ -1,8 +1,6 @@
import {useEffect, useState} from 'react' import {useEffect, useState} from 'react'
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import {View, Text, Image} from '@tarojs/components' import {View, Text, Image} from '@tarojs/components'
import useAuthStore from '@/stores/auth/useAuthStore'
import useCartStore from '@/stores/cart/useCartStore'
import IndexImage from '@/static/images/nav/index.png'; import IndexImage from '@/static/images/nav/index.png';
import IndexActiveImage from '@/static/images/nav/index_active.png'; import IndexActiveImage from '@/static/images/nav/index_active.png';
import CartImage from '@/static/images/nav/cart.png'; import CartImage from '@/static/images/nav/cart.png';
+21
View File
@@ -0,0 +1,21 @@
// ===== 零售价标注:小字置灰 =====
.price-text__retail {
font-size: 20rpx;
color: #969799;
font-weight: 400;
line-height: 1.4;
white-space: nowrap;
}
// inline 模式:与大价格同行,左间距分隔
.price-text__retail--inline {
margin-left: 8rpx;
}
// block 模式:大价格 / 零售价上下两行(窄卡片布局)
.price-text {
display: flex;
flex-direction: column;
align-items: flex-start;
line-height: 1.3;
}
+49
View File
@@ -0,0 +1,49 @@
import { Text, View } from '@tarojs/components'
import { formatRetailPrice } from '@/utils/format'
import './index.less'
interface PriceTextProps {
/** 售价(展示为 ¥price */
price: string | number
/** 包规(用于计算零售价;无法计算时不展示零售价) */
spec?: string | number | null
/** 大价格样式类(字号 / 颜色由调用方控制) */
className?: string
/**
* 零售价布局:
* - inline 跟随大价格同行(宽裕区域:商品详情、各类弹层行)
* - block 独占一行(窄卡片:首页推荐、商品列表、购物车)
*/
mode?: 'inline' | 'block'
/** 单位 */
price_unit?: string | null
}
/**
* 商品价格:售价 + 零售价标注(小字)
* price=30、spec=15 → ¥30 零售价:¥2
*/
export default function PriceText({ price, spec, className, mode = 'inline', price_unit }: PriceTextProps) {
const retail = formatRetailPrice(price, spec)
// 窄卡片:大价格 / 零售价上下两行,避免与右侧按钮(+/步进器)挤压换行
if (mode === 'block') {
return (
<View className={`price-text ${className ?? ''}`}>
<Text className='price-text__main'>{price}</Text>
{retail !== null && (
<Text className='price-text__retail'>{retail} {price_unit}</Text>
)}
</View>
)
}
return (
<Text className={className}>
{price}
{retail !== null && (
<Text className='price-text__retail price-text__retail--inline'>{retail} {price_unit}</Text>
)}
</Text>
)
}
+1
View File
@@ -10,6 +10,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title>订货采购</title> <title>订货采购</title>
<script crossorigin="anonymous" src="https://polyfill.alicdn.com/polyfill.min.js?features=es2015%2Ces2016%2Ces2017%2Ces2018%2Ces2019%2Ces2020%2Ces2021%2Ces2022"></script> <script crossorigin="anonymous" src="https://polyfill.alicdn.com/polyfill.min.js?features=es2015%2Ces2016%2Ces2017%2Ces2018%2Ces2019%2Ces2020%2Ces2021%2Ces2022"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script><%= htmlWebpackPlugin.options.script %></script> <script><%= htmlWebpackPlugin.options.script %></script>
</head> </head>
<body> <body>
+4
View File
@@ -0,0 +1,4 @@
export default definePageConfig({
navigationStyle: 'custom',
navigationBarTitleText: '用户服务协议',
})
+54
View File
@@ -0,0 +1,54 @@
/* ========================================
协议/政策页面(用户协议、隐私政策共用)
======================================== */
.agreement-page {
min-height: 100vh;
background: #fff;
}
.agreement-scroll {
height: 100vh;
}
.agreement-content {
padding: 32px 40px 80px;
.doc-title {
display: block;
font-size: 40px;
font-weight: 600;
color: #323233;
text-align: center;
margin-bottom: 16px;
}
.doc-updated {
display: block;
font-size: 24px;
color: #969799;
text-align: center;
margin-bottom: 48px;
}
.doc-p {
display: block;
font-size: 28px;
color: #323233;
line-height: 1.8;
margin-bottom: 24px;
text-align: justify;
}
.doc-h2 {
display: block;
font-size: 32px;
font-weight: 600;
color: #323233;
margin: 48px 0 16px;
}
.doc-bold {
font-weight: 600;
}
}
+67
View File
@@ -0,0 +1,67 @@
import { View, Text, ScrollView } from '@tarojs/components'
import './index.less'
/**
* 用户服务协议
* 静态协议文本页,由登录页/设置页进入
*/
export default function AgreementPage() {
return (
<View className='agreement-page'>
<ScrollView scrollY className='agreement-scroll'>
<View className='agreement-content'>
<Text className='doc-title'></Text>
<Text className='doc-updated'>2026821 2026821</Text>
<Text className='doc-p'>
使使
</Text>
<Text className='doc-p doc-bold'>
使
</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>1.1 </Text>
<Text className='doc-p'>1.2 使</Text>
<Text className='doc-p'>1.3 使</Text>
<Text className='doc-p'>1.4 --</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>2.1 线线</Text>
<Text className='doc-p'>2.2 </Text>
<Text className='doc-p'>2.3 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>3.1 使</Text>
<Text className='doc-p'>3.2 </Text>
<Text className='doc-p'>3.3 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>4.1 退</Text>
<Text className='doc-p'>4.2 </Text>
<Text className='doc-p'>4.3 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>5.1 </Text>
<Text className='doc-p'>5.2 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>6.1 </Text>
<Text className='doc-p'>6.2 </Text>
<Text className='doc-p'>6.3 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>7.1 使使</Text>
<Text className='doc-p'>7.2 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>8.1 </Text>
<Text className='doc-p'>8.2 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'></Text>
</View>
</ScrollView>
</View>
)
}
+10 -8
View File
@@ -115,8 +115,8 @@
} }
&__img { &__img {
width: 72rpx; width: 120rpx;
height: 72rpx; height: 120rpx;
border-radius: 8rpx; border-radius: 8rpx;
background: #f2f3f5; background: #f2f3f5;
flex-shrink: 0; flex-shrink: 0;
@@ -147,14 +147,16 @@
flex-shrink: 0; flex-shrink: 0;
} }
&__qty {
font-size: 24rpx;
color: #969799;
display: block;
}
&__amount { &__amount {
font-size: 28rpx; font-size: 28rpx;
color: #ee0a24;
font-weight: 500;
display: block;
margin-top: 4rpx;
}
&__price {
font-size: 24rpx;
color: #323233; color: #323233;
font-weight: 500; font-weight: 500;
display: block; display: block;
+35 -31
View File
@@ -5,7 +5,7 @@ import { Empty, Popup } from '@antmjs/vantui'
import { getBillDetailApi } from '@/services/bill' import { getBillDetailApi } from '@/services/bill'
import { getOrderDetailApi } from '@/services/order' import { getOrderDetailApi } from '@/services/order'
import { ORDER_STATUS_TEXT } from '@/types/order' import { ORDER_STATUS_TEXT } from '@/types/order'
import { resolveFileUrl } from '@/utils/format' import {formatRetailPrice, formatSpec, resolveFileUrl} from '@/utils/format'
import type { OrderDetail } from '@/types/order' import type { OrderDetail } from '@/types/order'
import type { BillDetail } from '@/services/bill' import type { BillDetail } from '@/services/bill'
import './index.less' import './index.less'
@@ -59,18 +59,9 @@ export default function BillDetailPage() {
const { bill, items, orders } = detail const { bill, items, orders } = detail
/** 附加金额:正=压筐附加,负=回筐抵扣(0 不带头符号) */
const addedNum = Number(bill.added_amount)
const addedLabel = addedNum < 0 ? '回筐抵扣' : '压筐附加'
const addedText =
addedNum < 0
? `-¥${Math.abs(addedNum).toFixed(2)}`
: addedNum > 0
? `+¥${addedNum.toFixed(2)}`
: '¥0.00'
/** 筐/托盘明细:正压负回,数量取绝对值(单价为出账时快照) */ /** 筐/托盘明细:正压负回,数量取绝对值(单价为出账时快照) */
const boxPart = `${bill.box_num < 0 ? '回筐' : '压筐'} ${Math.abs(bill.box_num)}×¥${bill.box_price}` const boxTotalPrice = (Number(bill.box_price) * bill.box_num).toFixed(2)
const trayPart = `${bill.tray_num < 0 ? '回托盘' : '压托盘'} ${Math.abs(bill.tray_num)}×¥${bill.tray_price}` const trayTotalPrice = (Number(bill.tray_price) * bill.tray_num).toFixed(2)
return ( return (
<View className={`bill-detail ${bill.can_pay ? 'bill-detail--pay' : ''}`}> <View className={`bill-detail ${bill.can_pay ? 'bill-detail--pay' : ''}`}>
@@ -113,17 +104,11 @@ export default function BillDetailPage() {
<Text className='bill-card__value'>{bill.pay_remark}</Text> <Text className='bill-card__value'>{bill.pay_remark}</Text>
</View> </View>
)} )}
{bill.remark && (
<View className='bill-card__row'>
<Text className='bill-card__label'></Text>
<Text className='bill-card__value'>{bill.remark}</Text>
</View>
)}
</View> </View>
{/* ===== 金额构成 ===== */} {/* ===== 金额构成 ===== */}
<View className='bill-card'> <View className='bill-card'>
<Text className='bill-section__title'></Text> <Text className='bill-section__title'></Text>
<View className='bill-card__row'> <View className='bill-card__row'>
<Text className='bill-card__label'></Text> <Text className='bill-card__label'></Text>
<Text className='bill-card__value'>{bill.product_amount}</Text> <Text className='bill-card__value'>{bill.product_amount}</Text>
@@ -133,11 +118,27 @@ export default function BillDetailPage() {
<Text className='bill-card__value'>{bill.delivery_fee}</Text> <Text className='bill-card__value'>{bill.delivery_fee}</Text>
</View> </View>
<View className='bill-card__row'> <View className='bill-card__row'>
<Text className='bill-card__label'>{addedLabel}{boxPart}{trayPart}</Text> <Text className='bill-card__label'>{bill.box_price} × {bill.box_num}</Text>
<Text className={`bill-card__value ${addedNum < 0 ? 'bill-card__value--return' : ''}`}> <Text className={`bill-card__value ${Number(boxTotalPrice) < 0 ? 'bill-card__value--return' : ''}`}>
{addedText} {Number(boxTotalPrice) < 0 ? `- ¥${boxTotalPrice}` : `${boxTotalPrice}`}
</Text> </Text>
</View> </View>
<View className='bill-card__row'>
<Text className='bill-card__label'>{bill.tray_price} × {bill.tray_num}</Text>
<Text className={`bill-card__value ${Number(trayTotalPrice) < 0 ? 'bill-card__value--return' : ''}`}>
{Number(trayTotalPrice) < 0 ? `- ¥${trayTotalPrice}` : `${trayTotalPrice}`}
</Text>
</View>
<View className='bill-card__row'>
<Text className='bill-card__label'></Text>
<Text className={`bill-card__value ${Number(bill.after_sale) < 0 ? 'bill-card__value--return' : ''}`}>
{Number(bill.after_sale) < 0 ? `- ¥${bill.after_sale}` : `${bill.after_sale}`}
</Text>
</View>
<View className='bill-card__row'>
<Text className='bill-card__label'></Text>
<Text className='bill-card__value'>{bill.remark || '暂无备注'}</Text>
</View>
<View className='bill-card__row bill-card__row--total'> <View className='bill-card__row bill-card__row--total'>
<Text className='bill-card__label'></Text> <Text className='bill-card__label'></Text>
<Text className='bill-card__total'>{bill.total_amount}</Text> <Text className='bill-card__total'>{bill.total_amount}</Text>
@@ -147,7 +148,6 @@ export default function BillDetailPage() {
{/* ===== 商品明细(跨订单按商品合并) ===== */} {/* ===== 商品明细(跨订单按商品合并) ===== */}
<View className='bill-card'> <View className='bill-card'>
<Text className='bill-section__title'>{items?.length ?? 0}</Text> <Text className='bill-section__title'>{items?.length ?? 0}</Text>
<Text className='bill-section__desc'></Text>
{(items ?? []).map(item => ( {(items ?? []).map(item => (
<View key={item.product_id} className='bill-goods'> <View key={item.product_id} className='bill-goods'>
{!!item.image && ( {!!item.image && (
@@ -159,14 +159,17 @@ export default function BillDetailPage() {
/> />
)} )}
<View className='bill-goods__main'> <View className='bill-goods__main'>
<Text className='bill-goods__name'>{item.product_name}</Text> <View className='bill-goods__name'>{item.product_name}</View>
<Text className='bill-goods__spec'> <View className='bill-goods__spec'>
{item.product_spec ? `${item.product_spec} ` : ''}{item.price}/{item.unit} {formatSpec(item.product_spec, item.unit)}
</Text> </View>
<View className='bill-goods__spec'>
{formatRetailPrice(item.price, item.spec)} {item.price_unit}
</View>
</View> </View>
<View className='bill-goods__side'> <View className='bill-goods__side'>
<Text className='bill-goods__qty'>×{item.quantity}</Text> <Text className='bill-goods__price'>{item.price} × {item.quantity}</Text>
<Text className='bill-goods__amount'>{item.amount}</Text> <View className='bill-goods__amount'>{item.amount}</View>
</View> </View>
</View> </View>
))} ))}
@@ -214,10 +217,11 @@ export default function BillDetailPage() {
<View className='order-popup__item-info'> <View className='order-popup__item-info'>
<Text className='order-popup__item-name'>{item.product_name}</Text> <Text className='order-popup__item-name'>{item.product_name}</Text>
<Text className='order-popup__item-spec'> <Text className='order-popup__item-spec'>
{item.product_spec ? `${item.product_spec} ` : ''}{item.price}/{item.unit} × {item.quantity} {formatSpec(item.product_spec, item.unit)}{' '}
{formatRetailPrice(item.price, item.product_spec)} {item.price_unit}
</Text> </Text>
</View> </View>
<Text className='order-popup__item-amount'>{item.amount}</Text> <Text className='order-popup__item-amount'>{item.price} × {item.quantity}</Text>
</View> </View>
))} ))}
</ScrollView> </ScrollView>
+26 -29
View File
@@ -9,16 +9,24 @@
padding-bottom: 160rpx; padding-bottom: 160rpx;
} }
// ===== 待支付汇总 ===== // 底部待支付汇总栏留出空间
.bill-summary { &--pay {
padding-bottom: 180rpx;
}
// ===== 底部待支付汇总栏 =====
.bill-paybar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 99;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
background: linear-gradient(135deg, #ee0a24, #ff4d4f); padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
border-radius: 16rpx; background: #fff;
padding: 28rpx; box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.06);
margin-bottom: 20rpx;
color: #fff;
&__info { &__info {
display: flex; display: flex;
@@ -26,35 +34,24 @@
} }
&__label { &__label {
font-size: 24rpx; font-size: 22rpx;
opacity: 0.85; color: #969799;
}
&__count {
margin-top: 8rpx;
font-size: 28rpx;
font-weight: 600;
} }
&__amount { &__amount {
font-size: 40rpx; margin-top: 4rpx;
font-size: 36rpx;
color: #ee0a24;
font-weight: 600; font-weight: 600;
} }
&__right { &__btn {
display: flex; padding: 16rpx 56rpx;
flex-direction: column;
align-items: flex-end;
}
&__pay {
margin-top: 12rpx;
padding: 8rpx 32rpx;
background: #fff;
color: #ee0a24;
font-size: 24rpx;
font-weight: 500;
border-radius: 999rpx; border-radius: 999rpx;
background: linear-gradient(135deg, #ee0a24, #ff6034);
color: #fff;
font-size: 28rpx;
font-weight: 500;
} }
} }
+16 -16
View File
@@ -29,7 +29,7 @@ interface CategoryOption {
/** /**
* 账单列表页 * 账单列表页
* 采购单完成后由后台按门店生成(只读);头部 summary 为门店口径待支付汇总(含审核中,不受筛选影响) * 采购单完成后由后台按门店生成(只读);底部汇总栏为门店口径待支付汇总(含审核中,不受筛选影响)
* 支持多选账单合并导出 Excel(可按一级分类过滤商品明细) * 支持多选账单合并导出 Excel(可按一级分类过滤商品明细)
*/ */
export default function BillListPage() { export default function BillListPage() {
@@ -185,22 +185,11 @@ export default function BillListPage() {
[selectedIds, toggleSelectMode], [selectedIds, toggleSelectMode],
) )
return ( /** 底部待支付汇总栏是否可见(多选导出时让位给导出栏) */
<View className={`bill-page ${selectMode ? 'bill-page--select' : ''}`}> const showPayBar = loggedIn && !selectMode && !!summary && summary.unpaid_count > 0
{/* ========== 待支付汇总(门店口径,含审核中) ========== */}
{loggedIn && summary && summary.unpaid_count > 0 && (
<View className='bill-summary'>
<View className='bill-summary__info'>
<Text className='bill-summary__label'></Text>
<Text className='bill-summary__count'>{summary.unpaid_count} </Text>
</View>
<View className='bill-summary__right'>
<Text className='bill-summary__amount'>{summary.unpaid_amount}</Text>
<View className='bill-summary__pay' onClick={goPay}></View>
</View>
</View>
)}
return (
<View className={`bill-page ${selectMode ? 'bill-page--select' : ''} ${showPayBar ? 'bill-page--pay' : ''}`}>
{/* ========== 状态筛选 + 导出入口 ========== */} {/* ========== 状态筛选 + 导出入口 ========== */}
<View className='bill-toolbar'> <View className='bill-toolbar'>
<ScrollView scrollX className='status-scroll'> <ScrollView scrollX className='status-scroll'>
@@ -278,6 +267,17 @@ export default function BillListPage() {
<View className='bill-loading'><Text></Text></View> <View className='bill-loading'><Text></Text></View>
)} )}
{/* ========== 底部待支付汇总栏(门店口径,含审核中) ========== */}
{showPayBar && summary && (
<View className='bill-paybar'>
<View className='bill-paybar__info'>
<Text className='bill-paybar__label'>{summary.unpaid_count} </Text>
<Text className='bill-paybar__amount'>{summary.unpaid_amount}</Text>
</View>
<View className='bill-paybar__btn' onClick={goPay}></View>
</View>
)}
{/* ========== 导出操作栏 ========== */} {/* ========== 导出操作栏 ========== */}
{selectMode && ( {selectMode && (
<View className='export-bar'> <View className='export-bar'>
+21 -3
View File
@@ -24,6 +24,15 @@
.cart-empty { .cart-empty {
padding-top: 160rpx; padding-top: 160rpx;
&__btn {
margin-top: 24rpx;
padding: 14rpx 60rpx;
background: #ee0a24;
color: #fff;
font-size: 28rpx;
border-radius: 999rpx;
}
} }
.cart-loading { .cart-loading {
@@ -50,8 +59,8 @@
} }
&__image { &__image {
width: 150rpx; width: 180rpx;
height: 150rpx; height: 180rpx;
border-radius: 12rpx; border-radius: 12rpx;
background: #f2f3f5; background: #f2f3f5;
flex-shrink: 0; flex-shrink: 0;
@@ -79,6 +88,15 @@
white-space: nowrap; white-space: nowrap;
} }
&__spec-tag {
margin-left: 12rpx;
font-size: 24rpx;
color: #969799;
border-radius: 6rpx;
padding: 2rpx 8rpx;
flex-shrink: 0;
}
&__invalid-tag { &__invalid-tag {
margin-left: 12rpx; margin-left: 12rpx;
font-size: 20rpx; font-size: 20rpx;
@@ -90,7 +108,6 @@
} }
&__spec { &__spec {
margin-top: 10rpx;
font-size: 24rpx; font-size: 24rpx;
color: #969799; color: #969799;
} }
@@ -158,6 +175,7 @@
padding: 16rpx 24rpx; padding: 16rpx 24rpx;
border-top: 1rpx solid #ebedf0; border-top: 1rpx solid #ebedf0;
box-sizing: border-box; box-sizing: border-box;
z-index: 99;
&__total { &__total {
flex: 1; flex: 1;
+32 -13
View File
@@ -2,14 +2,18 @@ import { useCallback, useEffect, useRef, useState } from 'react'
import Taro, { useDidShow } from '@tarojs/taro' import Taro, { useDidShow } from '@tarojs/taro'
import { View, Text, Image, Textarea, ScrollView } from '@tarojs/components' import { View, Text, Image, Textarea, ScrollView } from '@tarojs/components'
import { Button, Empty, Icon, Popup, Stepper } from '@antmjs/vantui' import { Button, Empty, Icon, Popup, Stepper } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore'
import useCartStore from '@/stores/cart/useCartStore' import useCartStore from '@/stores/cart/useCartStore'
import { createOrderApi } from '@/services/order' import { createOrderApi } from '@/services/order'
import { getStoreInfoApi } from '@/services/store' import { getStoreInfoApi } from '@/services/store'
import {formatRetailPrice, formatSpec} from '@/utils/format'
import type { CartItem } from '@/types/cart' import type { CartItem } from '@/types/cart'
import type { StoreDetail } from '@/types/store' import type { StoreDetail } from '@/types/store'
import './index.less' import './index.less'
import CustomTabBar from "@/components/CustomTabBar";
export default function CartPage() { export default function CartPage() {
const token = useAuthStore(s => s.token)
const items = useCartStore(s => s.items) const items = useCartStore(s => s.items)
const totalQuantity = useCartStore(s => s.totalQuantity) const totalQuantity = useCartStore(s => s.totalQuantity)
const totalAmount = useCartStore(s => s.totalAmount) const totalAmount = useCartStore(s => s.totalAmount)
@@ -37,6 +41,12 @@ export default function CartPage() {
const purchasable = items.filter(item => item.status === 1) const purchasable = items.filter(item => item.status === 1)
const hasInvalid = items.length > 0 && purchasable.length < items.length const hasInvalid = items.length > 0 && purchasable.length < items.length
const loggedIn = !!token
const goLogin = useCallback(() => {
Taro.navigateTo({ url: '/pages/login/index' })
}, [])
/** 拉取门店配送信息 */ /** 拉取门店配送信息 */
const fetchStoreInfo = useCallback(() => { const fetchStoreInfo = useCallback(() => {
setStoreLoading(true) setStoreLoading(true)
@@ -47,6 +57,8 @@ export default function CartPage() {
}, []) }, [])
useDidShow(() => { useDidShow(() => {
// 未登录不请求接口,直接展示去登录空态(参考消息页)
if (!loggedIn) return
fetchCart().catch(() => {}) fetchCart().catch(() => {})
// 从门店信息编辑页返回且弹层仍打开时 → 刷新配送信息 // 从门店信息编辑页返回且弹层仍打开时 → 刷新配送信息
if (showOrder) fetchStoreInfo() if (showOrder) fetchStoreInfo()
@@ -147,7 +159,7 @@ export default function CartPage() {
if (submitting) return if (submitting) return
setSubmitting(true) setSubmitting(true)
try { try {
const res = await createOrderApi({ await createOrderApi({
items: purchasable.map(item => ({ items: purchasable.map(item => ({
product_id: item.product_id, product_id: item.product_id,
quantity: Number(qtyMap[item.id] ?? item.quantity), quantity: Number(qtyMap[item.id] ?? item.quantity),
@@ -175,13 +187,17 @@ export default function CartPage() {
{/* ========== 头部 ========== */} {/* ========== 头部 ========== */}
<View className='cart-header'> <View className='cart-header'>
<Text className='cart-header__title'></Text> <Text className='cart-header__title'></Text>
{items.length > 0 && ( {loggedIn && items.length > 0 && (
<Text className='cart-header__clear' onClick={handleClear}></Text> <Text className='cart-header__clear' onClick={handleClear}></Text>
)} )}
</View> </View>
{/* ========== 列表 ========== */} {/* ========== 列表 ========== */}
{items.length === 0 ? ( {!loggedIn ? (
<Empty description='登录后查看购物车' className='cart-empty'>
<View className='cart-empty__btn' onClick={goLogin}></View>
</Empty>
) : items.length === 0 ? (
loading ? ( loading ? (
<View className='cart-loading'><Text>...</Text></View> <View className='cart-loading'><Text>...</Text></View>
) : ( ) : (
@@ -205,13 +221,12 @@ export default function CartPage() {
<Text className='cart-item__name'>{item.name}</Text> <Text className='cart-item__name'>{item.name}</Text>
{item.status === 0 && <Text className='cart-item__invalid-tag'></Text>} {item.status === 0 && <Text className='cart-item__invalid-tag'></Text>}
</View> </View>
<Text className='cart-item__spec'>{item.spec} / {item.unit}</Text> <Text className='cart-item__spec'>
{formatSpec(item.spec, item.unit)}{' '}
<View>{formatRetailPrice(item.price, item.spec)} {item.price_unit}</View>
</Text>
<View className='cart-item__bottom'> <View className='cart-item__bottom'>
{item.price !== null ? ( <Text className='cart-item__price'>{item.price}</Text>
<Text className='cart-item__price'>{item.price}</Text>
) : (
<Text className='cart-item__price cart-item__price--none'></Text>
)}
{item.status === 1 ? ( {item.status === 1 ? (
<Stepper <Stepper
value={displayQty(item)} value={displayQty(item)}
@@ -236,17 +251,19 @@ export default function CartPage() {
)) ))
)} )}
{hasInvalid && ( <View style={{ height: 100 }}></View>
{loggedIn && hasInvalid && (
<View className='cart-invalid-hint'> <View className='cart-invalid-hint'>
<Text></Text> <Text></Text>
</View> </View>
)} )}
{/* ========== 底部结算栏 ========== */} {/* ========== 底部结算栏 ========== */}
{items.length > 0 && ( {loggedIn && items.length > 0 && (
<View className='cart-footer'> <View className='cart-footer'>
<View className='cart-footer__total'> <View className='cart-footer__total'>
<Text className='cart-footer__label'>{totalQuantity}</Text> <Text className='cart-footer__label'>{totalQuantity}</Text>
<Text className='cart-footer__amount'>{totalAmount}</Text> <Text className='cart-footer__amount'>{totalAmount}</Text>
</View> </View>
<Button type='danger' className='cart-footer__submit' onClick={handleOrderTap}> <Button type='danger' className='cart-footer__submit' onClick={handleOrderTap}>
@@ -302,7 +319,7 @@ export default function CartPage() {
<Image className='order-popup__item-image' src={item.image} mode='aspectFill' lazyLoad /> <Image className='order-popup__item-image' src={item.image} mode='aspectFill' lazyLoad />
<View className='order-popup__item-title'> <View className='order-popup__item-title'>
<Text className='order-popup__item-name'>{item.name}</Text> <Text className='order-popup__item-name'>{item.name}</Text>
<Text className='order-popup__item-spec'>{item.spec} / {item.unit}</Text> <Text className='order-popup__item-spec'>{formatSpec(item.spec, item.unit)}</Text>
</View> </View>
</View> </View>
<View className='order-popup__item-right'> <View className='order-popup__item-right'>
@@ -335,6 +352,8 @@ export default function CartPage() {
</View> </View>
</View> </View>
</Popup> </Popup>
{process.env.TARO_ENV === 'h5' && <CustomTabBar />}
</View> </View>
) )
} }
@@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '修改密码',
})
+48
View File
@@ -0,0 +1,48 @@
.change-password-page {
min-height: 100vh;
background: #f7f8fa;
padding: 20rpx 24rpx 60rpx;
box-sizing: border-box;
// ===== 表单区块 =====
.pwd-section {
background: #fff;
border-radius: 20rpx;
padding: 8rpx 28rpx;
margin-bottom: 20rpx;
}
// ===== 表单行 =====
.pwd-field {
display: flex;
align-items: center;
padding: 28rpx 0;
border-bottom: 1rpx solid #f2f3f5;
&:last-child {
border-bottom: none;
}
&__label {
width: 160rpx;
flex-shrink: 0;
font-size: 28rpx;
color: #323233;
}
&__input {
flex: 1;
font-size: 28rpx;
color: #323233;
}
&__placeholder {
color: #c8c9cc;
}
}
// ===== 提交按钮 =====
.pwd-submit {
margin-top: 40rpx;
}
}
+111
View File
@@ -0,0 +1,111 @@
import { useCallback, useState } from 'react'
import Taro from '@tarojs/taro'
import { View, Text, Input } from '@tarojs/components'
import { Button } from '@antmjs/vantui'
import { changePasswordApi } from '@/services/auth'
import './index.less'
/** 新密码长度限制(与后端一致:6~20 位) */
const LIMITS = {
passwordMin: 6,
passwordMax: 20,
} as const
/**
* 修改密码页
* 修改成功后现有 token 仍然有效,无需重新登录
*/
export default function ChangePasswordPage() {
/** 原密码 */
const [oldPassword, setOldPassword] = useState('')
/** 新密码 */
const [newPassword, setNewPassword] = useState('')
/** 确认新密码 */
const [rePassword, setRePassword] = useState('')
const [saving, setSaving] = useState(false)
/** 提交:PUT /mini/auth/password */
const handleSubmit = useCallback(async () => {
if (saving) return
if (!oldPassword) {
Taro.showToast({ title: '请输入原密码', icon: 'none' })
return
}
if (newPassword.length < LIMITS.passwordMin) {
Taro.showToast({ title: `新密码至少 ${LIMITS.passwordMin}`, icon: 'none' })
return
}
if (newPassword !== rePassword) {
Taro.showToast({ title: '两次输入的密码不一致', icon: 'none' })
return
}
setSaving(true)
try {
await changePasswordApi({ oldPassword, newPassword, rePassword })
Taro.showToast({ title: '密码修改成功', icon: 'success' })
setTimeout(() => Taro.navigateBack(), 800)
} catch {
// 错误提示已由 request 层 toast(原密码不正确等)
} finally {
setSaving(false)
}
}, [saving, oldPassword, newPassword, rePassword])
return (
<View className='change-password-page'>
{/* ========== 密码表单 ========== */}
<View className='pwd-section'>
<View className='pwd-field'>
<Text className='pwd-field__label'></Text>
<Input
className='pwd-field__input'
password
value={oldPassword}
maxlength={LIMITS.passwordMax}
placeholder='请输入原密码'
placeholderClass='pwd-field__placeholder'
onInput={e => setOldPassword(e.detail.value)}
/>
</View>
<View className='pwd-field'>
<Text className='pwd-field__label'></Text>
<Input
className='pwd-field__input'
password
value={newPassword}
maxlength={LIMITS.passwordMax}
placeholder={`请输入新密码(${LIMITS.passwordMin}~${LIMITS.passwordMax} 位)`}
placeholderClass='pwd-field__placeholder'
onInput={e => setNewPassword(e.detail.value)}
/>
</View>
<View className='pwd-field'>
<Text className='pwd-field__label'></Text>
<Input
className='pwd-field__input'
password
value={rePassword}
maxlength={LIMITS.passwordMax}
placeholder='请再次输入新密码'
placeholderClass='pwd-field__placeholder'
confirmType='done'
onInput={e => setRePassword(e.detail.value)}
onConfirm={handleSubmit}
/>
</View>
</View>
{/* ========== 提交 ========== */}
<Button
type='danger'
block
round
loading={saving}
className='pwd-submit'
onClick={handleSubmit}
>
</Button>
</View>
)
}
+17 -6
View File
@@ -1,7 +1,8 @@
.home-page { .home-page {
min-height: 100vh; min-height: 100vh;
background: #f7f8fa; background: #f7f8fa;
padding-bottom: calc(140rpx + env(safe-area-inset-bottom)); // 底部预留自定义 tabBar(110rpx + 安全区)+ 购物车悬浮球空间,避免内容被遮挡
padding-bottom: calc(250rpx + env(safe-area-inset-bottom));
box-sizing: border-box; box-sizing: border-box;
// ===== 自定义顶部导航栏 ===== // ===== 自定义顶部导航栏 =====
@@ -234,6 +235,17 @@
color: #969799; color: #969799;
} }
&__loading {
display: flex;
justify-content: center;
padding: 20rpx 0 8rpx;
}
&__loading-text {
font-size: 24rpx;
color: #969799;
}
&__login-btn { &__login-btn {
margin-top: 24rpx; margin-top: 24rpx;
padding: 14rpx 60rpx; padding: 14rpx 60rpx;
@@ -273,8 +285,8 @@
font-size: 28rpx; font-size: 28rpx;
color: #323233; color: #323233;
font-weight: 500; font-weight: 500;
display: block;
overflow: hidden; overflow: hidden;
margin-right: 20rpx;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
@@ -283,14 +295,13 @@
margin-top: 8rpx; margin-top: 8rpx;
font-size: 22rpx; font-size: 22rpx;
color: #969799; color: #969799;
display: block;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
&__bottom { &__bottom {
margin-top: 16rpx; margin-top: 8rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
@@ -309,8 +320,8 @@
} }
&__add { &__add {
width: 52rpx; width: 42rpx;
height: 52rpx; height: 42rpx;
border-radius: 50%; border-radius: 50%;
background: linear-gradient(135deg, #ee0a24, #ff6034); background: linear-gradient(135deg, #ee0a24, #ff6034);
display: flex; display: flex;
+150 -48
View File
@@ -1,20 +1,27 @@
import { useCallback, useMemo, useState } from 'react' import { useCallback, useMemo, useRef, useState } from 'react'
import Taro, { useDidShow } from '@tarojs/taro' import Taro, { useDidShow, useReachBottom } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import { Grid, GridItem, Icon, Search, Swiper, SwiperItem } from '@antmjs/vantui' import { Grid, GridItem, Icon, Search, Swiper, SwiperItem } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore'
import useCartStore from '@/stores/cart/useCartStore' import useCartStore from '@/stores/cart/useCartStore'
import { getHomeConfigApi } from '@/services/home' import { getHomeConfigApi } from '@/services/home'
import type { HomeConfig } from '@/services/home' import type { HomeConfig } from '@/services/home'
import { getProductListApi } from '@/services/product' import { getSpecialListApi, normalizeSpecialCart } from '@/services/special'
import { getProductCover } from '@/types/product' import { getProductCover } from '@/types/product'
import type { Product } from '@/types/product' import type { Product, ProductCartPatch } from '@/types/product'
import { getToken } from '@/utils/request'
import CartBall from '@/components/CartBall'
import CartStepper from '@/components/CartStepper'
import {formatRetailPrice, formatSpec} from '@/utils/format'
import './index.less' import './index.less'
import CustomTabBar from "@/components/CustomTabBar";
/** 首页 → 商品页的本地存储传参 key(switchTab 无法带参) */ /** 首页 → 商品页的本地存储传参 key(switchTab 无法带参) */
const PENDING_CATEGORY_KEY = 'product_category_id' const PENDING_CATEGORY_KEY = 'product_category_id'
const PENDING_KEYWORD_KEY = 'product_keyword' const PENDING_KEYWORD_KEY = 'product_keyword'
/** 特价推荐每页条数 */
const SPECIAL_PAGE_SIZE = 10
/** tabBar 页面路径(link 跳转需改用 switchTab */ /** tabBar 页面路径(link 跳转需改用 switchTab */
const TAB_PATHS = [ const TAB_PATHS = [
'pages/index/index', 'pages/index/index',
@@ -39,11 +46,21 @@ function getStatusBarHeight(): number {
export default function IndexPage() { export default function IndexPage() {
const addItem = useCartStore(s => s.addItem) const addItem = useCartStore(s => s.addItem)
const setSummary = useCartStore(s => s.setSummary)
/** 首页配置(轮播图 / 宫格导航 / 促销卡片) */ /** 首页配置(轮播图 / 宫格导航 / 促销卡片) */
const [config, setConfig] = useState<HomeConfig>({ banners: [], navs: [], promos: [] }) const [config, setConfig] = useState<HomeConfig>({ banners: [], navs: [], promos: [] })
/** 推荐商品 */ /** 特价推荐商品(后台「客户端配置 → 特价推荐」标记,价格为登录门店的等级价) */
const [products, setProducts] = useState<Product[]>([]) const [specials, setSpecials] = useState<Product[]>([])
/** 特价推荐分页 */
const [specialPage, setSpecialPage] = useState(1)
const [specialHasMore, setSpecialHasMore] = useState(false)
/** 加载更多中(首屏重置不展示,避免已渲染列表下方闪烁) */
const [specialLoading, setSpecialLoading] = useState(false)
/** 特价推荐请求序号(返回 tab 重置与上拉加载并发时,仅采用最后一次响应) */
const specialSeqRef = useRef(0)
/** 是否有「加载更多」请求进行中 */
const specialLoadingRef = useRef(false)
/** 搜索框输入 */ /** 搜索框输入 */
const [keyword, setKeyword] = useState('') const [keyword, setKeyword] = useState('')
@@ -51,28 +68,58 @@ export default function IndexPage() {
useDidShow(() => { useDidShow(() => {
loadHomeConfig() loadHomeConfig()
loadRecommend() loadSpecials(1, true)
}) })
/** 首页配置聚合数据 */ /** 上拉加载更多特价推荐 */
useReachBottom(() => {
if (!specialHasMore) return
loadSpecials(specialPage + 1, false)
})
/** 首页配置聚合数据(响应附带悬浮球汇总) */
const loadHomeConfig = useCallback(async () => { const loadHomeConfig = useCallback(async () => {
try { try {
const res = await getHomeConfigApi() const res = await getHomeConfigApi()
setConfig(res.data) setConfig(res.data)
// 旧版本后端可能未返回 cart 块
if (res.data.cart) setSummary(res.data.cart)
} catch { } catch {
// 错误已由 request 层 toast // 错误已由 request 层 toast
} }
}, []) }, [setSummary])
/** 推荐商品 */ /**
const loadRecommend = useCallback(async () => { * 特价推荐商品(reset 时回到第一页整体替换)。
try { * 行结构与 /mini/product/list 一致;响应附带悬浮球汇总
const res = await getProductListApi({ page: 1, pageSize: 10 }) */
setProducts(res.data.data) const loadSpecials = useCallback(
} catch { async (pageNum: number, reset: boolean) => {
// 错误已由 request 层 toast if (!reset && specialLoadingRef.current) return
} const seq = ++specialSeqRef.current
}, []) specialLoadingRef.current = true
if (!reset) setSpecialLoading(true)
try {
const res = await getSpecialListApi({ page: pageNum, pageSize: SPECIAL_PAGE_SIZE })
if (seq !== specialSeqRef.current) return // 已有更新的请求,丢弃本次响应
const { data, total, cart } = res.data
setSpecials(prev => (reset ? data : [...prev, ...data]))
setSpecialPage(pageNum)
setSpecialHasMore(pageNum * SPECIAL_PAGE_SIZE < total)
// 列表响应附带悬浮球汇总(旧版本后端可能未返回)
const summary = normalizeSpecialCart(cart)
if (summary) setSummary(summary)
} catch {
// 错误已由 request 层 toast
} finally {
if (seq === specialSeqRef.current) {
specialLoadingRef.current = false
setSpecialLoading(false)
}
}
},
[setSummary],
)
/** /**
* 后台配置的 link 统一跳转: * 后台配置的 link 统一跳转:
@@ -100,25 +147,46 @@ export default function IndexPage() {
Taro.switchTab({ url: '/pages/product/index' }) Taro.switchTab({ url: '/pages/product/index' })
}, []) }, [])
/** 跳转商品详情 */
const goDetail = useCallback((id: number) => {
Taro.navigateTo({ url: `/pages/product-detail/index?id=${id}` })
}, [])
/** 搜索框聚焦/提交 → 商品页搜索 */ /** 搜索框聚焦/提交 → 商品页搜索 */
const handleSearchFocus = useCallback(() => { const handleSearchFocus = useCallback(() => {
goProduct(keyword.trim()) goProduct(keyword.trim())
}, [goProduct, keyword]) }, [goProduct, keyword])
/** 快捷加购 */ /** 行内加减购确认后回写特价商品项的购物车字段 */
const handleRowSync = useCallback((productId: number, patch: ProductCartPatch) => {
setSpecials(prev => prev.map(p => (p.id === productId ? { ...p, ...patch } : p)))
}, [])
/** 快捷加购(用返回的购物车行回写,卡片随即展示加减器) */
const handleQuickAdd = useCallback( const handleQuickAdd = useCallback(
async (product: Product, e: any) => { async (product: Product, e: any) => {
e.stopPropagation() e.stopPropagation()
try { try {
await addItem(product.id, 1) const res = await addItem(product.id, 1)
handleRowSync(product.id, { cart_id: res.id, cart_quantity: res.quantity })
Taro.showToast({ title: '已加入购物车', icon: 'success' }) Taro.showToast({ title: '已加入购物车', icon: 'success' })
} catch { } catch {
// 错误(未设等级价等)已由 request 层 toast // 错误(未设等级价等)已由 request 层 toast
} }
}, },
[addItem], [addItem, handleRowSync],
) )
/** 无价格时点击:未登录引导登录,已登录但未设等级价提示原因 */
const handlePriceGuide = useCallback((e: any) => {
e.stopPropagation()
if (getToken()) {
Taro.showToast({ title: '该商品暂未设置等级价', icon: 'none' })
} else {
Taro.navigateTo({ url: '/pages/login/index' })
}
}, [])
return ( return (
<View className='home-page'> <View className='home-page'>
{/* ========== 自定义顶部导航栏 ========== */} {/* ========== 自定义顶部导航栏 ========== */}
@@ -221,49 +289,83 @@ export default function IndexPage() {
</View> </View>
)} )}
{/* ========== 推荐商品 ========== */} {/* ========== 特价推荐 ========== */}
<View className='home-recommend'> <View className='home-recommend'>
<View className='home-recommend__header'> <View className='home-recommend__header'>
<View className='home-recommend__title-wrap'> <View className='home-recommend__title-wrap'>
<View className='home-recommend__title-bar' /> <View className='home-recommend__title-bar' />
<Text className='home-recommend__title'></Text> <Text className='home-recommend__title'></Text>
</View> </View>
<Text className='home-recommend__more' onClick={() => goProduct()}> </Text> <Text className='home-recommend__more' onClick={() => goProduct()}> </Text>
</View> </View>
{ products.length === 0 ? ( { specials.length === 0 ? (
<View className='home-recommend__empty'> <View className='home-recommend__empty'>
<Text className='home-recommend__empty-text'></Text> <Text className='home-recommend__empty-text'></Text>
</View> </View>
) : ( ) : (
<View className='product-grid'> <>
{products.map(product => ( <View className='product-grid'>
<View key={product.id} className='product-card' onClick={() => goProduct()}> {specials.map(product => (
<Image <View key={product.id} className='product-card' onClick={() => goDetail(product.id)}>
className='product-card__image' <Image
src={getProductCover(product) || 'https://img.yzcdn.cn/vant/cat.jpeg'} className='product-card__image'
mode='aspectFill' src={getProductCover(product) || 'https://img.yzcdn.cn/vant/cat.jpeg'}
lazyLoad mode='aspectFill'
/> lazyLoad
<View className='product-card__info'> />
<Text className='product-card__name'>{product.name}</Text> <View className='product-card__info'>
<Text className='product-card__spec'>{product.spec} / {product.unit}</Text> <Text className='product-card__name'>{product.name}</Text>
<View className='product-card__bottom'> <View className='product-card__spec'>
{product.price !== null ? ( {formatSpec(product.spec, product.unit)}{' '}
<Text className='product-card__price'>{product.price}</Text> <View>
) : ( {product.price !== null && <>
<Text className='product-card__price product-card__price--none'></Text> {formatRetailPrice(product.price, product.spec)} {product.price_unit}
)} </>}
<View className='product-card__add' onClick={e => handleQuickAdd(product, e)}> </View>
<Text className='product-card__add-icon'></Text> </View>
<View className='product-card__bottom'>
{product.price !== null ? (
<Text className='product-card__price'>{product.price}</Text>
) : (
<Text
className='product-card__price product-card__price--none'
onClick={handlePriceGuide}
>
</Text>
)}
{/* 已加购展示行内加减器,否则展示快捷加购按钮 */}
{Number(product.cart_quantity ?? 0) > 0 ? (
<CartStepper product={product} onSync={handleRowSync} />
) : (
<View className='product-card__add' onClick={e => handleQuickAdd(product, e)}>
<Text className='product-card__add-icon'></Text>
</View>
)}
</View> </View>
</View> </View>
</View> </View>
))}
</View>
{/* 加载更多状态 */}
{specialLoading && (
<View className='home-recommend__loading'>
<Text className='home-recommend__loading-text'></Text>
</View> </View>
))} )}
</View> {!specialHasMore && specialPage > 1 && (
<View className='home-recommend__loading'>
<Text className='home-recommend__loading-text'></Text>
</View>
)}
</>
)} )}
</View> </View>
{/* ========== 购物车悬浮球 ========== */}
<CartBall />
{process.env.TARO_ENV === 'h5' && <CustomTabBar />}
</View> </View>
) )
} }
+68 -19
View File
@@ -100,17 +100,46 @@
} }
} }
/* ========== 功能介绍 ========== */ /* ========== 登录表单 ========== */
.login-features { .login-form {
margin-bottom: 80px; width: 100%;
background: #f7f8fa;
border-radius: 24px;
padding: 0 32px;
margin-bottom: 60px;
}
.feature-text { .form-item {
font-size: 26px; display: flex;
color: #c8c9cc; align-items: center;
letter-spacing: 2px; height: 112px;
border-bottom: 1px solid #ebedf0;
&:last-child {
border-bottom: none;
} }
} }
.form-label {
width: 120px;
font-size: 30px;
color: #323233;
flex-shrink: 0;
}
.form-input {
flex: 1;
height: 100%;
font-size: 30px;
color: #323233;
display: flex;
align-items: center;
}
.form-input-placeholder {
color: #c8c9cc;
}
/* ========== 登录操作区 ========== */ /* ========== 登录操作区 ========== */
.login-actions { .login-actions {
width: 100%; width: 100%;
@@ -144,26 +173,20 @@
opacity: 0.75; opacity: 0.75;
} }
/* ========== 去注册入口 ========== */ /* ========== 客服提示 ========== */
.login-switch { .login-tip {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
margin-top: 32px; margin-top: 32px;
.switch-text { .tip-text {
font-size: 28px; font-size: 26px;
color: #969799; color: #969799;
} }
.switch-link {
font-size: 28px;
color: #ee0a24;
margin-left: 8px;
}
} }
/* ========== 协议文字 ========== */ /* ========== 协议勾选区 ========== */
.login-agreement { .login-agreement {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -172,9 +195,35 @@
margin-top: 32px; margin-top: 32px;
line-height: 1.6; line-height: 1.6;
.agree-checkbox {
width: 32px;
height: 32px;
border-radius: 50%;
border: 2px solid #c8c9cc;
margin-right: 12px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
transition: all 0.2s;
&--checked {
background: #ee0a24;
border-color: #ee0a24;
}
}
.agree-checkbox-tick {
font-size: 22px;
color: #fff;
line-height: 1;
font-weight: 700;
}
.agree-text { .agree-text {
font-size: 24px; font-size: 24px;
color: #c8c9cc; color: #969799;
} }
.agree-link { .agree-link {
+78 -56
View File
@@ -1,17 +1,24 @@
import { useCallback, useEffect, useState } from 'react' import { useCallback, useState } from 'react'
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components' import { View, Text, Button, Input } from '@tarojs/components'
import CustomNavBar from '@/components/NavBar'
import useAuthStore from '@/stores/auth/useAuthStore' import useAuthStore from '@/stores/auth/useAuthStore'
import './index.less' import './index.less'
/** 登录账号长度限制(与后端一致:4~20 位) */
const USERNAME_MAX = 20
/** 密码长度限制 */
const PASSWORD_MAX = 20
export default function LoginPage() { export default function LoginPage() {
const login = useAuthStore(s => s.login) const login = useAuthStore(s => s.login)
const isLoggedIn = useAuthStore(s => !!s.token && !!s.user)
/** 登录账号(商家后台分配) */
const [username, setUsername] = useState('')
/** 登录密码 */
const [password, setPassword] = useState('')
const [submitting, setSubmitting] = useState(false) const [submitting, setSubmitting] = useState(false)
/** 是否已阅读并同意协议(默认不勾选,须用户自主勾选后才能登录) */
const isWeb = Taro.getEnv() === Taro.ENV_TYPE.WEB const [agreed, setAgreed] = useState(false)
/** 返回上一页(无页面栈时回首页) */ /** 返回上一页(无页面栈时回首页) */
const goBack = useCallback(() => { const goBack = useCallback(() => {
@@ -23,65 +30,51 @@ export default function LoginPage() {
} }
}, []) }, [])
/** 前往注册页 */ /** 账号密码登录:POST /mini/auth/login */
const goRegister = useCallback(() => {
Taro.navigateTo({ url: '/pages/register/index' })
}, [])
/** 已登录 → 自动返回 */
useEffect(() => {
if (isLoggedIn) goBack()
}, [isLoggedIn, goBack])
/** 微信一键登录(wx.login code 换 openid,仅已注册用户可登录) */
const handleLogin = useCallback(async () => { const handleLogin = useCallback(async () => {
if (submitting) return if (submitting) return
// H5 环境无法获取微信登录凭证 const account = username.trim()
if (isWeb) { if (!account) {
Taro.showToast({ title: '请在微信小程序中使用微信登录', icon: 'none' }) Taro.showToast({ title: '请输入登录账号', icon: 'none' })
return
}
if (!password) {
Taro.showToast({ title: '请输入登录密码', icon: 'none' })
return
}
if (!agreed) {
Taro.showToast({ title: '请先阅读并勾选同意《用户服务协议》和《隐私政策》', icon: 'none' })
return return
} }
setSubmitting(true) setSubmitting(true)
try { try {
const res = await Taro.login() await login({ username: account, password })
if (!res.code) { Taro.showToast({ title: '登录成功', icon: 'success' })
Taro.showToast({ title: '获取登录凭证失败', icon: 'none' }) goBack()
return } catch {
} // 错误提示已由 request 层 toast(账号或密码错误 / 账号已停用等)
await login({ code: res.code })
// 登录成功后由 effect 自动返回
} catch (e: any) {
// 未注册用户:引导前往注册页(其余错误已由 request 层提示)
if (typeof e?.msg === 'string' && e.msg.includes('用户不存在')) {
Taro.showModal({
title: '未注册',
content: '该微信账号尚未注册,需授权手机号并填写门店编码完成注册',
confirmText: '去注册',
cancelText: '取消',
success: res => {
if (res.confirm) goRegister()
},
})
}
} finally { } finally {
setSubmitting(false) setSubmitting(false)
} }
}, [login, submitting, isWeb, goRegister]) }, [login, submitting, username, password, agreed, goBack])
/** 查看用户协议 */ /** 查看用户服务协议 */
const handleShowAgreement = useCallback(() => { const handleShowAgreement = useCallback(() => {
Taro.showToast({ title: '用户协议即将上线', icon: 'none' }) Taro.navigateTo({ url: '/pages/agreement/index' })
}, []) }, [])
/** 查看隐私政策 */ /** 查看隐私政策 */
const handleShowPrivacy = useCallback(() => { const handleShowPrivacy = useCallback(() => {
Taro.showToast({ title: '隐私政策即将上线', icon: 'none' }) Taro.navigateTo({ url: '/pages/privacy/index' })
}, [])
/** 勾选/取消勾选协议 */
const toggleAgreed = useCallback(() => {
setAgreed(v => !v)
}, []) }, [])
return ( return (
<View className='login-page'> <View className='login-page'>
{/* ========== 导航栏 ========== */}
<CustomNavBar title='登录' />
{/* ========== 内容区域 ========== */} {/* ========== 内容区域 ========== */}
<View className='login-content'> <View className='login-content'>
@@ -94,9 +87,34 @@ export default function LoginPage() {
<Text className='app-slogan'> · · </Text> <Text className='app-slogan'> · · </Text>
</View> </View>
{/* 功能介绍 */} {/* 登录表单 */}
<View className='login-features'> <View className='login-form'>
<Text className='feature-text'>线 · · </Text> <View className='form-item'>
<Text className='form-label'></Text>
<Input
className='form-input'
type='text'
value={username}
maxlength={USERNAME_MAX}
placeholder='请输入登录账号'
placeholderClass='form-input-placeholder'
onInput={e => setUsername(e.detail.value)}
/>
</View>
<View className='form-item'>
<Text className='form-label'></Text>
<Input
className='form-input'
password
value={password}
maxlength={PASSWORD_MAX}
placeholder='请输入登录密码'
placeholderClass='form-input-placeholder'
confirmType='done'
onInput={e => setPassword(e.detail.value)}
onConfirm={handleLogin}
/>
</View>
</View> </View>
{/* 登录操作 */} {/* 登录操作 */}
@@ -107,19 +125,23 @@ export default function LoginPage() {
loading={submitting} loading={submitting}
disabled={submitting} disabled={submitting}
> >
{submitting ? '登录中...' : '微信一键登录'} {submitting ? '登录中...' : '登 录'}
</Button> </Button>
{/* 未注册用户入口 */} <View className='login-tip'>
<View className='login-switch' onClick={goRegister}> <Text className='tip-text'></Text>
<Text className='switch-text'></Text>
<Text className='switch-link'></Text>
</View> </View>
<View className='login-agreement'> <View className='login-agreement'>
<Text className='agree-text'></Text> <View
className={`agree-checkbox ${agreed ? 'agree-checkbox--checked' : ''}`}
onClick={toggleAgreed}
>
{agreed && <Text className='agree-checkbox-tick'></Text>}
</View>
<Text className='agree-text'></Text>
<Text className='agree-link' onClick={handleShowAgreement}> <Text className='agree-link' onClick={handleShowAgreement}>
</Text> </Text>
<Text className='agree-text'></Text> <Text className='agree-text'></Text>
<Text className='agree-link' onClick={handleShowPrivacy}> <Text className='agree-link' onClick={handleShowPrivacy}>
+3
View File
@@ -8,6 +8,7 @@ import { formatTime } from '@/utils/format'
import { NOTICE_TYPE_MAP } from '@/types/notice' import { NOTICE_TYPE_MAP } from '@/types/notice'
import type { Notice, NoticeType } from '@/types/notice' import type { Notice, NoticeType } from '@/types/notice'
import './index.less' import './index.less'
import CustomTabBar from "@/components/CustomTabBar";
const PAGE_SIZE = 10 const PAGE_SIZE = 10
@@ -123,6 +124,8 @@ export default function MessagePage() {
{loggedIn && finished && notices.length > 0 && ( {loggedIn && finished && notices.length > 0 && (
<View className='message-loading'><Text></Text></View> <View className='message-loading'><Text></Text></View>
)} )}
{process.env.TARO_ENV === 'h5' && <CustomTabBar />}
</View> </View>
) )
} }
+7 -5
View File
@@ -5,7 +5,8 @@ import { Empty, Popup } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore' import useAuthStore from '@/stores/auth/useAuthStore'
import { cancelOrderApi, getOrderDetailApi, getOrderListApi } from '@/services/order' import { cancelOrderApi, getOrderDetailApi, getOrderListApi } from '@/services/order'
import { ORDER_STATUS_FILTERS, ORDER_STATUS_TEXT } from '@/types/order' import { ORDER_STATUS_FILTERS, ORDER_STATUS_TEXT } from '@/types/order'
import { resolveFileUrl } from '@/utils/format' import {formatRetailPrice, formatSpec, resolveFileUrl} from '@/utils/format'
import PriceText from '@/components/PriceText'
import type { OrderDetail, OrderListItem, OrderStatus } from '@/types/order' import type { OrderDetail, OrderListItem, OrderStatus } from '@/types/order'
import './index.less' import './index.less'
@@ -184,8 +185,8 @@ export default function OrderListPage() {
)} )}
<View className='order-item__goods-info'> <View className='order-item__goods-info'>
<Text className='order-item__goods-name'>{i.product_name}</Text> <Text className='order-item__goods-name'>{i.product_name}</Text>
{!!i.product_spec && ( {!!formatSpec(i.product_spec, i.unit) && (
<Text className='order-item__goods-spec'>{i.product_spec} {i.unit}</Text> <Text className='order-item__goods-spec'>{formatSpec(i.product_spec, i.unit)}</Text>
)} )}
</View> </View>
<Text className='order-item__goods-qty'>×{i.quantity} </Text> <Text className='order-item__goods-qty'>×{i.quantity} </Text>
@@ -262,10 +263,11 @@ export default function OrderListPage() {
<View className='detail-popup__item-info'> <View className='detail-popup__item-info'>
<Text className='detail-popup__item-name'>{item.product_name}</Text> <Text className='detail-popup__item-name'>{item.product_name}</Text>
<Text className='detail-popup__item-spec'> <Text className='detail-popup__item-spec'>
{item.product_spec ? `${item.product_spec}${item.unit} ` : ''}{item.price} × {item.quantity} {formatSpec(item.product_spec, item.unit)}{' '}
{formatRetailPrice(item.price, item.product_spec)} {item.price_unit}
</Text> </Text>
</View> </View>
<Text className='detail-popup__item-amount'>{item.amount}</Text> <Text className='detail-popup__item-amount'>{item.price} × {item.quantity}</Text>
</View> </View>
))} ))}
</ScrollView> </ScrollView>
+96 -28
View File
@@ -2,15 +2,20 @@ import { useCallback, useEffect, useState } from 'react'
import Taro, { useRouter } from '@tarojs/taro' import Taro, { useRouter } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import { Empty } from '@antmjs/vantui' import { Empty } from '@antmjs/vantui'
import { getPaymentDetailApi, PAY_METHOD_NAMES, PAY_STATUS_NAMES } from '@/services/payment' import {
getPaymentDetailApi,
getPayStatusName,
PAY_METHOD_NAMES,
queryOnlinePaymentApi,
} from '@/services/payment'
import { resolveFileUrl } from '@/utils/format' import { resolveFileUrl } from '@/utils/format'
import type { PaymentDetail } from '@/services/payment' import type { PaymentDetail } from '@/services/payment'
import './index.less' import './index.less'
/** /**
* 支付详情页 * 支付详情页
* 支付信息 + 汇款凭证(可预览)+ 合并付款的账单(可下钻账单详情) * 线下凭证单:支付信息 + 汇款凭证(可预览)+ 合并付款的账单(可下钻账单详情),审核拒绝后可重新发起付款
* 已拒绝时底部提供「重新发起付款」(账单已由后台释放,可重新合并提交 * 在线支付单:无凭证,待支付时可「刷新支付结果」主动同步网关结果(后台通知延迟/丢失时的兜底
*/ */
export default function PaymentDetailPage() { export default function PaymentDetailPage() {
const router = useRouter() const router = useRouter()
@@ -18,16 +23,25 @@ export default function PaymentDetailPage() {
const [detail, setDetail] = useState<PaymentDetail | null>(null) const [detail, setDetail] = useState<PaymentDetail | null>(null)
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [syncing, setSyncing] = useState(false)
useEffect(() => { const loadDetail = useCallback(async () => {
if (!id) return if (!id) return
setLoading(true) setLoading(true)
getPaymentDetailApi(id) try {
.then(res => setDetail(res.data)) const res = await getPaymentDetailApi(id)
.catch(() => {}) setDetail(res.data)
.finally(() => setLoading(false)) } catch {
// 错误已由 request 层 toast
} finally {
setLoading(false)
}
}, [id]) }, [id])
useEffect(() => {
loadDetail()
}, [loadDetail])
/** 预览凭证图片 */ /** 预览凭证图片 */
const previewVoucher = useCallback((current: string) => { const previewVoucher = useCallback((current: string) => {
const urls = (detail?.payment.voucher_urls ?? []).map(resolveFileUrl) const urls = (detail?.payment.voucher_urls ?? []).map(resolveFileUrl)
@@ -39,13 +53,35 @@ export default function PaymentDetailPage() {
Taro.navigateTo({ url: `/pages/bill-detail/index?id=${billId}` }) Taro.navigateTo({ url: `/pages/bill-detail/index?id=${billId}` })
}, []) }, [])
/** 已拒绝 → 携带本组账单重新发起付款 */ /** 已拒绝 / 支付失败 → 携带本组账单重新发起付款(账单已由后台释放) */
const handleRepay = useCallback(() => { const handleRepay = useCallback(() => {
if (!detail) return if (!detail) return
const ids = detail.bills.map(b => b.id).join(',') const ids = detail.bills.map(b => b.id).join(',')
Taro.redirectTo({ url: `/pages/payment/index?ids=${ids}` }) Taro.redirectTo({ url: `/pages/payment/index?ids=${ids}` })
}, [detail]) }, [detail])
/** 在线支付待支付 → 主动查询网关同步结果(已支付则后端立即结账),随后刷新详情 */
const handleSync = useCallback(async () => {
if (!detail || syncing) return
setSyncing(true)
try {
const res = await queryOnlinePaymentApi(detail.payment.payment_no)
if (res.data.status === 1) {
Taro.showToast({ title: '支付成功', icon: 'success' })
loadDetail()
} else if (res.data.status === 2) {
Taro.showToast({ title: '支付失败,账单已释放', icon: 'none' })
loadDetail()
} else {
Taro.showToast({ title: '暂未查询到支付结果,请稍后再试', icon: 'none' })
}
} catch {
// 错误已由 request 层 toast
} finally {
setSyncing(false)
}
}, [detail, syncing, loadDetail])
if (loading && !detail) { if (loading && !detail) {
return <View className='pay-detail'><Empty description='加载中...' /></View> return <View className='pay-detail'><Empty description='加载中...' /></View>
} }
@@ -55,6 +91,8 @@ export default function PaymentDetailPage() {
const { payment, bills } = detail const { payment, bills } = detail
const vouchers = payment.voucher_urls.map(resolveFileUrl) const vouchers = payment.voucher_urls.map(resolveFileUrl)
/** 在线支付单(旺铺网关):状态语义与线下凭证单不同,无凭证 */
const isOnline = payment.pay_type === 2
return ( return (
<View className={`pay-detail ${payment.status === 2 ? 'pay-detail--reject' : ''}`}> <View className={`pay-detail ${payment.status === 2 ? 'pay-detail--reject' : ''}`}>
@@ -63,16 +101,23 @@ export default function PaymentDetailPage() {
<View className='pay-card__header'> <View className='pay-card__header'>
<Text className='pay-card__no'>{payment.payment_no}</Text> <Text className='pay-card__no'>{payment.payment_no}</Text>
<Text className={`pay-card__status pay-card__status--${payment.status}`}> <Text className={`pay-card__status pay-card__status--${payment.status}`}>
{PAY_STATUS_NAMES[payment.status]} {getPayStatusName(payment)}
</Text> </Text>
</View> </View>
<Text className='pay-card__amount'>{payment.amount}</Text> <Text className='pay-card__amount'>{payment.amount}</Text>
{payment.status === 0 && ( {payment.status === 0 && !isOnline && (
<Text className='pay-card__tip'></Text> <Text className='pay-card__tip'></Text>
)} )}
{payment.status === 0 && isOnline && (
<Text className='pay-card__tip'>
</Text>
)}
{payment.status === 2 && ( {payment.status === 2 && (
<Text className='pay-card__tip pay-card__tip--reject'> <Text className='pay-card__tip pay-card__tip--reject'>
{payment.audit_remark ? `${payment.audit_remark}` : ''} {isOnline
? '支付失败,账单已释放,可重新发起付款'
: `审核未通过${payment.audit_remark ? `${payment.audit_remark}` : ''},账单已释放,可重新发起付款`}
</Text> </Text>
)} )}
<View className='pay-card__row'> <View className='pay-card__row'>
@@ -89,6 +134,18 @@ export default function PaymentDetailPage() {
<Text className='pay-card__value'>{payment.audited_at}</Text> <Text className='pay-card__value'>{payment.audited_at}</Text>
</View> </View>
)} )}
{isOnline && payment.paid_at && (
<View className='pay-card__row'>
<Text className='pay-card__label'></Text>
<Text className='pay-card__value'>{payment.paid_at}</Text>
</View>
)}
{isOnline && payment.trade_no && (
<View className='pay-card__row'>
<Text className='pay-card__label'></Text>
<Text className='pay-card__value'>{payment.trade_no}</Text>
</View>
)}
{payment.remark && ( {payment.remark && (
<View className='pay-card__row'> <View className='pay-card__row'>
<Text className='pay-card__label'></Text> <Text className='pay-card__label'></Text>
@@ -97,22 +154,24 @@ export default function PaymentDetailPage() {
)} )}
</View> </View>
{/* ===== 汇款凭证 ===== */} {/* ===== 汇款凭证(在线支付单无凭证) ===== */}
<View className='pay-card'> {!isOnline && (
<Text className='pay-section__title'>{vouchers.length}</Text> <View className='pay-card'>
<View className='pay-vouchers'> <Text className='pay-section__title'>{vouchers.length}</Text>
{vouchers.map((url, i) => ( <View className='pay-vouchers'>
<Image {vouchers.map((url, i) => (
key={i} <Image
className='pay-vouchers__img' key={i}
src={url} className='pay-vouchers__img'
mode='aspectFill' src={url}
onClick={() => previewVoucher(url)} mode='aspectFill'
/> onClick={() => previewVoucher(url)}
))} />
))}
</View>
{vouchers.length === 0 && <Empty description='暂无凭证图片' />}
</View> </View>
{vouchers.length === 0 && <Empty description='暂无凭证图片' />} )}
</View>
{/* ===== 合并账单 ===== */} {/* ===== 合并账单 ===== */}
<View className='pay-card'> <View className='pay-card'>
@@ -132,12 +191,21 @@ export default function PaymentDetailPage() {
{bills.length === 0 && <Empty description='暂无关联账单' />} {bills.length === 0 && <Empty description='暂无关联账单' />}
</View> </View>
{/* ===== 已拒绝 → 重新付款 ===== */} {/* ===== 已拒绝 / 支付失败 → 重新付款 ===== */}
{payment.status === 2 && ( {payment.status === 2 && (
<View className='pay-bar'> <View className='pay-bar'>
<View className='pay-bar__btn' onClick={handleRepay}></View> <View className='pay-bar__btn' onClick={handleRepay}></View>
</View> </View>
)} )}
{/* ===== 在线支付待支付 → 主动同步支付结果 ===== */}
{isOnline && payment.status === 0 && (
<View className='pay-bar'>
<View className='pay-bar__btn' onClick={handleSync}>
{syncing ? '查询中...' : '刷新支付结果'}
</View>
</View>
)}
</View> </View>
) )
} }
+3 -3
View File
@@ -3,7 +3,7 @@ import Taro, { useDidShow, useReachBottom } from '@tarojs/taro'
import { View, Text, ScrollView } from '@tarojs/components' import { View, Text, ScrollView } from '@tarojs/components'
import { Empty } from '@antmjs/vantui' import { Empty } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore' import useAuthStore from '@/stores/auth/useAuthStore'
import { getPaymentListApi, PAY_METHOD_NAMES, PAY_STATUS_NAMES } from '@/services/payment' import { getPaymentListApi, getPayStatusName, PAY_METHOD_NAMES } from '@/services/payment'
import type { Payment, PayStatus } from '@/services/payment' import type { Payment, PayStatus } from '@/services/payment'
import './index.less' import './index.less'
@@ -115,7 +115,7 @@ export default function PaymentRecordsPage() {
<View className='payment-item__header'> <View className='payment-item__header'>
<Text className='payment-item__no'>{record.payment_no}</Text> <Text className='payment-item__no'>{record.payment_no}</Text>
<Text className={`payment-item__status payment-item__status--${record.status}`}> <Text className={`payment-item__status payment-item__status--${record.status}`}>
{PAY_STATUS_NAMES[record.status]} {getPayStatusName(record)}
</Text> </Text>
</View> </View>
<View className='payment-item__body'> <View className='payment-item__body'>
@@ -128,7 +128,7 @@ export default function PaymentRecordsPage() {
<Text className='payment-item__bills'> {record.bills_count ?? 0} </Text> <Text className='payment-item__bills'> {record.bills_count ?? 0} </Text>
</View> </View>
</View> </View>
{record.status === 2 && !!record.audit_remark && ( {record.status === 2 && record.pay_type !== 2 && !!record.audit_remark && (
<Text className='payment-item__reject'>{record.audit_remark}</Text> <Text className='payment-item__reject'>{record.audit_remark}</Text>
)} )}
</View> </View>
+300 -51
View File
@@ -4,7 +4,7 @@ import { View, Text, Image, Textarea } from '@tarojs/components'
import { Empty, Icon } from '@antmjs/vantui' import { Empty, Icon } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore' import useAuthStore from '@/stores/auth/useAuthStore'
import { getBillListApi } from '@/services/bill' import { getBillListApi } from '@/services/bill'
import { createPaymentApi, getPaymentConfigApi } from '@/services/payment' import { createOnlinePaymentApi, createPaymentApi, getPaymentConfigApi, queryOnlinePaymentApi } from '@/services/payment'
import { chooseAndUploadImages } from '@/utils/upload' import { chooseAndUploadImages } from '@/utils/upload'
import { resolveFileUrl } from '@/utils/format' import { resolveFileUrl } from '@/utils/format'
import type { Bill } from '@/services/bill' import type { Bill } from '@/services/bill'
@@ -17,8 +17,72 @@ const PAGE_SIZE = 20
/** 凭证最多上传张数 */ /** 凭证最多上传张数 */
const MAX_VOUCHERS = 3 const MAX_VOUCHERS = 3
/** 支付方式选项 */ /** 在线支付(调起 wx.requestPayment)仅微信小程序支持 */
const IS_WEAPP = process.env.TARO_ENV === 'weapp'
/** H5 端处于微信内置浏览器时,可走公众号网页授权 + JSAPI 在线支付 */
const IS_H5_WECHAT =
process.env.TARO_ENV === 'h5' &&
typeof navigator !== 'undefined' &&
/micromessenger/i.test(navigator.userAgent)
/** 在线支付(旺铺网关 JSAPI)是否可用:小程序 / 微信内 H5 */
const ONLINE_PAY_AVAILABLE = IS_WEAPP || IS_H5_WECHAT
/** H5 公众号支付草稿存储 key(授权跳转前暂存账单选择,回跳后恢复) */
const H5_PAY_DRAFT_KEY = 'h5_online_pay_draft'
/** H5 公众号支付草稿(授权回跳页面重载,勾选状态经 sessionStorage 恢复) */
interface H5PayDraft {
bill_ids: number[]
remark?: string
}
/**
* 调起公众号 JSAPI 支付(WeixinJSBridge 未注入时等待 WeixinJSBridgeReady 事件)
* resolve: 'ok' 支付成功 / 'cancel' 用户取消 / 'fail' 调起失败
*/
function invokeWechatJsapiPay(payParams: Record<string, any>): Promise<'ok' | 'cancel' | 'fail'> {
return new Promise(resolve => {
const invoke = () => {
;(window as any).WeixinJSBridge.invoke(
'getBrandWCPayRequest',
{
appId: String(payParams.appId || ''),
timeStamp: String(payParams.timeStamp || ''),
nonceStr: String(payParams.nonceStr || ''),
package: String(payParams.package || ''),
signType: String(payParams.signType || 'RSA'),
paySign: String(payParams.paySign || ''),
},
(res: any) => {
const msg: string = res?.err_msg || ''
if (msg === 'get_brand_wcpay_request:ok') resolve('ok')
else if (msg === 'get_brand_wcpay_request:cancel') resolve('cancel')
else resolve('fail')
},
)
}
if ((window as any).WeixinJSBridge) {
invoke()
} else {
document.addEventListener('WeixinJSBridgeReady', invoke, { once: true })
}
})
}
/** 支付方式选项(在线支付仅小程序/微信内 H5 展示,排在最前) */
const PAY_METHODS: Array<{ value: PayMethod; label: string; icon: string; desc: string }> = [ const PAY_METHODS: Array<{ value: PayMethod; label: string; icon: string; desc: string }> = [
...(ONLINE_PAY_AVAILABLE
? [
{
value: 4 as PayMethod,
label: '微信在线支付',
icon: 'wechat',
desc: IS_WEAPP ? '小程序内直接付款,免上传凭证' : '微信内直接付款,免上传凭证',
},
]
: []),
{ value: 1, label: '微信支付', icon: 'wechat', desc: '扫码完成转账' }, { value: 1, label: '微信支付', icon: 'wechat', desc: '扫码完成转账' },
{ value: 2, label: '支付宝', icon: 'alipay', desc: '扫码完成转账' }, { value: 2, label: '支付宝', icon: 'alipay', desc: '扫码完成转账' },
{ value: 3, label: '对公汇款', icon: 'credit-pay', desc: '银行转账至对公账户' }, { value: 3, label: '对公汇款', icon: 'credit-pay', desc: '银行转账至对公账户' },
@@ -26,22 +90,11 @@ const PAY_METHODS: Array<{ value: PayMethod; label: string; icon: string; desc:
/** /**
* 发起付款页(合并付款) * 发起付款页(合并付款)
* 选择本店可付款账单(?payable=1)→ 选择支付方式(展示收款码 / 对公账户)→ 上传汇款凭证 → 提交,后台审核
* 支持 ?ids=1,2 预选账单(账单详情页"去付款"跳转)
*/ */
export default function PaymentPage() { export default function PaymentPage() {
const router = useRouter()
const token = useAuthStore(s => s.token) const token = useAuthStore(s => s.token)
const loggedIn = !!token const loggedIn = !!token
/** 预选账单(路由参数,仅在首次加载时消费一次) */
const presetRef = useRef<number[] | null>(
(router.params.ids || '')
.split(',')
.map(Number)
.filter(n => n > 0),
)
const [bills, setBills] = useState<Bill[]>([]) const [bills, setBills] = useState<Bill[]>([])
const [selectedIds, setSelectedIds] = useState<number[]>([]) const [selectedIds, setSelectedIds] = useState<number[]>([])
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
@@ -50,12 +103,15 @@ export default function PaymentPage() {
const loadingRef = useRef(false) const loadingRef = useRef(false)
const [config, setConfig] = useState<PaymentConfig | null>(null) const [config, setConfig] = useState<PaymentConfig | null>(null)
const [payMethod, setPayMethod] = useState<PayMethod>(1) const [payMethod, setPayMethod] = useState<PayMethod>(ONLINE_PAY_AVAILABLE ? 4 : 1)
const [vouchers, setVouchers] = useState<UploadedFile[]>([]) const [vouchers, setVouchers] = useState<UploadedFile[]>([])
const [remark, setRemark] = useState('') const [remark, setRemark] = useState('')
const [uploading, setUploading] = useState(false) const [uploading, setUploading] = useState(false)
const [submitting, setSubmitting] = useState(false) const [submitting, setSubmitting] = useState(false)
/** 在线支付(旺铺网关 JSAPI):免凭证,调起微信支付 */
const isOnline = payMethod === 4
/** 拉取可付款账单(首次加载应用路由预选) */ /** 拉取可付款账单(首次加载应用路由预选) */
const loadBills = useCallback( const loadBills = useCallback(
async (pageNum: number, reset: boolean) => { async (pageNum: number, reset: boolean) => {
@@ -68,11 +124,7 @@ export default function PaymentPage() {
setBills(prev => (reset ? data : [...prev, ...data])) setBills(prev => (reset ? data : [...prev, ...data]))
setPage(pageNum) setPage(pageNum)
setFinished(pageNum * PAGE_SIZE >= total) setFinished(pageNum * PAGE_SIZE >= total)
if (presetRef.current) { setSelectedIds(prev => Array.from(new Set([...prev, ...data.map(i => i.id)])))
const preset = presetRef.current
presetRef.current = null
setSelectedIds(prev => Array.from(new Set([...prev, ...preset])))
}
} catch { } catch {
// 错误已由 request 层 toast // 错误已由 request 层 toast
} finally { } finally {
@@ -152,8 +204,8 @@ export default function PaymentPage() {
Taro.setClipboardData({ data: config.bank_info }) Taro.setClipboardData({ data: config.bank_info })
}, [config]) }, [config])
/** 提交付款申请 */ /** 提交线下凭证付款申请(后台审核) */
const handleSubmit = useCallback(async () => { const handleVoucherSubmit = useCallback(async () => {
if (submitting) return if (submitting) return
if (selectedIds.length === 0) { if (selectedIds.length === 0) {
Taro.showToast({ title: '请选择要付款的账单', icon: 'none' }) Taro.showToast({ title: '请选择要付款的账单', icon: 'none' })
@@ -183,8 +235,203 @@ export default function PaymentPage() {
} }
}, [submitting, selectedIds, vouchers, payMethod, remark, loadBills]) }, [submitting, selectedIds, vouchers, payMethod, remark, loadBills])
/**
* 在线支付:wx.login 取 code → 后端经旺铺网关下单 → 调起微信支付 → 主动查询同步结果
* 无论支付成功/取消都跳转支付详情(待支付单可在详情页刷新同步结果)
*/
const handleOnlinePay = useCallback(async () => {
if (submitting) return
if (!IS_WEAPP) {
Taro.showToast({ title: '请在微信小程序中使用在线支付', icon: 'none' })
return
}
if (selectedIds.length === 0) {
Taro.showToast({ title: '请选择要付款的账单', icon: 'none' })
return
}
setSubmitting(true)
try {
// 1. 获取微信登录凭证(后端换付款人 openid)
const { code } = await Taro.login()
if (!code) {
Taro.showToast({ title: '微信登录失败,请稍后重试', icon: 'none' })
return
}
// 2. 后端下单(创建支付单并锁定账单)
const res = await createOnlinePaymentApi({
bill_ids: selectedIds,
code,
remark: remark.trim() || undefined,
})
const { id, payment_no, pay_params } = res.data
// 3. 调起微信支付(pay_params 为网关透传的调起参数)
try {
await Taro.requestPayment({
timeStamp: String(pay_params.timeStamp || ''),
nonceStr: String(pay_params.nonceStr || ''),
package: String(pay_params.package || ''),
signType: (pay_params.signType || 'RSA') as 'MD5' | 'HMAC-SHA256' | 'RSA',
paySign: String(pay_params.paySign || ''),
})
} catch (e: any) {
// 用户取消或调起失败:账单仍锁定在支付单中,进详情页可刷新同步/稍后处理
const errMsg = e?.errMsg || ''
Taro.showToast({
title: errMsg.includes('cancel') ? '已取消支付' : '支付调起失败,请稍后重试',
icon: 'none',
})
setTimeout(() => {
Taro.redirectTo({ url: `/pages/payment-detail/index?id=${id}` })
}, 800)
return
}
// 4. 主动查询同步结果(网关后台通知延迟/丢失时的兜底结账)
let paid = false
try {
const q = await queryOnlinePaymentApi(payment_no)
paid = q.data.status === 1
} catch {
// 查询失败不阻断,进详情页可手动刷新
}
Taro.showToast({ title: paid ? '支付成功' : '支付结果确认中', icon: paid ? 'success' : 'none' })
setTimeout(() => {
Taro.redirectTo({ url: `/pages/payment-detail/index?id=${id}` })
}, 800)
} catch {
// 下单失败:账单可能已被其他端付款/锁定,刷新列表
loadBills(1, true)
} finally {
setSubmitting(false)
}
}, [submitting, selectedIds, remark, loadBills])
/**
* H5 公众号支付主流程(授权回跳后执行):
* 授权 code 下单(scene=mp,后端换付款人 openid)→ WeixinJSBridge 调起支付 → 主动查询同步结果
* 与小程序端一致:无论成功/取消都跳转支付详情(待支付单可在详情页刷新同步结果)
*/
const runH5OnlinePay = useCallback(
async (billIds: number[], code: string, remarkText?: string) => {
setSubmitting(true)
try {
const res = await createOnlinePaymentApi({
bill_ids: billIds,
code,
scene: 'mp',
remark: remarkText,
})
const { id, payment_no, pay_params } = res.data
const result = await invokeWechatJsapiPay(pay_params)
if (result !== 'ok') {
// 用户取消或调起失败:账单仍锁定在支付单中,进详情页可刷新同步/稍后处理
Taro.showToast({
title: result === 'cancel' ? '已取消支付' : '支付调起失败,请稍后重试',
icon: 'none',
})
setTimeout(() => {
Taro.redirectTo({ url: `/pages/payment-detail/index?id=${id}` })
}, 800)
return
}
// 主动查询同步结果(网关后台通知延迟/丢失时的兜底结账)
let paid = false
try {
const q = await queryOnlinePaymentApi(payment_no)
paid = q.data.status === 1
} catch {
// 查询失败不阻断,进详情页可手动刷新
}
Taro.showToast({ title: paid ? '支付成功' : '支付结果确认中', icon: paid ? 'success' : 'none' })
setTimeout(() => {
Taro.redirectTo({ url: `/pages/payment-detail/index?id=${id}` })
}, 800)
} catch {
// 下单失败:账单可能已被其他端付款/锁定,刷新列表
loadBills(1, true)
} finally {
setSubmitting(false)
}
},
[loadBills],
)
/** H5 公众号支付:处理微信授权回跳(URL 携带 code 且本地存在支付草稿时自动继续支付) */
const h5CallbackRef = useRef(false)
useEffect(() => {
if (!IS_H5_WECHAT || h5CallbackRef.current || !loggedIn) return
const code = new URLSearchParams(window.location.search).get('code')
if (!code) return
// 清理地址栏授权参数,避免刷新/分享带出已失效的 code
window.history.replaceState(null, '', window.location.pathname)
let draft: H5PayDraft | null = null
try {
draft = JSON.parse(window.sessionStorage.getItem(H5_PAY_DRAFT_KEY) || 'null')
window.sessionStorage.removeItem(H5_PAY_DRAFT_KEY)
} catch {
draft = null
}
if (!draft || !Array.isArray(draft.bill_ids) || draft.bill_ids.length === 0) return
h5CallbackRef.current = true
setSelectedIds(draft.bill_ids)
if (draft.remark) setRemark(draft.remark)
runH5OnlinePay(draft.bill_ids, code, draft.remark)
}, [loggedIn, runH5OnlinePay])
/**
* H5 公众号支付入口:暂存支付草稿 → 跳转微信网页授权(snsapi_base 静默授权)
* 授权后回跳本页携带 code,由上方 effect 恢复草稿并继续支付
*/
const handleH5OnlinePay = useCallback(async () => {
if (submitting) return
if (selectedIds.length === 0) {
Taro.showToast({ title: '请选择要付款的账单', icon: 'none' })
return
}
setSubmitting(true)
try {
// mp_appid 可能尚未加载完成,兜底重新拉取
let appid = config?.mp_appid
if (!appid) {
const res = await getPaymentConfigApi()
setConfig(res.data)
appid = res.data.mp_appid
}
if (!appid) {
Taro.showToast({ title: '公众号支付暂未开通,请选择其他支付方式', icon: 'none' })
setSubmitting(false)
return
}
const draft: H5PayDraft = { bill_ids: selectedIds, remark: remark.trim() || undefined }
window.sessionStorage.setItem(H5_PAY_DRAFT_KEY, JSON.stringify(draft))
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname)
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base#wechat_redirect`
} catch {
setSubmitting(false)
}
}, [submitting, selectedIds, remark, config])
/** 提交入口:按支付方式与端分发(小程序 wx.requestPayment / H5 公众号 JSAPI / 线下凭证) */
const handleSubmit = useCallback(() => {
if (isOnline) {
if (IS_H5_WECHAT) {
handleH5OnlinePay()
} else {
handleOnlinePay()
}
} else {
handleVoucherSubmit()
}
}, [isOnline, handleOnlinePay, handleH5OnlinePay, handleVoucherSubmit])
/** 当前支付方式的收款展示 */ /** 当前支付方式的收款展示 */
const renderMethodContent = () => { const renderMethodContent = () => {
if (isOnline) {
return (
<Text className='pay-method__empty'>
</Text>
)
}
if (payMethod === 3) { if (payMethod === 3) {
return config?.bank_info ? ( return config?.bank_info ? (
<View className='pay-method__content'> <View className='pay-method__content'>
@@ -284,37 +531,39 @@ export default function PaymentPage() {
{renderMethodContent()} {renderMethodContent()}
</View> </View>
{/* ========== 汇款凭证 ========== */} {/* ========== 汇款凭证(在线支付免凭证) ========== */}
<View className='pay-section'> {!isOnline && (
<View className='pay-section__header'> <View className='pay-section'>
<Text className='pay-section__title'></Text> <View className='pay-section__header'>
<Text className='pay-section__hint'> {MAX_VOUCHERS} </Text> <Text className='pay-section__title'></Text>
</View> <Text className='pay-section__hint'> {MAX_VOUCHERS} </Text>
<View className='pay-vouchers'> </View>
{vouchers.map((v, i) => { <View className='pay-vouchers'>
const url = resolveFileUrl(v.url) {vouchers.map((v, i) => {
return ( const url = resolveFileUrl(v.url)
<View key={v.id} className='pay-voucher'> return (
<Image <View key={v.id} className='pay-voucher'>
className='pay-voucher__img' <Image
src={url} className='pay-voucher__img'
mode='aspectFill' src={url}
onClick={() => previewImage(vouchers.map(x => resolveFileUrl(x.url)), url)} mode='aspectFill'
/> onClick={() => previewImage(vouchers.map(x => resolveFileUrl(x.url)), url)}
<View className='pay-voucher__del' onClick={() => handleRemoveVoucher(i)}> />
<Icon name='cross' size={12} color='#fff' /> <View className='pay-voucher__del' onClick={() => handleRemoveVoucher(i)}>
<Icon name='cross' size={12} color='#fff' />
</View>
</View> </View>
)
})}
{vouchers.length < MAX_VOUCHERS && (
<View className='pay-voucher pay-voucher--add' onClick={handleAddVoucher}>
<Icon name={uploading ? 'more' : 'plus'} size={24} color='#969799' />
<Text className='pay-voucher__add-text'>{uploading ? '上传中' : '上传凭证'}</Text>
</View> </View>
) )}
})} </View>
{vouchers.length < MAX_VOUCHERS && (
<View className='pay-voucher pay-voucher--add' onClick={handleAddVoucher}>
<Icon name={uploading ? 'more' : 'plus'} size={24} color='#969799' />
<Text className='pay-voucher__add-text'>{uploading ? '上传中' : '上传凭证'}</Text>
</View>
)}
</View> </View>
</View> )}
{/* ========== 备注 ========== */} {/* ========== 备注 ========== */}
<View className='pay-section'> <View className='pay-section'>
@@ -323,7 +572,7 @@ export default function PaymentPage() {
className='pay-remark' className='pay-remark'
value={remark} value={remark}
maxlength={255} maxlength={255}
placeholder='如:汇款人姓名、转账时间等' placeholder={isOnline ? '可填写付款说明' : '如:汇款人姓名、转账时间等'}
onInput={e => setRemark(e.detail.value)} onInput={e => setRemark(e.detail.value)}
/> />
</View> </View>
@@ -339,7 +588,7 @@ export default function PaymentPage() {
className={`pay-bar__btn ${selectedIds.length === 0 || submitting ? 'disabled' : ''}`} className={`pay-bar__btn ${selectedIds.length === 0 || submitting ? 'disabled' : ''}`}
onClick={handleSubmit} onClick={handleSubmit}
> >
{submitting ? '提交中...' : '提交付款'} {submitting ? (isOnline ? '支付中...' : '提交中...') : isOnline ? '立即支付' : '提交付款'}
</View> </View>
</View> </View>
)} )}
@@ -1,4 +1,4 @@
export default definePageConfig({ export default definePageConfig({
navigationStyle: 'custom', navigationStyle: 'custom',
navigationBarTitleText: '注册', navigationBarTitleText: '隐私政策',
}) })
+54
View File
@@ -0,0 +1,54 @@
/* ========================================
隐私政策页面(与用户协议共用样式)
======================================== */
.privacy-page {
min-height: 100vh;
background: #fff;
}
.privacy-scroll {
height: 100vh;
}
.privacy-content {
padding: 32px 40px 80px;
.doc-title {
display: block;
font-size: 40px;
font-weight: 600;
color: #323233;
text-align: center;
margin-bottom: 16px;
}
.doc-updated {
display: block;
font-size: 24px;
color: #969799;
text-align: center;
margin-bottom: 48px;
}
.doc-p {
display: block;
font-size: 28px;
color: #323233;
line-height: 1.8;
margin-bottom: 24px;
text-align: justify;
}
.doc-h2 {
display: block;
font-size: 32px;
font-weight: 600;
color: #323233;
margin: 48px 0 16px;
}
.doc-bold {
font-weight: 600;
}
}
+62
View File
@@ -0,0 +1,62 @@
import { View, Text, ScrollView } from '@tarojs/components'
import './index.less'
/**
* 隐私政策
* 静态政策文本页,由登录页/设置页进入
*/
export default function PrivacyPage() {
return (
<View className='privacy-page'>
<ScrollView scrollY className='privacy-scroll'>
<View className='privacy-content'>
<Text className='doc-title'></Text>
<Text className='doc-updated'>2026821 2026821</Text>
<Text className='doc-p'>
</Text>
<Text className='doc-p doc-bold'>
使使使
</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>使</Text>
<Text className='doc-p'>1.1 使</Text>
<Text className='doc-p'>1.2 使</Text>
<Text className='doc-p'>1.3 </Text>
<Text className='doc-p'>1.4 </Text>
<Text className='doc-h2'>使</Text>
<Text className='doc-p'>2.1 </Text>
<Text className='doc-p'>2.2 使</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>3.1 </Text>
<Text className='doc-p'>3.2 </Text>
<Text className='doc-p'>3.3 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>4.1 </Text>
<Text className='doc-p'>4.2 访访使</Text>
<Text className='doc-p'>4.3 </Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>5.1 </Text>
<Text className='doc-p'>5.2 --</Text>
<Text className='doc-p'>5.3 </Text>
<Text className='doc-p'>5.4 使使</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>使</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'>使使</Text>
<Text className='doc-h2'></Text>
<Text className='doc-p'></Text>
</View>
</ScrollView>
</View>
)
}
-6
View File
@@ -61,12 +61,6 @@
} }
} }
&__unit {
margin-left: 8rpx;
font-size: 24rpx;
color: #969799;
}
&__name { &__name {
display: block; display: block;
margin-top: 16rpx; margin-top: 16rpx;
+7 -3
View File
@@ -5,7 +5,7 @@ import { Empty, Stepper, Swiper, SwiperItem } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore' import useAuthStore from '@/stores/auth/useAuthStore'
import useCartStore from '@/stores/cart/useCartStore' import useCartStore from '@/stores/cart/useCartStore'
import { getProductDetailApi } from '@/services/product' import { getProductDetailApi } from '@/services/product'
import { resolveFileUrl } from '@/utils/format' import {formatRetailPrice, formatSpec, resolveFileUrl} from '@/utils/format'
import type { Product } from '@/types/product' import type { Product } from '@/types/product'
import './index.less' import './index.less'
@@ -121,10 +121,14 @@ export default function ProductDetailPage() {
{loggedIn ? '价格待定' : '登录后查看价格'} {loggedIn ? '价格待定' : '登录后查看价格'}
</Text> </Text>
)} )}
<Text className='goods-card__unit'>/{product.unit}</Text>
</View> </View>
<Text className='goods-card__name'>{product.name}</Text> <Text className='goods-card__name'>{product.name}</Text>
<Text className='goods-card__spec'>{product.spec}</Text> <Text className='goods-card__spec'>
{formatSpec(product.spec, product.unit)}{' '}
{product.price !== null && <>
{formatRetailPrice(product.price, product.spec)} {product.price_unit}
</>}
</Text>
<View className='goods-card__meta'> <View className='goods-card__meta'>
{!!product.shelf_life && product.shelf_life > 0 && ( {!!product.shelf_life && product.shelf_life > 0 && (
<Text className='goods-card__tag'> {product.shelf_life} </Text> <Text className='goods-card__tag'> {product.shelf_life} </Text>
+7 -7
View File
@@ -92,8 +92,9 @@
.product-main { .product-main {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
padding: 20rpx 20rpx 40rpx; height: 100%;
overflow-y: auto; // 底部留白避免最后一行被购物车悬浮球遮挡
padding: 20rpx 20rpx 20rpx;
box-sizing: border-box; box-sizing: border-box;
} }
@@ -110,8 +111,8 @@
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04); box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
&__image { &__image {
width: 160rpx; width: 180rpx;
height: 160rpx; height: 180rpx;
border-radius: 12rpx; border-radius: 12rpx;
background: #f2f3f5; background: #f2f3f5;
flex-shrink: 0; flex-shrink: 0;
@@ -135,7 +136,6 @@
} }
&__spec { &__spec {
margin-top: 10rpx;
font-size: 24rpx; font-size: 24rpx;
color: #969799; color: #969799;
} }
@@ -160,8 +160,8 @@
} }
&__add { &__add {
width: 56rpx; width: 42rpx;
height: 56rpx; height: 42rpx;
border-radius: 50%; border-radius: 50%;
background: #ee0a24; background: #ee0a24;
display: flex; display: flex;
+59 -92
View File
@@ -1,13 +1,17 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import Taro, { useDidShow, useReachBottom } from '@tarojs/taro' import Taro, { useDidShow } from '@tarojs/taro'
import { View, Text, Image, ScrollView } from '@tarojs/components' import { View, Text, Image, ScrollView } from '@tarojs/components'
import { Button, Empty, Popup, Search, Stepper } from '@antmjs/vantui' import { Empty, Search } from '@antmjs/vantui'
import useCartStore from '@/stores/cart/useCartStore' import useCartStore from '@/stores/cart/useCartStore'
import { getCategoriesApi, getProductListApi } from '@/services/product' import { getCategoriesApi, getProductListApi } from '@/services/product'
import type { ProductListParams } from '@/services/product' import type { ProductListParams } from '@/services/product'
import { getProductCover } from '@/types/product' import { getProductCover } from '@/types/product'
import type { Category, Product } from '@/types/product' import type { Category, Product, ProductCartPatch } from '@/types/product'
import CartBall from '@/components/CartBall'
import CartStepper from '@/components/CartStepper'
import {formatRetailPrice, formatSpec} from '@/utils/format'
import './index.less' import './index.less'
import CustomTabBar from "@/components/CustomTabBar";
const PAGE_SIZE = 10 const PAGE_SIZE = 10
/** 存储 key:首页点击分类/搜索跳转时经本地存储传参(switchTab 无法带参) */ /** 存储 key:首页点击分类/搜索跳转时经本地存储传参(switchTab 无法带参) */
@@ -16,6 +20,7 @@ const PENDING_KEYWORD_KEY = 'product_keyword'
export default function ProductPage() { export default function ProductPage() {
const addItem = useCartStore(s => s.addItem) const addItem = useCartStore(s => s.addItem)
const setSummary = useCartStore(s => s.setSummary)
/** 分类树 */ /** 分类树 */
const [categories, setCategories] = useState<Category[]>([]) const [categories, setCategories] = useState<Category[]>([])
@@ -38,12 +43,6 @@ export default function ProductPage() {
/** 是否有请求进行中(仅用于避免"加载更多"并发) */ /** 是否有请求进行中(仅用于避免"加载更多"并发) */
const loadingRef = useRef(false) const loadingRef = useRef(false)
/** 加购弹层 */
const [showPopup, setShowPopup] = useState(false)
const [current, setCurrent] = useState<Product | null>(null)
const [qty, setQty] = useState(1)
const addingRef = useRef(false)
/** 当前选中二级分类所属的一级分类ID(用于父级高亮) */ /** 当前选中二级分类所属的一级分类ID(用于父级高亮) */
const activeParentId = useMemo(() => { const activeParentId = useMemo(() => {
if (activeId == null) return null if (activeId == null) return null
@@ -68,10 +67,12 @@ export default function ProductPage() {
if (keyword) params.keyword = keyword if (keyword) params.keyword = keyword
const res = await getProductListApi(params) const res = await getProductListApi(params)
if (seq !== reqSeqRef.current) return // 已有更新的请求,丢弃本次响应 if (seq !== reqSeqRef.current) return // 已有更新的请求,丢弃本次响应
const { data, total: totalCount } = res.data const { data, total: totalCount, cart } = res.data
setProducts(prev => (reset ? data : [...prev, ...data])) setProducts(prev => (reset ? data : [...prev, ...data]))
setPage(pageNum) setPage(pageNum)
setFinished(pageNum * PAGE_SIZE >= totalCount) setFinished(pageNum * PAGE_SIZE >= totalCount)
// 列表响应附带悬浮球汇总(旧版本后端可能未返回)
if (cart) setSummary(cart)
} catch { } catch {
// 错误已由 request 层 toast // 错误已由 request 层 toast
} finally { } finally {
@@ -81,7 +82,7 @@ export default function ProductPage() {
} }
} }
}, },
[effectiveCategoryId, searchKey], [effectiveCategoryId, searchKey, setSummary],
) )
/** 分类/搜索词变化时重新加载第一页(首屏由 useDidShow 触发,跳过首次执行) */ /** 分类/搜索词变化时重新加载第一页(首屏由 useDidShow 触发,跳过首次执行) */
@@ -147,11 +148,12 @@ export default function ProductPage() {
fetchList(1, true, pendingKeyword ?? undefined) fetchList(1, true, pendingKeyword ?? undefined)
}) })
useReachBottom(() => { /** 右侧列表触底加载(页面为固定布局不滚动,由 ScrollView 触发) */
const handleLoadMore = useCallback(() => {
if (!finished) { if (!finished) {
fetchList(page + 1, false) fetchList(page + 1, false)
} }
}) }, [finished, page, fetchList])
/** 点击一级分类:有子分类仅展开/收起(不可选中),无子分类则选中 */ /** 点击一级分类:有子分类仅展开/收起(不可选中),无子分类则选中 */
const handleTopTap = useCallback((cat: Category) => { const handleTopTap = useCallback((cat: Category) => {
@@ -183,11 +185,9 @@ export default function ProductPage() {
setSearchKey('') setSearchKey('')
}, []) }, [])
/** 打开加购弹层 */ /** 行内加减购确认后回写列表项的购物车字段 */
const handleAddTap = useCallback((product: Product) => { const handleRowSync = useCallback((productId: number, patch: ProductCartPatch) => {
setCurrent(product) setProducts(prev => prev.map(p => (p.id === productId ? { ...p, ...patch } : p)))
setQty(1)
setShowPopup(true)
}, []) }, [])
/** 跳转商品详情 */ /** 跳转商品详情 */
@@ -195,20 +195,16 @@ export default function ProductPage() {
Taro.navigateTo({ url: `/pages/product-detail/index?id=${id}` }) Taro.navigateTo({ url: `/pages/product-detail/index?id=${id}` })
}, []) }, [])
/** 确认加购 */ /** 确认加购(用返回的购物车行回写列表项,行内随即展示加减器) */
const handleConfirmAdd = useCallback(async () => { const handleConfirmAdd = useCallback(async (product: Product) => {
if (!current || addingRef.current) return
addingRef.current = true
try { try {
await addItem(current.id, qty) const res = await addItem(product.id, 1)
Taro.showToast({ title: '已加入购物车', icon: 'success' }) handleRowSync(product.id, { cart_id: res.id, cart_quantity: res.quantity })
setShowPopup(false) // Taro.showToast({ title: '已加入购物车', icon: 'success' })
} catch { } catch {
// 错误(未设等级价/数量上限)已由 request 层 toast
} finally {
addingRef.current = false
} }
}, [current, qty, addItem]) }, [addItem, handleRowSync])
return ( return (
<View className='product-page'> <View className='product-page'>
@@ -272,8 +268,13 @@ export default function ProductPage() {
})} })}
</ScrollView> </ScrollView>
{/* ========== 右侧商品列表 ========== */} {/* ========== 右侧商品列表ScrollView 滚动 + 触底加载) ========== */}
<View className='product-main'> <ScrollView
scrollY
className='product-main'
lowerThreshold={80}
onScrollToLower={handleLoadMore}
>
{/* 商品列表 */} {/* 商品列表 */}
{products.length === 0 && !loading ? ( {products.length === 0 && !loading ? (
<Empty description='暂无商品' className='product-empty' /> <Empty description='暂无商品' className='product-empty' />
@@ -288,22 +289,34 @@ export default function ProductPage() {
/> />
<View className='product-item__info'> <View className='product-item__info'>
<Text className='product-item__name'>{product.name}</Text> <Text className='product-item__name'>{product.name}</Text>
<Text className='product-item__spec'>{product.spec} / {product.unit}</Text> <Text className='product-item__spec'>
{formatSpec(product.spec, product.unit)}{' '}
<View>
{product.price !== null && <>
{formatRetailPrice(product.price, product.spec)} {product.price_unit}
</>}
</View>
</Text>
<View className='product-item__bottom'> <View className='product-item__bottom'>
{product.price !== null ? ( {product.price !== null ? (
<Text className='product-item__price'>{product.price}</Text> <Text className='product-item__price'>{product.price}</Text>
) : ( ) : (
<Text className='product-item__price product-item__price--none'></Text> <Text className='product-item__price product-item__price--none'></Text>
)} )}
<View {/* 已加购展示行内加减器,否则展示加购按钮(点击开弹层选数量) */}
className='product-item__add' {Number(product.cart_quantity ?? 0) > 0 ? (
onClick={e => { <CartStepper product={product} onSync={handleRowSync} />
e.stopPropagation() ) : (
handleAddTap(product) <View
}} className='product-item__add'
> onClick={e => {
<Text className='product-item__add-icon'></Text> e.stopPropagation()
</View> handleConfirmAdd(product)
}}
>
<Text className='product-item__add-icon'></Text>
</View>
)}
</View> </View>
</View> </View>
</View> </View>
@@ -315,59 +328,13 @@ export default function ProductPage() {
{finished && products.length > 0 && ( {finished && products.length > 0 && (
<View className='product-loading'><Text></Text></View> <View className='product-loading'><Text></Text></View>
)} )}
</View> <View style={{ height: 68 }}></View>
</ScrollView>
</View> </View>
{/* ========== 加购弹层 ========== */} {/* ========== 购物车悬浮球 ========== */}
<Popup <CartBall />
show={showPopup} {process.env.TARO_ENV === 'h5' && <CustomTabBar />}
position='bottom'
round
closeable
closeOnClickOverlay
safeAreaInsetBottom
style={{ paddingBottom: '110px' }}
onClose={() => setShowPopup(false)}
>
{current && (
<View className='add-popup'>
<View className='add-popup__product'>
<Image
className='add-popup__image'
src={getProductCover(current) || 'https://img.yzcdn.cn/vant/cat.jpeg'}
mode='aspectFill'
/>
<View className='add-popup__info'>
<Text className='add-popup__name'>{current.name}</Text>
<Text className='add-popup__spec'>{current.spec} / {current.unit}</Text>
{current.price !== null ? (
<Text className='add-popup__price'>{current.price}</Text>
) : (
<Text className='add-popup__price add-popup__price--none'></Text>
)}
</View>
</View>
<View className='add-popup__row'>
<Text className='add-popup__label'></Text>
<Stepper
value={qty}
min={1}
max={99999999.99}
onChange={e => setQty(Number(e.detail))}
/>
</View>
<Button
type='danger'
block
round
className='add-popup__submit'
onClick={handleConfirmAdd}
>
</Button>
</View>
)}
</Popup>
</View> </View>
) )
} }
+47
View File
@@ -144,6 +144,53 @@
} }
} }
// ===== 运营报表入口 =====
.report-entry {
margin-top: 12rpx;
border-top: 1rpx solid #f2f3f5;
padding-top: 20rpx;
display: flex;
align-items: center;
&__icon {
width: 84rpx;
height: 84rpx;
border-radius: 24rpx;
background: #fff0f0;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
&__info {
flex: 1;
min-width: 0;
margin-left: 20rpx;
display: flex;
flex-direction: column;
}
&__title {
font-size: 28rpx;
color: #323233;
}
&__desc {
margin-top: 6rpx;
font-size: 22rpx;
color: #969799;
}
&__arrow {
font-size: 32rpx;
color: #c8c9cc;
line-height: 1;
margin-left: 12rpx;
flex-shrink: 0;
}
}
// ===== 账单入口 ===== // ===== 账单入口 =====
.bill-entry { .bill-entry {
display: flex; display: flex;
+34 -28
View File
@@ -8,8 +8,8 @@ import { getBillListApi } from '@/services/bill'
import type { BillSummary } from '@/services/bill' import type { BillSummary } from '@/services/bill'
import { ORDER_NAV_ITEMS } from '@/types/order' import { ORDER_NAV_ITEMS } from '@/types/order'
import { resolveAvatarUrl } from '@/utils/format' import { resolveAvatarUrl } from '@/utils/format'
import type { UserType } from '@/types/user'
import './index.less' import './index.less'
import CustomTabBar from "@/components/CustomTabBar";
/** 菜单项(订单/账单入口已由上方专区承载,后续单独页面开发时在此追加) */ /** 菜单项(订单/账单入口已由上方专区承载,后续单独页面开发时在此追加) */
const MENU_ITEMS = [ const MENU_ITEMS = [
@@ -38,9 +38,9 @@ export default function ProfilePage() {
const loggedIn = !!token && !!user const loggedIn = !!token && !!user
/** 功能菜单(门店账号追加「门店信息」「支付记录」入口 */ /** 功能菜单(登录门店可用:门店信息 / 支付记录 / 修改密码 */
const menuItems = useMemo(() => { const menuItems = useMemo(() => {
if (!user?.store) return MENU_ITEMS if (!loggedIn) return MENU_ITEMS
return [ return [
{ {
key: 'store-info', key: 'store-info',
@@ -54,9 +54,15 @@ export default function ProfilePage() {
icon: 'balance-o', icon: 'balance-o',
onClick: () => Taro.navigateTo({ url: '/pages/payment-records/index' }), onClick: () => Taro.navigateTo({ url: '/pages/payment-records/index' }),
}, },
{
key: 'change-password',
label: '修改密码',
icon: 'lock',
onClick: () => Taro.navigateTo({ url: '/pages/change-password/index' }),
},
...MENU_ITEMS, ...MENU_ITEMS,
] ]
}, [user?.store]) }, [loggedIn])
useDidShow(() => { useDidShow(() => {
if (!loggedIn) return if (!loggedIn) return
@@ -70,18 +76,16 @@ export default function ProfilePage() {
.catch(() => {}) .catch(() => {})
}) })
/** 身份标签 */
const getTypeLabel = useCallback((type: UserType): string => {
if (type === 1) return '门店'
if (type === 2) return '供应商'
return '待绑定'
}, [])
/** 订单总汇 → 订单列表页(按状态) */ /** 订单总汇 → 订单列表页(按状态) */
const handleOrderNav = useCallback((status?: number) => { const handleOrderNav = useCallback((status?: number) => {
Taro.navigateTo({ url: `/pages/order-list/index?status=${status ?? 'all'}` }) Taro.navigateTo({ url: `/pages/order-list/index?status=${status ?? 'all'}` })
}, []) }, [])
/** 运营报表入口 → 运营报表页 */
const goReport = useCallback(() => {
Taro.navigateTo({ url: '/pages/report/index' })
}, [])
/** 账单入口 → 账单列表页 */ /** 账单入口 → 账单列表页 */
const goBill = useCallback(() => { const goBill = useCallback(() => {
Taro.navigateTo({ url: '/pages/bill/index' }) Taro.navigateTo({ url: '/pages/bill/index' })
@@ -130,29 +134,18 @@ export default function ProfilePage() {
/> />
) : ( ) : (
<View className='profile-card__avatar profile-card__avatar--text'> <View className='profile-card__avatar profile-card__avatar--text'>
{user?.nickname?.[0] || ''} {user?.name?.[0] || ''}
</View> </View>
)} )}
<View className='profile-card__info'> <View className='profile-card__info'>
<Text className='profile-card__name'>{user?.nickname}</Text> <Text className='profile-card__name'>{user?.name}</Text>
<Text className='profile-card__desc'>{user?.phone || '未绑定手机号'}</Text> <Text className='profile-card__desc'>{user?.phone || '未设置联系电话'}</Text>
</View> </View>
{user?.type === 0 && (
<View className='profile-card__btn' onClick={goLogin}></View>
)}
</View> </View>
<View className='profile-card__identity'> <View className='profile-card__identity'>
{user?.store ? ( <Text className='profile-card__tag'> · {user?.code}</Text>
<> {user?.level && (
<Text className='profile-card__tag'> · {user.store.name}</Text> <Text className='profile-card__tag profile-card__tag--level'>{user.level.name}</Text>
{user.store.level && (
<Text className='profile-card__tag profile-card__tag--level'>{user.store.level.name}</Text>
)}
</>
) : user?.supplier ? (
<Text className='profile-card__tag'> · {user.supplier.name}</Text>
) : (
<Text className='profile-card__tag'>{getTypeLabel(user?.type ?? 0)}</Text>
)} )}
</View> </View>
</> </>
@@ -175,6 +168,17 @@ export default function ProfilePage() {
</View> </View>
))} ))}
</View> </View>
{/* 运营报表入口 */}
<View className='report-entry' onClick={goReport}>
<View className='report-entry__icon'>
<Icon name='bar-chart-o' size={28} color='#ee0a24' />
</View>
<View className='report-entry__info'>
<Text className='report-entry__title'></Text>
<Text className='report-entry__desc'>/</Text>
</View>
<Text className='report-entry__arrow'></Text>
</View>
</View> </View>
{/* ========== 我的账单 ========== */} {/* ========== 我的账单 ========== */}
@@ -226,6 +230,8 @@ export default function ProfilePage() {
<Text>退</Text> <Text>退</Text>
</View> </View>
)} )}
{process.env.TARO_ENV === 'h5' && <CustomTabBar />}
</View> </View>
) )
} }
-196
View File
@@ -1,196 +0,0 @@
/* ========================================
注册页面
======================================== */
.register-page {
min-height: 100vh;
background: #fff;
}
/* ========== 内容区域 ========== */
.register-content {
display: flex;
flex-direction: column;
align-items: center;
padding: 80px 60px 0;
}
/* ========== 品牌区域 ========== */
.register-brand {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 60px;
.logo-wrapper {
width: 160px;
height: 160px;
border-radius: 50%;
background: linear-gradient(160deg, #ee0a24 0%, #ff4d4f 100%);
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 24px;
box-shadow: 0 8px 32px rgba(238, 10, 36, 0.3);
}
.logo-text {
font-size: 80px;
color: #fff;
font-weight: 700;
}
.app-name {
font-size: 44px;
font-weight: 600;
color: #323233;
margin-bottom: 12px;
}
.app-slogan {
font-size: 28px;
color: #969799;
}
}
/* ========== 注册表单 ========== */
.register-form {
width: 100%;
background: #f7f8fa;
border-radius: 24px;
padding: 0 32px;
margin-bottom: 80px;
}
.form-item {
display: flex;
align-items: center;
height: 112px;
border-bottom: 1px solid #ebedf0;
&:last-child {
border-bottom: none;
}
}
.form-label {
width: 160px;
font-size: 30px;
color: #323233;
flex-shrink: 0;
}
.form-input {
flex: 1;
height: 100%;
font-size: 30px;
color: #323233;
}
.form-input-placeholder {
color: #c8c9cc;
}
/* 手机号已授权状态 */
.form-phone-ok {
flex: 1;
display: flex;
align-items: center;
.form-phone-ok__text {
font-size: 30px;
color: #07c160;
}
}
/* 手机号授权按钮(微信原生 Button 需重置样式) */
.phone-auth-btn {
flex: 1;
height: 64px;
line-height: 64px;
background: #fff0f0;
color: #ee0a24;
font-size: 28px;
font-weight: 500;
border: none;
border-radius: 32px;
text-align: center;
padding: 0 32px;
/* 重置微信 Button 默认样式 */
&::after {
border: none;
}
}
/* ========== 注册操作区 ========== */
.register-actions {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.register-btn {
width: 100%;
height: 96px;
line-height: 96px;
background: linear-gradient(160deg, #ee0a24 0%, #ff4d4f 100%);
color: #fff;
font-size: 34px;
font-weight: 500;
border: none;
border-radius: 48px;
text-align: center;
padding: 0;
box-shadow: 0 6px 24px rgba(238, 10, 36, 0.35);
transition: opacity 0.2s;
/* 重置微信 Button 默认样式 */
&::after {
border: none;
}
}
.register-btn--loading {
opacity: 0.75;
}
/* ========== 去登录入口 ========== */
.register-switch {
display: flex;
align-items: center;
justify-content: center;
margin-top: 32px;
.switch-text {
font-size: 28px;
color: #969799;
}
.switch-link {
font-size: 28px;
color: #ee0a24;
margin-left: 8px;
}
}
/* ========== 协议文字 ========== */
.register-agreement {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
margin-top: 32px;
line-height: 1.6;
.agree-text {
font-size: 24px;
color: #c8c9cc;
}
.agree-link {
font-size: 24px;
color: #ee0a24;
}
}
-222
View File
@@ -1,222 +0,0 @@
import { useCallback, useEffect, useState } from 'react'
import Taro from '@tarojs/taro'
import { View, Text, Button, Input } from '@tarojs/components'
import CustomNavBar from '@/components/NavBar'
import useAuthStore from '@/stores/auth/useAuthStore'
import './index.less'
export default function RegisterPage() {
const register = useAuthStore(s => s.register)
const isLoggedIn = useAuthStore(s => !!s.token && !!s.user)
/** 门店编码(后台门店管理维护) */
const [storeCode, setStoreCode] = useState('')
/** 微信手机号授权得到的 code */
const [phoneCode, setPhoneCode] = useState('')
const [submitting, setSubmitting] = useState(false)
const isWeb = Taro.getEnv() === Taro.ENV_TYPE.WEB
/** 返回上一页(无页面栈时回首页) */
const goBack = useCallback(() => {
const pages = Taro.getCurrentPages()
if (pages.length > 1) {
Taro.navigateBack()
} else {
Taro.switchTab({ url: '/pages/index/index' })
}
}, [])
/** 前往登录页 */
const goLogin = useCallback(() => {
const pages = Taro.getCurrentPages()
if (pages.length > 1) {
Taro.navigateBack()
} else {
Taro.navigateTo({ url: '/pages/login/index' })
}
}, [])
/** 已注册成功(登录态就绪)→ 自动返回 */
useEffect(() => {
if (isLoggedIn) goBack()
}, [isLoggedIn, goBack])
/** 发起注册:wx.login 换 code → POST /mini/auth/register */
const doRegister = useCallback(
async (phoneCodeValue: string) => {
if (submitting) return
if (isWeb) {
Taro.showToast({ title: '请在微信小程序中注册', icon: 'none' })
return
}
const code = storeCode.trim()
if (!code) {
Taro.showToast({ title: '请填写门店编码', icon: 'none' })
return
}
setSubmitting(true)
try {
const res = await Taro.login()
if (!res.code) {
Taro.showToast({ title: '获取登录凭证失败', icon: 'none' })
return
}
await register({ code: res.code, phoneCode: phoneCodeValue, storeCode: code })
// 注册成功后由 effect 自动返回
} catch (e: any) {
// 该微信已注册:引导前往登录(其余错误已由 request 层提示)
if (typeof e?.msg === 'string' && e.msg.includes('已经注册')) {
Taro.showModal({
title: '提示',
content: '该微信已经注册,请直接登录',
confirmText: '去登录',
cancelText: '取消',
success: res => {
if (res.confirm) goLogin()
},
})
}
} finally {
setSubmitting(false)
}
},
[register, submitting, isWeb, storeCode, goLogin],
)
/** 微信手机号授权(openType getPhoneNumber */
const handleGetPhoneNumber = useCallback(
(e: any) => {
if (isWeb) {
Taro.showToast({ title: '请在微信小程序中授权手机号', icon: 'none' })
return
}
const detail = e.detail || {}
// 用户拒绝授权
if (detail.errMsg && !detail.errMsg.includes(':ok')) {
Taro.showToast({ title: '需要授权手机号才能注册', icon: 'none' })
return
}
if (!detail.code) {
Taro.showToast({ title: '未获取到手机号授权凭证', icon: 'none' })
return
}
setPhoneCode(detail.code)
if (storeCode.trim()) {
// 门店编码已填 → 直接发起注册
doRegister(detail.code)
} else {
Taro.showToast({ title: '手机号已授权,请填写门店编码', icon: 'none' })
}
},
[isWeb, storeCode, doRegister],
)
/** 点击注册按钮(门店编码已填 + 手机号已授权) */
const handleSubmit = useCallback(() => {
if (!phoneCode) {
Taro.showToast({ title: '请先授权手机号', icon: 'none' })
return
}
if (!storeCode.trim()) {
Taro.showToast({ title: '请填写门店编码', icon: 'none' })
return
}
doRegister(phoneCode)
}, [phoneCode, storeCode, doRegister])
/** 查看用户协议 */
const handleShowAgreement = useCallback(() => {
Taro.showToast({ title: '用户协议即将上线', icon: 'none' })
}, [])
/** 查看隐私政策 */
const handleShowPrivacy = useCallback(() => {
Taro.showToast({ title: '隐私政策即将上线', icon: 'none' })
}, [])
return (
<View className='register-page'>
{/* ========== 导航栏 ========== */}
<CustomNavBar title='注册' />
{/* ========== 内容区域 ========== */}
<View className='register-content'>
{/* 品牌区域 */}
<View className='register-brand'>
<View className='logo-wrapper'>
<Text className='logo-text'></Text>
</View>
<Text className='app-name'></Text>
<Text className='app-slogan'></Text>
</View>
{/* 注册表单 */}
<View className='register-form'>
{/* 门店编码 */}
<View className='form-item'>
<Text className='form-label'></Text>
<Input
className='form-input'
type='text'
value={storeCode}
placeholder='请输入门店编码(门店管理员提供)'
placeholderClass='form-input-placeholder'
onInput={e => setStoreCode(e.detail.value)}
/>
</View>
{/* 手机号授权 */}
<View className='form-item'>
<Text className='form-label'></Text>
{phoneCode ? (
<View className='form-phone-ok'>
<Text className='form-phone-ok__text'></Text>
</View>
) : (
<Button
className='phone-auth-btn'
openType='getPhoneNumber'
onGetPhoneNumber={handleGetPhoneNumber}
>
</Button>
)}
</View>
</View>
{/* 注册操作 */}
<View className='register-actions'>
<Button
className={`register-btn ${submitting ? 'register-btn--loading' : ''}`}
onClick={handleSubmit}
loading={submitting}
disabled={submitting}
>
{submitting ? '注册中...' : '注 册'}
</Button>
{/* 已注册用户入口 */}
<View className='register-switch' onClick={goLogin}>
<Text className='switch-text'></Text>
<Text className='switch-link'></Text>
</View>
<View className='register-agreement'>
<Text className='agree-text'></Text>
<Text className='agree-link' onClick={handleShowAgreement}>
</Text>
<Text className='agree-text'></Text>
<Text className='agree-link' onClick={handleShowPrivacy}>
</Text>
</View>
</View>
</View>
</View>
)
}
+3
View File
@@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '运营报表',
})
+222
View File
@@ -0,0 +1,222 @@
.report-page {
min-height: 100vh;
background: #f7f8fa;
padding: 20rpx 24rpx 60rpx;
box-sizing: border-box;
// ===== 周期切换 =====
.period-bar {
display: flex;
gap: 16rpx;
}
.period-chip {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 14rpx 0;
border-radius: 999rpx;
background: #fff;
font-size: 26rpx;
color: #323233;
&.active {
background: #ee0a24;
color: #fff;
font-weight: 600;
}
}
// ===== 汇总卡片 =====
.report-summary {
margin-top: 20rpx;
background: linear-gradient(135deg, #ee0a24, #ff4d4f);
border-radius: 20rpx;
padding: 32rpx 28rpx;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
&__label {
font-size: 24rpx;
opacity: 0.85;
}
&__amount {
margin-top: 12rpx;
font-size: 56rpx;
font-weight: 700;
line-height: 1.2;
}
&__range {
margin-top: 12rpx;
font-size: 22rpx;
opacity: 0.85;
}
&__meta {
margin-top: 28rpx;
width: 100%;
display: flex;
border-top: 1rpx solid rgba(255, 255, 255, 0.25);
padding-top: 24rpx;
}
&__meta-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
&__meta-value {
font-size: 34rpx;
font-weight: 600;
}
&__meta-label {
margin-top: 6rpx;
font-size: 22rpx;
opacity: 0.85;
}
}
// ===== 单品排行 =====
.report-list {
margin-top: 20rpx;
background: #fff;
border-radius: 20rpx;
padding: 24rpx 28rpx 8rpx;
&__header {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8rpx;
}
&__title {
font-size: 30rpx;
font-weight: 600;
}
&__desc {
font-size: 22rpx;
color: #969799;
}
}
.report-item {
display: flex;
padding: 24rpx 0;
border-bottom: 1rpx solid #f2f3f5;
&:last-child {
border-bottom: none;
}
&__rank {
width: 44rpx;
height: 44rpx;
border-radius: 12rpx;
background: #f2f3f5;
color: #969799;
font-size: 24rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-top: 4rpx;
&--top {
background: #fff0f0;
color: #ee0a24;
font-weight: 600;
}
}
&__main {
flex: 1;
min-width: 0;
margin-left: 20rpx;
}
&__row {
display: flex;
align-items: center;
justify-content: space-between;
}
&__name {
font-size: 28rpx;
color: #323233;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__amount {
font-size: 30rpx;
color: #ee0a24;
font-weight: 600;
margin-left: 16rpx;
flex-shrink: 0;
}
&__spec {
margin-top: 8rpx;
font-size: 22rpx;
color: #969799;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&__percent {
margin-top: 8rpx;
font-size: 24rpx;
color: #323233;
margin-left: 16rpx;
flex-shrink: 0;
}
&__bar {
margin-top: 14rpx;
height: 8rpx;
border-radius: 999rpx;
background: #f2f3f5;
overflow: hidden;
}
&__bar-inner {
height: 100%;
border-radius: 999rpx;
background: linear-gradient(90deg, #ff8a8f, #ee0a24);
}
}
// ===== 空态 / 加载中 =====
.report-empty {
margin-top: 60rpx;
&__btn {
margin-top: 20rpx;
font-size: 26rpx;
padding: 14rpx 48rpx;
border-radius: 999rpx;
background: #ee0a24;
color: #fff;
}
}
.report-loading {
padding: 60rpx 0;
text-align: center;
font-size: 26rpx;
color: #969799;
}
}
+225
View File
@@ -0,0 +1,225 @@
import { useCallback, useRef, useState } from 'react'
import Taro, { useDidShow } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { Calendar, Empty } from '@antmjs/vantui'
import useAuthStore from '@/stores/auth/useAuthStore'
import { getPurchaseReportApi } from '@/services/report'
import type { PurchaseReport, PurchaseReportParams, ReportPreset } from '@/services/report'
import './index.less'
/** 周期选项 key(custom 为前端伪预设:选中自定义区间后生效) */
type PeriodKey = ReportPreset
/** 周期切换 chips */
const PERIOD_TABS: Array<{ key: PeriodKey; label: string }> = [
{ key: 'week', label: '本周' },
{ key: 'last_week', label: '上周' },
{ key: 'month', label: '本月' },
{ key: 'last_month', label: '上月' },
{ key: 'custom', label: '自定义' },
]
/** 自定义区间可选范围:2020-01-01 ~ 今天(进行中的周期由后端封顶今天) */
const MIN_DATE = new Date(2020, 0, 1).getTime()
const MAX_DATE = Date.now()
/** Date → Y-m-d */
function formatDate(d: Date): string {
const m = `${d.getMonth() + 1}`.padStart(2, '0')
const day = `${d.getDate()}`.padStart(2, '0')
return `${d.getFullYear()}-${m}-${day}`
}
/**
* 运营报表页
* 按周期(本周/上周/本月/上月/自定义区间)统计门店采购总金额与单品累计金额占比;
* 数据为下单快照口径,已取消/已删除订单不计入
*/
export default function ReportPage() {
const token = useAuthStore(s => s.token)
const [period, setPeriod] = useState<PeriodKey>('month')
/** 自定义区间(period=custom 时使用) */
const [range, setRange] = useState<{ start: string; end: string } | null>(null)
const [report, setReport] = useState<PurchaseReport | null>(null)
const [loading, setLoading] = useState(false)
const [showCalendar, setShowCalendar] = useState(false)
const loadingRef = useRef(false)
const loggedIn = !!token
/** 拉取报表 */
const load = useCallback(
async (params: PurchaseReportParams) => {
if (!loggedIn || loadingRef.current) return
loadingRef.current = true
setLoading(true)
try {
const res = await getPurchaseReportApi(params)
setReport(res.data)
} catch {
// 错误已由 request 层 toast
} finally {
loadingRef.current = false
setLoading(false)
}
},
[loggedIn],
)
useDidShow(() => {
load(
period === 'custom' && range
? { start_date: range.start, end_date: range.end }
: { preset: period === 'custom' ? 'month' : period },
)
})
/** 切换周期;自定义打开日历选择区间 */
const handlePeriodTap = useCallback(
(key: PeriodKey) => {
if (key === 'custom') {
setShowCalendar(true)
return
}
if (key === period) return
setPeriod(key)
load({ preset: key })
},
[period, load],
)
/** 日历确认区间 → 自定义区间查询(优先于 preset) */
const handleCalendarConfirm = useCallback(
(e: { detail: { value: Date | Date[] } }) => {
const value = Array.isArray(e.detail.value) ? e.detail.value : [e.detail.value]
const [start, end] = value
if (!start || !end) return
const next = { start: formatDate(start), end: formatDate(end) }
setRange(next)
setPeriod('custom')
setShowCalendar(false)
load({ start_date: next.start, end_date: next.end })
},
[load],
)
const goLogin = useCallback(() => {
Taro.navigateTo({ url: '/pages/login/index' })
}, [])
return (
<View className='report-page'>
{/* ========== 周期切换 ========== */}
<View className='period-bar'>
{PERIOD_TABS.map(tab => (
<View
key={tab.key}
className={`period-chip ${period === tab.key ? 'active' : ''}`}
onClick={() => handlePeriodTap(tab.key)}
>
<Text>{tab.label}</Text>
</View>
))}
</View>
{!loggedIn ? (
<Empty description='登录后查看运营报表' className='report-empty'>
<View className='report-empty__btn' onClick={goLogin}></View>
</Empty>
) : (
<>
{/* ========== 汇总卡片 ========== */}
{report && (
<View className='report-summary'>
<Text className='report-summary__label'></Text>
<Text className='report-summary__amount'>{report.total_amount}</Text>
<Text className='report-summary__range'>
{report.start_date} ~ {report.end_date}
</Text>
<View className='report-summary__meta'>
<View className='report-summary__meta-item'>
<Text className='report-summary__meta-value'>{report.order_count}</Text>
<Text className='report-summary__meta-label'></Text>
</View>
<View className='report-summary__meta-item'>
<Text className='report-summary__meta-value'>{report.item_count}</Text>
<Text className='report-summary__meta-label'></Text>
</View>
<View className='report-summary__meta-item'>
<Text className='report-summary__meta-value'>{report.total_quantity}</Text>
<Text className='report-summary__meta-label'></Text>
</View>
</View>
</View>
)}
{/* ========== 单品排行 ========== */}
{report && report.items.length > 0 && (
<View className='report-list'>
<View className='report-list__header'>
<Text className='report-list__title'></Text>
<Text className='report-list__desc'> {report.item_count} </Text>
</View>
{report.items.map((item, index) => (
<View key={item.product_id} className='report-item'>
<View className={`report-item__rank ${index < 3 ? 'report-item__rank--top' : ''}`}>
{index + 1}
</View>
<View className='report-item__main'>
<View className='report-item__row'>
<Text className='report-item__name'>{item.product_name}</Text>
<Text className='report-item__amount'>{item.amount}</Text>
</View>
<View className='report-item__row'>
<Text className='report-item__spec'>
{item.product_spec ? `${item.product_spec}` : ''}{item.unit}
</Text>
</View>
<View className='report-item__row'>
<Text className='report-item__spec'>
{item.quantity}
{parseFloat(item.weight) > 0 ? ` · 重量 ${item.weight}` : ''}
</Text>
<Text className='report-item__percent'>{item.percent}%</Text>
</View>
<View className='report-item__bar'>
<View
className='report-item__bar-inner'
style={{ width: `${Math.min(Math.max(item.percent, 0), 100)}%` }}
/>
</View>
</View>
</View>
))}
</View>
)}
{/* ========== 空态 / 加载中 ========== */}
{(!report || report.items.length === 0) && (
loading ? (
<View className='report-loading'><Text>...</Text></View>
) : (
<Empty description='该时间段暂无采购数据' className='report-empty' />
)
)}
</>
)}
{/* ========== 自定义区间日历 ========== */}
<Calendar
show={showCalendar}
type='range'
allowSameDay
firstDayOfWeek={1}
minDate={MIN_DATE}
maxDate={MAX_DATE}
color='#ee0a24'
title='选择统计区间'
defaultDate={range ? [new Date(range.start).getTime(), new Date(range.end).getTime()] : undefined}
onClose={() => setShowCalendar(false)}
onConfirm={handleCalendarConfirm}
/>
</View>
)
}
+3 -3
View File
@@ -21,11 +21,11 @@ export default function SettingsPage() {
<Text className='setting-cell__label'></Text> <Text className='setting-cell__label'></Text>
<Text className='setting-cell__value'></Text> <Text className='setting-cell__value'></Text>
</View> </View>
<View className='setting-cell' onClick={() => handlePlaceholder('用户协议')}> <View className='setting-cell' onClick={() => Taro.navigateTo({ url: '/pages/agreement/index' })}>
<Text className='setting-cell__label'></Text> <Text className='setting-cell__label'></Text>
<Text className='setting-cell__value'></Text> <Text className='setting-cell__value'></Text>
</View> </View>
<View className='setting-cell' onClick={() => handlePlaceholder('隐私政策')}> <View className='setting-cell' onClick={() => Taro.navigateTo({ url: '/pages/privacy/index' })}>
<Text className='setting-cell__label'></Text> <Text className='setting-cell__label'></Text>
<Text className='setting-cell__value'></Text> <Text className='setting-cell__value'></Text>
</View> </View>
+27 -24
View File
@@ -1,39 +1,42 @@
import { get, post } from '@/utils/request' import { get, post, put } from '@/utils/request'
import type { User } from '@/types/user' import type { User } from '@/types/user'
/** 微信登录参数 */ /** 账号密码登录参数 */
export interface WxLoginParams { export interface LoginParams {
/** wx.login 的临时凭证 */ /** 登录账号(商家后台分配,4~20 位) */
code: string username: string
/** 登录密码 */
password: string
} }
/** 微信注册参数 */ /** 登录返回 */
export interface RegisterParams {
/** wx.login 的临时凭证 */
code: string
/** wx.getPhoneNumber 授权得到的 code */
phoneCode: string
/** 门店编码(后台门店管理维护) */
storeCode: string
}
/** 登录 / 注册返回 */
export interface AuthResult { export interface AuthResult {
token: string token: string
/** 门店即用户(扁平结构) */
user: User user: User
} }
/** 微信登录(仅已注册用户可登录):POST /mini/auth/login */ /** 修改密码参数 */
export function wxLoginApi(params: WxLoginParams) { export interface ChangePasswordParams {
/** 原密码 */
oldPassword: string
/** 新密码(6~20 位) */
newPassword: string
/** 确认新密码(须与 newPassword 一致) */
rePassword: string
}
/** 账号密码登录:POST /mini/auth/login */
export function loginApi(params: LoginParams) {
return post<AuthResult>('/mini/auth/login', params) return post<AuthResult>('/mini/auth/login', params)
} }
/** 微信注册(code 换 openid + phoneCode 换手机号 + storeCode 绑定门店):POST /mini/auth/register */ /** 当前门店信息(含客户等级):GET /mini/auth/info */
export function registerApi(params: RegisterParams) {
return post<AuthResult>('/mini/auth/register', params)
}
/** 当前用户信息(含门店客户等级):GET /mini/auth/info */
export function getUserInfoApi() { export function getUserInfoApi() {
return get<User>('/mini/auth/info') return get<User>('/mini/auth/info')
} }
/** 修改密码(成功后现有 token 仍有效):PUT /mini/auth/password */
export function changePasswordApi(params: ChangePasswordParams) {
return put<null>('/mini/auth/password', params)
}
+4
View File
@@ -44,6 +44,8 @@ export interface Bill {
settlement_date: string settlement_date: string
/** 付款时间(已支付时非空) */ /** 付款时间(已支付时非空) */
paid_at: string | null paid_at: string | null
/** 售后金额 */
after_sale: string
/** 付款备注 */ /** 付款备注 */
pay_remark: string pay_remark: string
/** 账单备注 */ /** 账单备注 */
@@ -72,6 +74,8 @@ export interface BillItem {
amount: string amount: string
/** 商品首图 URL(无图为空字符串) */ /** 商品首图 URL(无图为空字符串) */
image: string image: string
price_unit: string
spec: string
} }
/** 账单关联订单 */ /** 账单关联订单 */
+6 -1
View File
@@ -1,5 +1,5 @@
import { del, get, post, put } from '@/utils/request' import { del, get, post, put } from '@/utils/request'
import type { CartData } from '@/types/cart' import type { CartData, CartSummary } from '@/types/cart'
/** 加购 / 改数量返回 */ /** 加购 / 改数量返回 */
export interface CartMutationResult { export interface CartMutationResult {
@@ -17,6 +17,11 @@ export function getCartApi() {
return get<CartData>('/mini/cart') return get<CartData>('/mini/cart')
} }
/** 轻量汇总(悬浮球单独刷新用;必须登录,未登录 401):GET /mini/cart/summary */
export function getCartSummaryApi() {
return get<CartSummary>('/mini/cart/summary')
}
/** 修改数量:PUT /mini/cart/{id} */ /** 修改数量:PUT /mini/cart/{id} */
export function updateCartItemApi(id: number, quantity: number) { export function updateCartItemApi(id: number, quantity: number) {
return put<CartMutationResult>(`/mini/cart/${id}`, { quantity }) return put<CartMutationResult>(`/mini/cart/${id}`, { quantity })
+3
View File
@@ -1,4 +1,5 @@
import { get } from '@/utils/request' import { get } from '@/utils/request'
import type { CartSummary } from '@/types/cart'
/** 首页轮播图项 */ /** 首页轮播图项 */
export interface HomeBanner { export interface HomeBanner {
@@ -36,6 +37,8 @@ export interface HomeConfig {
banners: HomeBanner[] banners: HomeBanner[]
navs: HomeNav[] navs: HomeNav[]
promos: HomePromo[] promos: HomePromo[]
/** 购物车悬浮球汇总(未登录返回零值结构;旧版本后端可能未返回,调用方判空) */
cart?: CartSummary
} }
/** 首页配置(轮播图 + 宫格导航 + 促销卡片):GET /mini/home */ /** 首页配置(轮播图 + 宫格导航 + 促销卡片):GET /mini/home */
+82 -6
View File
@@ -1,16 +1,20 @@
import { get, post } from '@/utils/request' import { get, post } from '@/utils/request'
import type { PaginatedData } from '@/types/api' import type { PaginatedData } from '@/types/api'
/** 支付方式:1 微信 / 2 支付宝 / 3 对公汇款 */ /** 支付方式:1 微信 / 2 支付宝 / 3 对公汇款 / 4 旺铺支付(小程序在线支付) */
export type PayMethod = 1 | 2 | 3 export type PayMethod = 1 | 2 | 3 | 4
export const PAY_METHOD_NAMES: Record<PayMethod, string> = { export const PAY_METHOD_NAMES: Record<PayMethod, string> = {
1: '微信支付', 1: '微信支付',
2: '支付宝', 2: '支付宝',
3: '对公汇款', 3: '对公汇款',
4: '微信在线支付',
} }
/** 支付状态:0 待审核 / 1 已通过 / 2 已拒绝 */ /** 支付类型:1 线下凭证支付 / 2 在线支付(旧数据可能缺省,缺省按线下处理) */
export type PayType = 1 | 2
/** 支付状态:0 待审核 / 1 已通过 / 2 已拒绝(线下凭证支付单语义) */
export type PayStatus = 0 | 1 | 2 export type PayStatus = 0 | 1 | 2
export const PAY_STATUS_NAMES: Record<PayStatus, string> = { export const PAY_STATUS_NAMES: Record<PayStatus, string> = {
@@ -19,11 +23,27 @@ export const PAY_STATUS_NAMES: Record<PayStatus, string> = {
2: '已拒绝', 2: '已拒绝',
} }
/** 在线支付状态:0 待支付 / 1 支付成功 / 2 支付失败(与线下同字段,按 pay_type 区分语义) */
export type OnlinePayStatus = 0 | 1 | 2
export const ONLINE_PAY_STATUS_NAMES: Record<OnlinePayStatus, string> = {
0: '待支付',
1: '支付成功',
2: '支付失败',
}
/** 支付单状态展示名(在线支付单与线下凭证单同字段不同语义,按 pay_type 取名) */
export function getPayStatusName(payment: { status: PayStatus; pay_type?: PayType }): string {
return payment.pay_type === 2 ? ONLINE_PAY_STATUS_NAMES[payment.status] : PAY_STATUS_NAMES[payment.status]
}
/** 支付配置(付款页展示,图片为解析后的预览地址,可能为空串) */ /** 支付配置(付款页展示,图片为解析后的预览地址,可能为空串) */
export interface PaymentConfig { export interface PaymentConfig {
wechat_qrcode: string wechat_qrcode: string
alipay_qrcode: string alipay_qrcode: string
bank_info: string bank_info: string
/** 公众号 appid(H5 网页授权取 code 拼授权链接用,配置了公众号支付才返回) */
mp_appid?: string
} }
/** 支付记录(列表行与详情的 payment 字段一致) */ /** 支付记录(列表行与详情的 payment 字段一致) */
@@ -35,17 +55,23 @@ export interface Payment {
user_id: number user_id: number
/** 合并付款总金额 */ /** 合并付款总金额 */
amount: string amount: string
/** 支付类型:1 线下凭证 / 2 在线支付(旺铺网关) */
pay_type?: PayType
pay_method: PayMethod pay_method: PayMethod
/** 凭证图片 ID 数组(模型 casts 为 array */ /** 凭证图片 ID 数组(模型 casts 为 array,在线支付单为空 */
voucher_ids: number[] voucher_ids: number[]
status: PayStatus status: PayStatus
/** 提交备注 */ /** 提交备注 */
remark: string remark: string
/** 审核时间 */ /** 审核时间(线下凭证) */
audited_at: string | null audited_at: string | null
auditor_id: number | null auditor_id: number | null
/** 审核备注(拒绝原因) */ /** 审核备注(拒绝原因,线下凭证 */
audit_remark: string | null audit_remark: string | null
/** 在线支付成功时间(在线支付单非空) */
paid_at?: string | null
/** 网关交易号(在线支付单非空) */
trade_no?: string | null
created_at: string created_at: string
/** 列表返回:合并账单数 */ /** 列表返回:合并账单数 */
bills_count?: number bills_count?: number
@@ -98,3 +124,53 @@ export function createPaymentApi(data: {
export function getPaymentDetailApi(id: number) { export function getPaymentDetailApi(id: number) {
return get<PaymentDetail>(`/mini/payment/${id}`) return get<PaymentDetail>(`/mini/payment/${id}`)
} }
/** 在线支付下单返回(pay_params 为旺铺网关透传的调起参数:小程序给 wx.requestPaymentH5 公众号给 getBrandWCPayRequest,以网关实际返回为准) */
export interface OnlinePaymentCreateResult {
id: number
/** 支付单号(ZF 前缀,= 上送网关的商户订单号 mer_order_id),查询/对账用 */
payment_no: string
/** 应付金额(= 所选账单总额合计,元) */
amount: string
pay_params: {
appId?: string
timeStamp?: string
nonceStr?: string
package?: string
signType?: string
paySign?: string
[key: string]: any
}
}
/** 在线支付结果查询返回 */
export interface OnlinePaymentQueryResult {
payment_no: string
/** 0 待支付 / 1 支付成功(账单已置已支付)/ 2 支付失败(账单已释放) */
status: OnlinePayStatus
status_name: string
paid_at: string | null
trade_no: string | null
}
/**
* 发起在线支付(合并账单下单):POST /mini/payment/online
* code:小程序传 wx.login() 登录凭证(不传 scene);
* H5 公众号传网页授权回调 code,需带 scene: 'mp'(后端按场景换付款人 openid)
*/
export function createOnlinePaymentApi(data: {
bill_ids: number[]
code: string
scene?: 'mp'
remark?: string
}) {
return post<OnlinePaymentCreateResult>('/mini/payment/online', data)
}
/**
* 主动查询在线支付结果(网关后台通知延迟/丢失时的兜底):GET /mini/payment/online/{payment_no}/query
* 网关返回已支付则立即结账(与后台通知同一幂等逻辑)
*/
export function queryOnlinePaymentApi(paymentNo: string) {
return get<OnlinePaymentQueryResult>(`/mini/payment/online/${paymentNo}/query`)
}
+9 -2
View File
@@ -1,5 +1,6 @@
import { get } from '@/utils/request' import { get } from '@/utils/request'
import type { PaginatedData } from '@/types/api' import type { PaginatedData } from '@/types/api'
import type { CartSummary } from '@/types/cart'
import type { Category, Product } from '@/types/product' import type { Category, Product } from '@/types/product'
/** 商品分类树(仅含上架商品的分类及其祖先):GET /mini/product/categories */ /** 商品分类树(仅含上架商品的分类及其祖先):GET /mini/product/categories */
@@ -17,9 +18,15 @@ export interface ProductListParams {
pageSize?: number pageSize?: number
} }
/** 商品列表(当前门店等级实际价):GET /mini/product/list */ /** 商品列表响应(分页 + 购物车悬浮球汇总) */
export interface ProductListData extends PaginatedData<Product> {
/** 购物车悬浮球汇总(未登录返回零值结构;旧版本后端可能未返回,调用方判空) */
cart?: CartSummary
}
/** 商品列表(当前门店等级实际价 + 行内购物车字段):GET /mini/product/list */
export function getProductListApi(params: ProductListParams = {}) { export function getProductListApi(params: ProductListParams = {}) {
return get<PaginatedData<Product>>('/mini/product/list', { data: params }) return get<ProductListData>('/mini/product/list', { data: params })
} }
/** 商品详情(免登录;未登录/未绑店/未设等级 price=null;下架或不存在业务报错):GET /mini/product/{id} */ /** 商品详情(免登录;未登录/未绑店/未设等级 price=null;下架或不存在业务报错):GET /mini/product/{id} */
+61
View File
@@ -0,0 +1,61 @@
import { get } from '@/utils/request'
/**
* 统计周期预设:
* week 本周 / last_week 上周 / month 本月 / last_month 上月;
* custom 仅出现在响应中(传 start_date + end_date 自定义区间时生效,优先于 preset)
*/
export type ReportPreset = 'week' | 'last_week' | 'month' | 'last_month' | 'custom'
/** 单品累计行(按金额降序) */
export interface PurchaseReportItem {
product_id: number
/** 品名(下单时快照) */
product_name: string
/** 规格/包规(快照) */
product_spec: string
/** 计价单位(快照) */
unit: string
/** 周期内累计订货量 */
quantity: number
/** 周期内累计重量(3 位小数,未称重为 0.000) */
weight: string
/** 周期内累计采购金额(元,2 位小数字符串) */
amount: string
/** 金额占比(%,1 位小数;如 8.8 表示 8.8% */
percent: number
}
/** 采购运营报表 */
export interface PurchaseReport {
/** 实际生效的周期预设 */
preset: ReportPreset
/** 实际统计开始日期(Y-m-d,进行中的周期封顶为今天) */
start_date: string
/** 实际统计结束日期(Y-m-d) */
end_date: string
/** 周期内采购总金额(元,2 位小数字符串) */
total_amount: string
/** 周期内订货总量(各单品数量之和) */
total_quantity: number
/** 周期内有效订货单数 */
order_count: number
/** 单品个数(= items 长度) */
item_count: number
/** 单品累计列表,按金额降序 */
items: PurchaseReportItem[]
}
/** 报表查询参数:自定义区间(start_date + end_date 需成对)优先于 presetpreset 缺省为 month */
export interface PurchaseReportParams {
preset?: Exclude<ReportPreset, 'custom'>
/** 自定义开始日期(Y-m-d */
start_date?: string
/** 自定义结束日期(Y-m-d),不得早于 start_date */
end_date?: string
}
/** 采购运营报表:GET /mini/report/purchase(仅当前门店自身数据) */
export function getPurchaseReportApi(params: PurchaseReportParams = {}) {
return get<PurchaseReport>('/mini/report/purchase', { data: params })
}
+43
View File
@@ -0,0 +1,43 @@
import { get } from '@/utils/request'
import type { PaginatedData } from '@/types/api'
import type { CartSummary } from '@/types/cart'
import type { Product } from '@/types/product'
/** 特价推荐列表参数 */
export interface SpecialListParams {
page?: number
pageSize?: number
}
/**
* 特价推荐列表响应(分页 + 购物车悬浮球汇总)。
* 行结构与 /mini/product/list 一致:商品基础字段 + price + cart_id/cart_quantity
*/
export interface SpecialListData extends PaginatedData<Product> {
/**
* 购物车悬浮球汇总(未登录返回零值结构;旧版本后端可能未返回,调用方判空)。
* 接口文档示例为 count/quantity/amount 简写,与 /mini/home 等接口的 total_* 命名不一致,
* 统一经 normalizeSpecialCart 转换后再写入 store
*/
cart?: CartSummary | { count: number; quantity: string; amount: string }
}
/** 特价推荐商品列表(免登录;携带门店 token 时返回等级价与购物车字段):GET /mini/special/list */
export function getSpecialListApi(params: SpecialListParams = {}) {
return get<SpecialListData>('/mini/special/list', { data: params })
}
/** 特价推荐响应附带的悬浮球汇总归一化(兼容 count/quantity/amount 与 total_* 两种命名) */
export function normalizeSpecialCart(cart: SpecialListData['cart']): CartSummary | null {
if (!cart) return null
const raw = cart as Record<string, unknown>
const count = raw.total_count ?? raw.count
const quantity = raw.total_quantity ?? raw.quantity
const amount = raw.total_amount ?? raw.amount
if (count == null || quantity == null || amount == null) return null
return {
total_count: Number(count),
total_quantity: String(quantity),
total_amount: String(amount),
}
}
+9 -18
View File
@@ -1,7 +1,7 @@
import { create } from 'zustand' import { create } from 'zustand'
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import { registerApi, wxLoginApi } from '@/services/auth' import { loginApi } from '@/services/auth'
import type { RegisterParams, WxLoginParams } from '@/services/auth' import type { LoginParams } from '@/services/auth'
import type { User } from '@/types/user' import type { User } from '@/types/user'
/** 存储 key */ /** 存储 key */
@@ -26,7 +26,7 @@ function loadFromStorage(): { user: User | null; token: string | null } {
return { user: null, token: null } return { user: null, token: null }
} }
/** 登录 / 注册成功后持久化 token 与用户信息 */ /** 登录成功后持久化 token 与门店信息 */
function persistAuth(token: string, user: User): void { function persistAuth(token: string, user: User): void {
try { try {
Taro.setStorageSync(STORAGE_KEYS.TOKEN, token) Taro.setStorageSync(STORAGE_KEYS.TOKEN, token)
@@ -40,11 +40,10 @@ interface AuthState {
user: User | null user: User | null
token: string | null token: string | null
loading: boolean loading: boolean
login: (params: WxLoginParams) => Promise<void> /** 账号密码登录(门店账号由商家后台分配) */
/** 微信注册(手机号授权 + 门店编码绑定门店) */ login: (params: LoginParams) => Promise<void>
register: (params: RegisterParams) => Promise<void>
logout: () => void logout: () => void
/** 更新用户信息(用于编辑资料后同步 store) */ /** 更新门店信息(用于编辑资料后同步 store) */
setUser: (user: User) => void setUser: (user: User) => void
} }
@@ -57,17 +56,9 @@ const useAuthStore = create<AuthState>((set) => {
token: initial.token, token: initial.token,
loading: !!(initial.token && initial.user), // 已恢复则立即 ready loading: !!(initial.token && initial.user), // 已恢复则立即 ready
/** 登录(仅已注册用户可登录,未注册由页面引导去注册) */ /** 账号密码登录:POST /mini/auth/login */
login: async (params: WxLoginParams) => { login: async (params: LoginParams) => {
const res = await wxLoginApi(params) const res = await loginApi(params)
const { token, user } = res.data
set({ user, token })
persistAuth(token, user)
},
/** 注册:POST /mini/auth/register */
register: async (params: RegisterParams) => {
const res = await registerApi(params)
const { token, user } = res.data const { token, user } = res.data
set({ user, token }) set({ user, token })
persistAuth(token, user) persistAuth(token, user)
+66 -4
View File
@@ -5,13 +5,26 @@ import {
clearCartApi, clearCartApi,
deleteCartItemApi, deleteCartItemApi,
getCartApi, getCartApi,
getCartSummaryApi,
updateCartItemApi, updateCartItemApi,
} from '@/services/cart' } from '@/services/cart'
import type { CartItem } from '@/types/cart' import type { CartMutationResult } from '@/services/cart'
import { getToken } from '@/utils/request'
import type { CartItem, CartSummary } from '@/types/cart'
/** 存储 key */ /** 存储 key */
const STORAGE_KEY = 'cart_data' const STORAGE_KEY = 'cart_data'
/** 汇总请求序号(并发时仅采用最后一次响应) */
let summarySeq = 0
/** 汇总防抖校准定时器(列表加减停止 800ms 后整体拉取一次,以服务端为准) */
let summaryTimer: ReturnType<typeof setTimeout> | null = null
/** 数值 → 2 位小数字符串(与服务端金额/数量口径一致) */
function to2(n: number): string {
return (Math.round(n * 100) / 100).toFixed(2)
}
/** 持久化的购物车快照(服务端为准,此处仅作展示缓存) */ /** 持久化的购物车快照(服务端为准,此处仅作展示缓存) */
interface StoredCart { interface StoredCart {
items: CartItem[] items: CartItem[]
@@ -46,8 +59,8 @@ interface CartState {
loading: boolean loading: boolean
/** 拉取购物车(以服务端为准,金额一律服务端重算) */ /** 拉取购物车(以服务端为准,金额一律服务端重算) */
fetchCart: () => Promise<void> fetchCart: () => Promise<void>
/** 加购 */ /** 加购(返回合并后的购物车行,供列表页回写 cart_id/cart_quantity */
addItem: (productId: number, quantity: number) => Promise<void> addItem: (productId: number, quantity: number) => Promise<CartMutationResult>
/** 修改数量 */ /** 修改数量 */
updateQuantity: (id: number, quantity: number) => Promise<void> updateQuantity: (id: number, quantity: number) => Promise<void>
/** 删除单项 */ /** 删除单项 */
@@ -56,6 +69,12 @@ interface CartState {
clearCart: () => Promise<void> clearCart: () => Promise<void>
/** 下单成功后本地清空(不请求接口) */ /** 下单成功后本地清空(不请求接口) */
clearLocal: () => void clearLocal: () => void
/** 用接口附带的汇总块(首页/商品列表响应的 cart 字段)直接更新悬浮球 */
setSummary: (summary: CartSummary) => void
/** 拉取轻量汇总(需登录;未登录跳过,避免 401 跳转) */
fetchSummary: () => Promise<void>
/** 列表行内加减后本地增减悬浮球(乐观展示),并防抖调 fetchSummary 校准 */
applyDelta: (delta: { quantity: number; amount: number; count?: number }) => void
} }
/** 空的购物车快照 */ /** 空的购物车快照 */
@@ -80,6 +99,18 @@ const useCartStore = create<CartState>((set, get) => {
} }
} }
/** 写入悬浮球汇总并持久化(列表项快照保持不变) */
const applySummary = (summary: CartSummary) => {
const next = {
items: get().items,
totalCount: summary.total_count,
totalQuantity: summary.total_quantity,
totalAmount: summary.total_amount,
}
set(next)
persist(next)
}
return { return {
...EMPTY_SNAPSHOT, ...EMPTY_SNAPSHOT,
items: cached?.items ?? [], items: cached?.items ?? [],
@@ -111,8 +142,9 @@ const useCartStore = create<CartState>((set, get) => {
/** 加购:服务端校验上架与等级价,成功后重新同步 */ /** 加购:服务端校验上架与等级价,成功后重新同步 */
addItem: async (productId, quantity) => { addItem: async (productId, quantity) => {
await addCartApi({ product_id: productId, quantity }) const res = await addCartApi({ product_id: productId, quantity })
await get().fetchCart() await get().fetchCart()
return res.data
}, },
/** 修改数量 */ /** 修改数量 */
@@ -139,6 +171,36 @@ const useCartStore = create<CartState>((set, get) => {
set(EMPTY_SNAPSHOT) set(EMPTY_SNAPSHOT)
persist(EMPTY_SNAPSHOT) persist(EMPTY_SNAPSHOT)
}, },
/** 写入接口附带的汇总块(首页/商品列表) */
setSummary: (summary) => {
applySummary(summary)
},
/** 拉取轻量汇总(并发时仅采用最后一次响应) */
fetchSummary: async () => {
// 未登录无汇总(接口固定 401,会触发清理登录态),直接跳过
if (!getToken()) return
const seq = ++summarySeq
const res = await getCartSummaryApi()
if (seq !== summarySeq) return // 已有更新的请求,丢弃本次响应
applySummary(res.data)
},
/** 列表加减后的本地增减:即时反馈,防抖后以服务端汇总校准 */
applyDelta: ({ quantity, amount, count = 0 }) => {
const s = get()
applySummary({
total_count: Math.max(0, s.totalCount + count),
total_quantity: to2(Math.max(0, Number(s.totalQuantity) + quantity)),
total_amount: to2(Math.max(0, Number(s.totalAmount) + amount)),
})
if (summaryTimer) clearTimeout(summaryTimer)
summaryTimer = setTimeout(() => {
summaryTimer = null
get().fetchSummary().catch(() => {})
}, 800)
},
} }
}) })
+14
View File
@@ -15,6 +15,7 @@ export interface CartItem {
amount: string | null amount: string | null
/** 1 可购 / 0 商品下架、缺失或未设等级价 */ /** 1 可购 / 0 商品下架、缺失或未设等级价 */
status: number status: number
price_unit: string
} }
/** 购物车列表数据 */ /** 购物车列表数据 */
@@ -27,3 +28,16 @@ export interface CartData {
/** 可购项总金额 */ /** 可购项总金额 */
total_amount: string total_amount: string
} }
/**
* 购物车悬浮球汇总(/mini/home、/mini/product/list 响应附带;
* GET /mini/cart/summary 同构。未登录时列表/首页返回零值结构)
*/
export interface CartSummary {
/** 商品种数(全部行数,含已下架项) */
total_count: number
/** 总数量(仅可购项,2 位小数字符串) */
total_quantity: string
/** 总金额(仅可购项,元,2 位小数字符串) */
total_amount: string
}
+1
View File
@@ -85,6 +85,7 @@ export interface OrderItem {
product_name: string product_name: string
product_spec: string product_spec: string
unit: string unit: string
price_unit: string
/** 下单时门店等级实际价快照 */ /** 下单时门店等级实际价快照 */
price: string price: string
quantity: number quantity: number
+11
View File
@@ -27,6 +27,7 @@ export interface Product {
content: string content: string
/** 当前门店等级的实际销售价(未登录/未绑店/未设等级为 null) */ /** 当前门店等级的实际销售价(未登录/未绑店/未设等级为 null) */
price: string | null price: string | null
price_unit: string | null
images_arr: ProductImage[] images_arr: ProductImage[]
/** 所属分类(详情接口 with 返回) */ /** 所属分类(详情接口 with 返回) */
category?: { id: number; name: string } | null category?: { id: number; name: string } | null
@@ -36,6 +37,16 @@ export interface Product {
shelf_life?: number | null shelf_life?: number | null
stock?: number | null stock?: number | null
status?: number status?: number
/** 该商品对应的购物车行 ID(不在购物车/未登录为 0;列表加减、删除时需要) */
cart_id?: number
/** 购物车中该商品数量(2 位小数字符串;不在购物车/未登录为 "0.00" */
cart_quantity?: string
}
/** 商品行购物车字段回写(行内加减购确认后更新列表项) */
export interface ProductCartPatch {
cart_id: number
cart_quantity: string
} }
/** 商品首图地址 */ /** 商品首图地址 */
+20 -41
View File
@@ -4,54 +4,33 @@ export interface StoreLevel {
name: string name: string
} }
/** 门店信息 */ /**
export interface StoreInfo { * 登录门店信息(门店即用户)
id: number * 用户表与门店表已合并:登录 / auth/info 返回的 user 就是门店本身(扁平结构)
name: string */
/** 客户等级(level_id > 0 才可展示价格) */
level: StoreLevel | null
}
/** 供应商信息 */
export interface SupplierInfo {
id: number
name: string
}
/** 用户类型:0 待绑定 / 1 门店 / 2 供应商 */
export type UserType = 0 | 1 | 2
export const USER_TYPE_MAP: Record<UserType, string> = {
0: '待绑定',
1: '门店',
2: '供应商',
}
/** 用户信息(user 表实际返回字段) */
export interface User { export interface User {
id: number id: number
/** 用户名(注册时生成 wx_xxxx */ /** 门店名称 */
name: string
/** 门店编码(后台分配) */
code: string
/** 登录账号(后台分配,4~20 位) */
username: string username: string
/** 昵称(注册默认「微信用户」 */ /** 头像(可能为空 */
nickname: string
avatar: string avatar: string
/** 手机号(未绑定为空) */ level_id: number
/** 客户等级(level_id > 0 才可展示价格) */
level: StoreLevel | null
/** 联系人 */
contact: string
/** 联系电话 */
phone: string phone: string
/** 绑定门店ID0 未绑定) */ /** 地址 */
store_id: number address: string
/** 回款周期天数 */
payment_cycle_days: number
/** 1 正常 / 0 停用 */ /** 1 正常 / 0 停用 */
status: number status: number
/** 微信标识 */
openid: string
unionid: string
email: string
last_login_at: string | null last_login_at: string | null
created_at: string | null created_at: string | null
updated_at: string | null
/** 兼容旧 /mini/auth/info 返回(身份类型) */
type?: UserType
/** 兼容旧 /mini/auth/info 返回(门店信息) */
store?: StoreInfo | null
/** 兼容旧 /mini/auth/info 返回(供应商信息) */
supplier?: SupplierInfo | null
} }
+34
View File
@@ -55,3 +55,37 @@ export function resolveFileUrl(url?: string): string {
export function resolveAvatarUrl(avatar?: string): string { export function resolveAvatarUrl(avatar?: string): string {
return resolveFileUrl(avatar) return resolveFileUrl(avatar)
} }
/**
* 商品规格展示:包规与单位直接拼接
* spec=20、unit=斤/箱 → 20斤/箱
*/
export function formatSpec(spec?: string | number | null, unit?: string | null): string {
const s = spec === null || spec === undefined ? '' : String(spec).trim()
const u = (unit ?? '').trim()
return `${s}${u}`
}
/**
* 零售价 = 售价 ÷ 包规(如 30¥/箱 ÷ 20斤/箱 = 2¥/斤)
* 保留两位小数并去掉尾零(2 → "2"2.50 → "2.5"
* 售价为空、包规非数字或 ≤0 时返回 null(不展示零售价)
*/
export function formatRetailPrice(price?: string | number | null, spec?: string | number | null): string | null {
if (price === null || price === undefined || price === '') return null
const p = Number(price)
const s = Number(spec)
if (!Number.isFinite(p) || !Number.isFinite(s) || s <= 0) return null
return String(Math.round((p / s) * 100) / 100)
}
/**
* 数量展示:保留两位小数并去掉尾零("2.50" → "2.5""3.00" → "3"
* 用于悬浮球徽标、行内加减器等窄空间;非法值按 0 处理
*/
export function formatQuantity(value?: string | number | null): string {
if (value === null || value === undefined || value === '') return '0'
const n = Number(value)
if (!Number.isFinite(n)) return '0'
return String(Math.round(n * 100) / 100)
}
+2 -1
View File
@@ -10,7 +10,8 @@ const LOGIN_PATH = '/pages/login/index'
/** 默认请求超时(ms */ /** 默认请求超时(ms */
const DEFAULT_TIMEOUT = 15000 const DEFAULT_TIMEOUT = 15000
/** 接口根地址(uploadFile 等原生请求同样使用) */ /** 接口根地址(uploadFile 等原生请求同样使用) */
export const BASE_URL = "http://localhost:8000/index.php" // export const BASE_URL = "http://localhost:8000"
export const BASE_URL = "https://purchase.henanklkj.com/index.php"
/** /**
* HTTP 状态码 → 错误提示映射 * HTTP 状态码 → 错误提示映射