forked from gxwebsoft/mp-10550
Compare commits
22 Commits
68d5848d3d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 81c63e0e65 | |||
| 86f7506422 | |||
| fae144549e | |||
| 718eddff63 | |||
| a4a0a922fc | |||
| ca2436a2e8 | |||
| 83ba49d860 | |||
| 7375a3b1ce | |||
| 756b548bf9 | |||
| 76e76c62ef | |||
| 546d90cc28 | |||
| d4fd61376c | |||
| b27421fd6e | |||
| b929b8d35e | |||
| 23af704c68 | |||
| ab61aa9ee0 | |||
| 64d30e1b62 | |||
| a8eb9e11be | |||
| 338dc421db | |||
| 6f1e0a6a2b | |||
| 8b5609255a | |||
| 31d47f0a0b |
@@ -9,6 +9,6 @@ export const BaseUrl = API_BASE_URL;
|
||||
// 当前版本
|
||||
export const Version = 'v3.0.8';
|
||||
// 版权信息
|
||||
export const Copyright = 'WebSoft Inc.';
|
||||
export const Copyright = '桂乐淘·购享无界 乐惠万家';
|
||||
|
||||
// java -jar CertificateDownloader.jar -k 0kF5OlPr482EZwtn9zGufUcqa7ovgxRL -m 1723321338 -f ./apiclient_key.pem -s 2B933F7C35014A1C363642623E4A62364B34C4EB -o ./
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#### 新增功能
|
||||
- 用户头像和基本信息展示
|
||||
- 佣金统计(可提现、冻结中、累计收益)
|
||||
- 佣金统计(可提现、待使用、累计收益)
|
||||
- 团队统计(一级、二级、三级成员)
|
||||
- 功能导航网格(分销订单、提现申请、我的团队、推广二维码)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ dealer: {
|
||||
// 金额相关
|
||||
money: {
|
||||
available: 'linear-gradient(135deg, #10b981 0%, #059669 100%)', // 可提现 - 绿色
|
||||
frozen: 'linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)', // 冻结中 - 蓝色
|
||||
frozen: 'linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)', // 待使用 - 蓝色
|
||||
total: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)' // 累计 - 橙色
|
||||
}
|
||||
```
|
||||
|
||||
@@ -31,6 +31,10 @@ export interface ShopDealerOrder {
|
||||
isInvalid?: number;
|
||||
// 佣金结算(0未结算 1已结算)
|
||||
isSettled?: number;
|
||||
// 佣金解冻(0未解冻 1已解冻)
|
||||
isUnfreeze?: number;
|
||||
// 订单状态
|
||||
orderStatus?: number;
|
||||
// 结算时间
|
||||
settleTime?: number;
|
||||
// 商城ID
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '成为经销商',
|
||||
navigationBarTitleText: '注册成为会员',
|
||||
navigationBarTextStyle: 'black'
|
||||
})
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '桂乐淘分享中心'
|
||||
navigationBarTitleText: '账户管理中心'
|
||||
})
|
||||
|
||||
@@ -134,7 +134,7 @@ const DealerIndex: React.FC = () => {
|
||||
<View className="grid grid-cols-3 gap-3">
|
||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
||||
background: businessGradients.money.available
|
||||
}}>
|
||||
}} onClick={() => navigateToPage('/dealer/withdraw/index')}>
|
||||
<Text className="text-lg font-bold mb-1 text-white">
|
||||
{formatMoney(dealerUser.money)}
|
||||
</Text>
|
||||
@@ -146,7 +146,7 @@ const DealerIndex: React.FC = () => {
|
||||
<Text className="text-lg font-bold mb-1 text-white">
|
||||
{formatMoney(dealerUser.freezeMoney)}
|
||||
</Text>
|
||||
<Text className="text-xs" style={{ color: 'rgba(255, 255, 255, 0.9)' }}>冻结中</Text>
|
||||
<Text className="text-xs" style={{ color: 'rgba(255, 255, 255, 0.9)' }}>待使用</Text>
|
||||
</View>
|
||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
||||
background: businessGradients.money.total
|
||||
|
||||
@@ -94,15 +94,19 @@ const DealerOrders: React.FC = () => {
|
||||
}
|
||||
}, [fetchOrders])
|
||||
|
||||
const getStatusText = (isSettled?: number, isInvalid?: number) => {
|
||||
const getStatusText = (isSettled?: number, isInvalid?: number, isUnfreeze?: number, orderStatus?: number) => {
|
||||
if (orderStatus === 2 || orderStatus === 5 || orderStatus === 6) return '已取消'
|
||||
if (isInvalid === 1) return '已失效'
|
||||
if (isUnfreeze === 1) return '已解冻'
|
||||
if (isSettled === 1) return '已结算'
|
||||
return '待结算'
|
||||
}
|
||||
|
||||
const getStatusColor = (isSettled?: number, isInvalid?: number) => {
|
||||
const getStatusColor = (isSettled?: number, isInvalid?: number, isUnfreeze?: number, orderStatus?: number) => {
|
||||
if (orderStatus === 2 || orderStatus === 5 || orderStatus === 6) return 'default'
|
||||
if (isInvalid === 1) return 'danger'
|
||||
if (isSettled === 1) return 'success'
|
||||
if (isUnfreeze === 1) return 'success'
|
||||
if (isSettled === 1) return 'info'
|
||||
return 'warning'
|
||||
}
|
||||
|
||||
@@ -120,8 +124,8 @@ const DealerOrders: React.FC = () => {
|
||||
<Text className="font-semibold text-gray-800">
|
||||
订单号:{order.orderNo || '-'}
|
||||
</Text>
|
||||
<Tag type={getStatusColor(order.isSettled, order.isInvalid)}>
|
||||
{getStatusText(order.isSettled, order.isInvalid)}
|
||||
<Tag type={getStatusColor(order.isSettled, order.isInvalid, order.isUnfreeze,order.orderStatus)}>
|
||||
{getStatusText(order.isSettled, order.isInvalid, order.isUnfreeze,order.orderStatus)}
|
||||
</Tag>
|
||||
</View>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '桂乐淘分享中心',
|
||||
navigationBarTitleText: '账户管理中心',
|
||||
// Enable "Share to friends" and "Share to Moments" (timeline) for this page.
|
||||
enableShareAppMessage: true,
|
||||
enableShareTimeline: true
|
||||
|
||||
@@ -325,7 +325,7 @@ const DealerTeam: React.FC = () => {
|
||||
</View>
|
||||
{/* 显示手机号(仅本级可见) */}
|
||||
{showPhone && member.phone && (
|
||||
<Text className="text-sm text-gray-500" onClick={(e) => {
|
||||
<Text className="text-sm text-gray-500 hidden" onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
makePhoneCall(member.phone || '');
|
||||
}}>
|
||||
|
||||
@@ -98,7 +98,7 @@ const normalizeMoneyString = (money: unknown) => {
|
||||
}
|
||||
|
||||
const DealerWithdraw: React.FC = () => {
|
||||
const [activeTab, setActiveTab] = useState<string | number>('0')
|
||||
const [activeTab, setActiveTab] = useState<string>('0')
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [refreshing, setRefreshing] = useState<boolean>(false)
|
||||
const [submitting, setSubmitting] = useState<boolean>(false)
|
||||
@@ -114,10 +114,11 @@ const DealerWithdraw: React.FC = () => {
|
||||
// Tab 切换处理函数
|
||||
const handleTabChange = (value: string | number) => {
|
||||
console.log('Tab切换到:', value)
|
||||
setActiveTab(value)
|
||||
const next = String(value)
|
||||
setActiveTab(next)
|
||||
|
||||
// 如果切换到提现记录页面,刷新数据
|
||||
if (String(value) === '1') {
|
||||
if (next === '1') {
|
||||
fetchWithdrawRecords()
|
||||
}
|
||||
}
|
||||
@@ -310,7 +311,7 @@ const DealerWithdraw: React.FC = () => {
|
||||
if (amount > available) {
|
||||
Taro.showToast({
|
||||
title: '提现金额超过可用余额',
|
||||
icon: 'error'
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -487,7 +488,7 @@ const DealerWithdraw: React.FC = () => {
|
||||
labelPosition="top"
|
||||
>
|
||||
<CellGroup>
|
||||
<Form.Item name="amount" label="提现金额" required>
|
||||
<Form.Item name="amount" label="提现金额">
|
||||
<Input
|
||||
placeholder="请输入提现金额"
|
||||
type="number"
|
||||
@@ -522,7 +523,7 @@ const DealerWithdraw: React.FC = () => {
|
||||
<Text className="text-sm text-red-500">
|
||||
注意事项:
|
||||
1. 提取佣金必须完成实名认证。
|
||||
2. 佣金非自动到账,再您提取佣金申请通过后,请手动到我的申请记录点击领取。
|
||||
2. 佣金非自动到账,在您提取佣金申请通过后,请手动到我的申请记录点击领取。
|
||||
3. 桂乐淘温馨提示,请您依法依规申报所得,缴税相关税费。
|
||||
</Text>
|
||||
</View>
|
||||
@@ -628,13 +629,12 @@ const DealerWithdraw: React.FC = () => {
|
||||
<View className="bg-gray-50 min-h-screen">
|
||||
<Tabs value={activeTab} onChange={handleTabChange}>
|
||||
<Tabs.TabPane title="申请提现" value="0">
|
||||
{renderWithdrawForm()}
|
||||
</Tabs.TabPane>
|
||||
|
||||
<Tabs.TabPane title="提现记录" value="1">
|
||||
{renderWithdrawRecords()}
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
{activeTab === '0' ? renderWithdrawForm() : renderWithdrawRecords()}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import Taro from '@tarojs/taro';
|
||||
import { User } from '@/api/system/user/model';
|
||||
import { getUserInfo, updateUserInfo, loginByOpenId } from '@/api/layout';
|
||||
import { TenantId } from '@/config/app';
|
||||
import {getStoredInviteParams, handleInviteRelation} from '@/utils/invite';
|
||||
import { handleInviteRelation } from '@/utils/invite';
|
||||
|
||||
// 用户Hook
|
||||
export const useUser = () => {
|
||||
@@ -44,15 +44,10 @@ export const useUser = () => {
|
||||
reject(new Error('自动登录失败'));
|
||||
}
|
||||
}).catch(_ => {
|
||||
// 首次注册,跳转到邀请注册页面
|
||||
const pages = Taro.getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const inviteParams = getStoredInviteParams()
|
||||
if (currentPage?.route !== 'dealer/apply/add' && inviteParams?.inviter) {
|
||||
return Taro.navigateTo({
|
||||
url: '/dealer/apply/add'
|
||||
});
|
||||
}
|
||||
// 登录失败(通常是新用户尚未注册/未绑定手机号等)。
|
||||
// 这里不做任何“自动跳转”,避免用户点击「我的」时被强制带到分销/申请页,体验割裂。
|
||||
// 需要登录的页面请使用 utils/auth 的 ensureLoggedIn / goToRegister 做显式跳转。
|
||||
reject(new Error('autoLoginByOpenId failed'));
|
||||
});
|
||||
},
|
||||
fail: reject
|
||||
@@ -60,7 +55,11 @@ export const useUser = () => {
|
||||
});
|
||||
return res;
|
||||
} catch (error) {
|
||||
console.error('自动登录失败:', error);
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
// 新用户首次进入、未绑定手机号等场景属于“预期失败”,避免刷屏报错。
|
||||
if (msg !== 'autoLoginByOpenId failed') {
|
||||
console.error('自动登录失败:', error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import Banner from './Banner'
|
||||
import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro'
|
||||
import { View, Text, Image, ScrollView } from '@tarojs/components'
|
||||
import { useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||
import { Cart, Gift, Ticket, Agenda } from '@nutui/icons-react-taro'
|
||||
import { Cart, Gift, Ticket, Agenda, ArrowRight } from '@nutui/icons-react-taro'
|
||||
import { getShopInfo } from '@/api/layout'
|
||||
import { checkAndHandleInviteRelation, hasPendingInvite } from '@/utils/invite'
|
||||
import { pageShopGoods } from '@/api/shop/shopGoods'
|
||||
@@ -11,6 +11,7 @@ import type { ShopGoods, ShopGoodsParam } from '@/api/shop/shopGoods/model'
|
||||
import { getMyGltUserTicketTotal } from '@/api/glt/gltUserTicket'
|
||||
import { ensureLoggedIn } from '@/utils/auth'
|
||||
import './index.scss'
|
||||
// import navTo from "@/utils/common";
|
||||
|
||||
function Home() {
|
||||
const [activeTabKey, setActiveTabKey] = useState('recommend')
|
||||
@@ -289,7 +290,21 @@ function Home() {
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 分类Tabs */}
|
||||
<View className="ticket-card" onClick={() => Taro.navigateTo({ url: `/shop/category/index?id=4560` })}>
|
||||
<View className="ticket-card__head">
|
||||
<Text className="ticket-card__title">政企采购专区</Text>
|
||||
<ArrowRight className={'text-gray-50'} size={16} />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="ticket-card" onClick={() => Taro.navigateTo({ url: `/shop/category/index?id=4556` })}>
|
||||
<View className="ticket-card__head">
|
||||
<Text className="ticket-card__title">桂乐淘·福利惊爆区</Text>
|
||||
<ArrowRight className={'text-gray-50'} size={16} />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/*分类Tabs*/}
|
||||
<ScrollView className="home-tabs" scrollX enableFlex>
|
||||
<View className="home-tabs__inner">
|
||||
{tabs.map((tab) => {
|
||||
@@ -306,7 +321,6 @@ function Home() {
|
||||
})}
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
{/* 商品列表 */}
|
||||
<View className="goods-grid">
|
||||
{visibleGoods.map((item) => (
|
||||
@@ -329,20 +343,20 @@ function Home() {
|
||||
<Text className="goods-card__sold">已购:{item.sales || 0}人</Text>
|
||||
<View className="goods-card__price">
|
||||
<Text className="goods-card__priceUnit">¥</Text>
|
||||
<Text className="goods-card__priceValue">{item.price}</Text>
|
||||
<Text className="goods-card__priceValue">{item.buyingPrice}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="goods-card__actions">
|
||||
<View
|
||||
className="goods-card__btn goods-card__btn--ghost"
|
||||
onClick={() => {
|
||||
if (!ensureLoggedIn('/shop/orderConfirm/index?goodsId=10074')) return
|
||||
Taro.navigateTo({ url: '/shop/orderConfirm/index?goodsId=10074' })
|
||||
}}
|
||||
>
|
||||
<Text className="goods-card__btnText">买水票更优惠</Text>
|
||||
</View>
|
||||
{/*<View*/}
|
||||
{/* className="goods-card__btn goods-card__btn--ghost"*/}
|
||||
{/* onClick={() => {*/}
|
||||
{/* if (!ensureLoggedIn('/shop/orderConfirm/index?goodsId=10074')) return*/}
|
||||
{/* Taro.navigateTo({ url: '/shop/orderConfirm/index?goodsId=10074' })*/}
|
||||
{/* }}*/}
|
||||
{/*>*/}
|
||||
{/* <Text className="goods-card__btnText">买水票更优惠</Text>*/}
|
||||
{/*</View>*/}
|
||||
<View
|
||||
className="goods-card__btn goods-card__btn--primary"
|
||||
onClick={() =>
|
||||
@@ -356,6 +370,7 @@ function Home() {
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
||||
</View>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ const IsDealer = () => {
|
||||
<View style={{display: 'inline-flex', alignItems: 'center'}}>
|
||||
<Reward className={'text-orange-100 '} size={16}/>
|
||||
<Text style={{fontSize: '16px'}}
|
||||
className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '桂乐淘分享中心'}</Text>
|
||||
className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '账户管理中心'}</Text>
|
||||
{/*<Text className={'text-white opacity-80 pl-3'}>门店核销</Text>*/}
|
||||
</View>
|
||||
}
|
||||
@@ -76,7 +76,7 @@ const IsDealer = () => {
|
||||
title={
|
||||
<View style={{display: 'inline-flex', alignItems: 'center'}}>
|
||||
<Reward className={'text-orange-100 '} size={16}/>
|
||||
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '桂乐淘分享中心'}</Text>
|
||||
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '账户管理中心'}</Text>
|
||||
<Text className={'text-white opacity-80 pl-3'}>{config?.vipComments || ''}</Text>
|
||||
</View>
|
||||
}
|
||||
|
||||
@@ -335,13 +335,9 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
||||
<View className={'py-2'}>
|
||||
<View className={'flex justify-around mt-1'}>
|
||||
<View className={'item flex justify-center flex-col items-center'}
|
||||
onClick={() => navTo('/user/wallet/wallet', true)}>
|
||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>余额</Text>
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.balance || '0.00'}</Text>
|
||||
</View>
|
||||
<View className={'item flex justify-center flex-col items-center'}>
|
||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>积分</Text>
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.points || 0}</Text>
|
||||
onClick={() => navTo('/user/ticket/index', true)}>
|
||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>水票</Text>
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{ticketTotal}</Text>
|
||||
</View>
|
||||
<View className={'item flex justify-center flex-col items-center'}
|
||||
onClick={() => navTo('/user/coupon/index', true)}>
|
||||
@@ -349,9 +345,13 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.coupons || 0}</Text>
|
||||
</View>
|
||||
<View className={'item flex justify-center flex-col items-center'}
|
||||
onClick={() => navTo('/user/ticket/index', true)}>
|
||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>水票</Text>
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{ticketTotal}</Text>
|
||||
onClick={() => navTo('/user/wallet/wallet', true)}>
|
||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>余额</Text>
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.balance || '0.00'}</Text>
|
||||
</View>
|
||||
<View className={'item flex justify-center flex-col items-center'}>
|
||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>积分</Text>
|
||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.points || 0}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -47,8 +47,9 @@ const UserFooter = () => {
|
||||
return (
|
||||
<>
|
||||
<div className={'text-center py-4 w-full text-gray-300'} onClick={onLoginByPhone}>
|
||||
<div className={'text-xs text-gray-400 py-1'}>当前版本:{Version}</div>
|
||||
<div className={'text-xs text-gray-400 py-1'}>Copyright © { new Date().getFullYear() } {Copyright}</div>
|
||||
{/*<div className={'text-xs text-gray-400 py-1'}>当前版本:{Version}</div>*/}
|
||||
{/*<div className={'text-xs text-gray-400 py-1'}>Copyright © { new Date().getFullYear() } {Copyright}</div>*/}
|
||||
<div className={'text-xs text-gray-400 py-1'}>{Copyright}</div>
|
||||
</div>
|
||||
|
||||
<Popup
|
||||
|
||||
@@ -39,7 +39,7 @@ const UserCell = () => {
|
||||
return (
|
||||
<>
|
||||
<View className="bg-white mx-4 mt-4 rounded-xl">
|
||||
<View className="font-semibold text-gray-800 pt-4 pl-4">我的服务</View>
|
||||
<View className="font-semibold text-gray-800 pt-4 pl-4">桂乐淘服务中心</View>
|
||||
<ConfigProvider>
|
||||
<Grid
|
||||
columns={4}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useEffect, useRef} from 'react'
|
||||
import {useEffect, useRef, useState} from 'react'
|
||||
import {PullToRefresh} from '@nutui/nutui-react-taro'
|
||||
import UserCard from "./components/UserCard";
|
||||
import UserOrder from "./components/UserOrder";
|
||||
@@ -14,12 +14,15 @@ function User() {
|
||||
|
||||
const userCardRef = useRef<any>()
|
||||
const themeStyles = useThemeStyles();
|
||||
// TabBar 页在小程序里通常不会销毁;从“注册/申请”页返回时需要触发子组件重新初始化/拉取最新状态。
|
||||
const [dealerViewKey, setDealerViewKey] = useState(0)
|
||||
|
||||
// 下拉刷新处理
|
||||
const handleRefresh = async () => {
|
||||
if (userCardRef.current?.handleRefresh) {
|
||||
await userCardRef.current.handleRefresh()
|
||||
}
|
||||
setDealerViewKey(v => v + 1)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
@@ -30,6 +33,7 @@ function User() {
|
||||
userCardRef.current?.reloadStats?.()
|
||||
// 个人资料(头像/昵称)可能在其它页面被修改,这里确保返回时立刻刷新
|
||||
userCardRef.current?.reloadUserInfo?.()
|
||||
setDealerViewKey(v => v + 1)
|
||||
})
|
||||
|
||||
return (
|
||||
@@ -58,7 +62,7 @@ function User() {
|
||||
</View>
|
||||
<UserCard ref={userCardRef}/>
|
||||
<UserOrder/>
|
||||
<IsDealer/>
|
||||
<IsDealer key={dealerViewKey}/>
|
||||
<UserGrid/>
|
||||
<UserFooter/>
|
||||
</PullToRefresh>
|
||||
|
||||
@@ -130,7 +130,7 @@ const DealerIndex: React.FC = () => {
|
||||
{dealerUser && (
|
||||
<View className="mx-4 -mt-6 rounded-xl p-4 relative z-10" style={cardGradients.elevated}>
|
||||
<View className="mb-4">
|
||||
<Text className="font-semibold text-gray-800">工资统计</Text>
|
||||
<Text className="font-semibold text-gray-800">配送提成</Text>
|
||||
</View>
|
||||
<View className="grid grid-cols-3 gap-3">
|
||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
|
||||
.goods-grid {
|
||||
margin-top: 18rpx;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 18rpx;
|
||||
}
|
||||
|
||||
.goods-card {
|
||||
border-radius: 22rpx;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 18rpx 36rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.goods-card__imgWrap {
|
||||
padding: 18rpx 18rpx 0;
|
||||
}
|
||||
|
||||
.goods-card__img {
|
||||
width: 100%;
|
||||
height: 280rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #f4f4f4;
|
||||
}
|
||||
|
||||
.goods-card__body {
|
||||
padding: 18rpx 18rpx 20rpx;
|
||||
}
|
||||
|
||||
.goods-card__title {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
color: #1c1c1c;
|
||||
min-height: 72rpx;
|
||||
}
|
||||
|
||||
.goods-card__meta {
|
||||
margin-top: 10rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.goods-card__sold {
|
||||
font-size: 22rpx;
|
||||
color: #9a9a9a;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.goods-card__price {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 4rpx;
|
||||
color: #27c86b;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.goods-card__priceUnit {
|
||||
font-size: 22rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.goods-card__priceValue {
|
||||
font-size: 36rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.goods-card__actions {
|
||||
margin-top: 16rpx;
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.goods-card__btn {
|
||||
flex: 1;
|
||||
height: 64rpx;
|
||||
border-radius: 999rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.goods-card__btn--ghost {
|
||||
border: 2rpx solid rgba(32, 194, 106, 0.7);
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.goods-card__btn--primary {
|
||||
background: linear-gradient(90deg, #24d34c 0%, #6df09a 100%);
|
||||
}
|
||||
|
||||
.goods-card__btnText {
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
color: #18b85a;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.goods-card__btnText--primary {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.buy-btn{
|
||||
height: 70px;
|
||||
background: linear-gradient(to bottom, #1cd98a, #24ca94);
|
||||
border-radius: 100px;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
.cart-icon{
|
||||
background: linear-gradient(to bottom, #bbe094, #4ee265);
|
||||
border-radius: 100px 0 0 100px;
|
||||
height: 70px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,57 @@
|
||||
import {Image} from '@nutui/nutui-react-taro'
|
||||
import {Share} from '@nutui/icons-react-taro'
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
import './GoodsList.scss'
|
||||
import {ShopGoods} from "@/api/shop/shopGoods/model";
|
||||
|
||||
|
||||
const GoodsList = (props: any) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<View className={'py-3'}>
|
||||
<View className={'flex flex-col justify-between items-center rounded-lg px-2'}>
|
||||
{props.data?.map((item: any, index: number) => {
|
||||
return (
|
||||
<View key={index} className={'flex flex-col rounded-lg bg-white shadow-sm w-full mb-5'}>
|
||||
<Image src={item.image} mode={'aspectFit'} lazyLoad={false}
|
||||
radius="10px 10px 0 0" height="180"
|
||||
onClick={() => Taro.navigateTo({url: '/shop/goodsDetail/index?id=' + item.goodsId})}/>
|
||||
<View className={'flex flex-col p-2 rounded-lg'}>
|
||||
<View>
|
||||
<View className={'car-no text-sm'}>{item.name}</View>
|
||||
<View className={'flex justify-between text-xs py-1'}>
|
||||
<Text className={'text-orange-500'}>{item.comments}</Text>
|
||||
<Text className={'text-gray-400'}>已售 {item.sales}</Text>
|
||||
</View>
|
||||
<View className={'flex justify-between items-center py-2'}>
|
||||
<View className={'flex text-red-500 text-xl items-baseline'}>
|
||||
<Text className={'text-xs'}>¥</Text>
|
||||
<Text className={'font-bold text-2xl'}>{item.price}</Text>
|
||||
<Text className={'text-xs px-1'}>会员价</Text>
|
||||
<Text className={'text-xs text-gray-400 line-through'}>¥{item.salePrice}</Text>
|
||||
</View>
|
||||
<View className={'buy-btn'}>
|
||||
<View className={'cart-icon'}>
|
||||
<Share size={20} className={'mx-4 mt-2'}
|
||||
onClick={() => Taro.navigateTo({url: '/shop/goodsDetail/index?id=' + item.goodsId})}/>
|
||||
</View>
|
||||
<View className={'text-white pl-4 pr-5'}
|
||||
onClick={() => Taro.navigateTo({url: '/shop/goodsDetail/index?id=' + item.goodsId})}>购买
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={'p-3'}>
|
||||
|
||||
<View className="goods-grid">
|
||||
{props.data?.map((item: ShopGoods) => (
|
||||
<View key={item.goodsId} className="goods-card">
|
||||
<View className="goods-card__imgWrap">
|
||||
<Image
|
||||
className="goods-card__img"
|
||||
src={item.image || ''}
|
||||
mode="aspectFill"
|
||||
width="100%"
|
||||
height="280rpx"
|
||||
radius="18rpx"
|
||||
lazyLoad={false}
|
||||
onClick={() =>
|
||||
Taro.navigateTo({ url: `/shop/goodsDetail/index?id=${item.goodsId}` })
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View className="goods-card__body">
|
||||
<Text className="goods-card__title">{item.name}</Text>
|
||||
<View className="goods-card__meta">
|
||||
<Text className="goods-card__sold">已购:{item.sales || 0}人</Text>
|
||||
<View className="goods-card__price">
|
||||
<Text className="goods-card__priceUnit">¥</Text>
|
||||
<Text className="goods-card__priceValue">{item.buyingPrice}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="goods-card__actions">
|
||||
<View
|
||||
className="goods-card__btn goods-card__btn--primary"
|
||||
onClick={() =>
|
||||
Taro.navigateTo({ url: `/shop/goodsDetail/index?id=${item.goodsId}` })
|
||||
}
|
||||
>
|
||||
<Text className="goods-card__btnText goods-card__btnText--primary">立即购买</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import GoodsList from './components/GoodsList'
|
||||
import {useShareAppMessage} from "@tarojs/taro"
|
||||
import {Loading} from '@nutui/nutui-react-taro'
|
||||
import {Loading,Empty} from '@nutui/nutui-react-taro'
|
||||
import {useEffect, useState} from "react"
|
||||
import {useRouter} from '@tarojs/taro'
|
||||
import './index.scss'
|
||||
@@ -21,7 +21,7 @@ function Category() {
|
||||
// 1.加载远程数据
|
||||
const id = Number(params.id)
|
||||
const nav = await getCmsNavigation(id)
|
||||
const shopGoods = await pageShopGoods({categoryId: id})
|
||||
const shopGoods = await pageShopGoods({categoryId: id, status: 0})
|
||||
|
||||
// 2.处理业务逻辑
|
||||
setCategoryId(id)
|
||||
@@ -59,6 +59,12 @@ function Category() {
|
||||
)
|
||||
}
|
||||
|
||||
if(list.length == 0){
|
||||
return (
|
||||
<Empty description="暂无数据"/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={'flex flex-col'}>
|
||||
|
||||
@@ -366,9 +366,9 @@ const GoodsDetail = () => {
|
||||
<View className={'flex justify-between'}>
|
||||
<View className={'flex text-red-500 text-xl items-baseline'}>
|
||||
<Text className={'text-xs'}>¥</Text>
|
||||
<Text className={'font-bold text-2xl'}>{goods.price}</Text>
|
||||
<Text className={'font-bold text-2xl'}>{goods.buyingPrice}</Text>
|
||||
<Text className={'text-xs px-1'}>会员价</Text>
|
||||
<Text className={'text-xs text-gray-400 line-through'}>¥{goods.salePrice}</Text>
|
||||
<Text className={'text-xs text-gray-400 line-through'}>¥{goods.salePrice}/{goods.unitName}</Text>
|
||||
</View>
|
||||
<span className={"text-gray-400 text-xs"}>已售 {goods.sales}</span>
|
||||
</View>
|
||||
|
||||
@@ -430,6 +430,7 @@ const OrderConfirm = () => {
|
||||
* 统一支付入口
|
||||
*/
|
||||
const onPay = async (goods: ShopGoods) => {
|
||||
let skipFinallyResetPayLoading = false
|
||||
try {
|
||||
setPayLoading(true)
|
||||
|
||||
@@ -603,6 +604,29 @@ const OrderConfirm = () => {
|
||||
// })
|
||||
} catch (error: any) {
|
||||
const message = String(error?.message || '')
|
||||
const isUserCancelPay =
|
||||
message.includes('用户取消支付') ||
|
||||
message.includes('取消支付') ||
|
||||
message.toLowerCase().includes('requestpayment:fail cancel') ||
|
||||
message.toLowerCase().includes('cancel')
|
||||
|
||||
// 用户取消支付:跳转到待付款列表,方便继续支付
|
||||
if (isUserCancelPay) {
|
||||
skipFinallyResetPayLoading = true
|
||||
setPayLoading(false)
|
||||
const url = '/user/order/order?statusFilter=0'
|
||||
try {
|
||||
await Taro.redirectTo({ url })
|
||||
} catch (_e) {
|
||||
try {
|
||||
await Taro.navigateTo({ url })
|
||||
} catch (_e2) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const isOutOfDeliveryRange =
|
||||
message.includes('不在配送范围') ||
|
||||
message.includes('配送范围') ||
|
||||
@@ -632,7 +656,9 @@ const OrderConfirm = () => {
|
||||
Taro.showToast({ title: message || '支付失败,请重试', icon: 'none' })
|
||||
}
|
||||
} finally {
|
||||
setPayLoading(false)
|
||||
if (!skipFinallyResetPayLoading) {
|
||||
setPayLoading(false)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -853,15 +879,17 @@ const OrderConfirm = () => {
|
||||
<View className={'flex justify-between items-center'}>
|
||||
<Text className={'text-red-500'}>¥{goods.price}</Text>
|
||||
<View className={'flex flex-col items-end gap-1'}>
|
||||
<ConfigProvider theme={customTheme}>
|
||||
<InputNumber
|
||||
value={quantity}
|
||||
min={isTicketTemplateActive ? minBuyQty : 1}
|
||||
max={goods.stock || 999}
|
||||
disabled={((goods.canBuyNumber ?? 0) !== 0) && !isTicketTemplateActive}
|
||||
onChange={handleQuantityChange}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
<ConfigProvider theme={customTheme}>
|
||||
<InputNumber
|
||||
value={quantity}
|
||||
min={isTicketTemplateActive ? minBuyQty : 1}
|
||||
max={goods.stock || 999}
|
||||
step={minBuyQty === 1 ? 1 : 10}
|
||||
readOnly
|
||||
disabled={((goods.canBuyNumber ?? 0) !== 0) && !isTicketTemplateActive}
|
||||
onChange={handleQuantityChange}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
{goods.stock !== undefined && (
|
||||
<Text className={'text-xs text-gray-400'}>
|
||||
库存 {goods.stock} 件
|
||||
|
||||
@@ -3,7 +3,7 @@ import {Cell, CellGroup, Image, Space, Button, Dialog} from '@nutui/nutui-react-
|
||||
import Taro from '@tarojs/taro'
|
||||
import {View} from '@tarojs/components'
|
||||
import {ShopOrder} from "@/api/shop/shopOrder/model";
|
||||
import {getShopOrder, updateShopOrder, refundShopOrder} from "@/api/shop/shopOrder";
|
||||
import {getShopOrder, updateShopOrder} from "@/api/shop/shopOrder";
|
||||
import {listShopOrderGoods} from "@/api/shop/shopOrderGoods";
|
||||
import {ShopOrderGoods} from "@/api/shop/shopOrderGoods/model";
|
||||
import dayjs from "dayjs";
|
||||
@@ -69,7 +69,7 @@ const OrderDetail = () => {
|
||||
Taro.showLoading({ title: '提交中...' })
|
||||
|
||||
// 退款相关操作使用退款接口:PUT /api/shop/shop-order/refund
|
||||
await refundShopOrder({
|
||||
await updateShopOrder({
|
||||
orderId: order.orderId,
|
||||
refundMoney: order.payPrice || order.totalPrice,
|
||||
orderStatus: 7
|
||||
|
||||
@@ -47,6 +47,7 @@ const AddUserAddress = () => {
|
||||
const [FormData, setFormData] = useState<ShopUserAddress>({})
|
||||
const [inputText, setInputText] = useState<string>('')
|
||||
const [selectedLocation, setSelectedLocation] = useState<SelectedLocation | null>(null)
|
||||
const [regionLocked, setRegionLocked] = useState(false)
|
||||
const formRef = useRef<any>(null)
|
||||
const wxDraftRef = useRef<Partial<ShopUserAddress> | null>(null)
|
||||
const wxDraftPatchedRef = useRef(false)
|
||||
@@ -120,7 +121,12 @@ const AddUserAddress = () => {
|
||||
// 设置所在地区
|
||||
setText(`${address.province} ${address.city} ${address.region}`)
|
||||
// 回显已保存的经纬度(编辑模式)
|
||||
if (hasValidLngLat(address)) setSelectedLocation({ lng: String(address.lng), lat: String(address.lat) })
|
||||
if (hasValidLngLat(address)) {
|
||||
setSelectedLocation({ lng: String(address.lng), lat: String(address.lat) })
|
||||
setRegionLocked(true)
|
||||
} else {
|
||||
setRegionLocked(false)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载地址失败:', error)
|
||||
Taro.showToast({
|
||||
@@ -172,30 +178,39 @@ const AddUserAddress = () => {
|
||||
const result = parseAddressText(inputText);
|
||||
|
||||
// 更新表单数据
|
||||
const newFormData = {
|
||||
const newFormData: any = {
|
||||
...FormData,
|
||||
name: result.name || FormData.name,
|
||||
phone: result.phone || FormData.phone,
|
||||
address: result.address || FormData.address,
|
||||
province: result.province || FormData.province,
|
||||
city: result.city || FormData.city,
|
||||
region: result.region || FormData.region
|
||||
address: result.address || FormData.address
|
||||
};
|
||||
|
||||
if (!regionLocked) {
|
||||
newFormData.province = result.province || FormData.province
|
||||
newFormData.city = result.city || FormData.city
|
||||
newFormData.region = result.region || FormData.region
|
||||
}
|
||||
|
||||
setFormData(newFormData);
|
||||
|
||||
// 更新地区显示文本
|
||||
if (result.province && result.city && result.region) {
|
||||
if (!regionLocked && result.province && result.city && result.region) {
|
||||
setText(`${result.province} ${result.city} ${result.region}`);
|
||||
}
|
||||
|
||||
// 更新表单字段值
|
||||
if (formRef.current) {
|
||||
formRef.current.setFieldsValue(newFormData);
|
||||
const patch: any = {
|
||||
name: newFormData.name,
|
||||
phone: newFormData.phone,
|
||||
address: newFormData.address
|
||||
}
|
||||
if (!regionLocked && newFormData.region) patch.region = newFormData.region
|
||||
formRef.current.setFieldsValue(patch);
|
||||
}
|
||||
|
||||
Taro.showToast({
|
||||
title: '识别成功',
|
||||
title: regionLocked ? '识别成功(所在地区以定位为准)' : '识别成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
@@ -311,7 +326,6 @@ const AddUserAddress = () => {
|
||||
name: res.name,
|
||||
address: res.address
|
||||
}
|
||||
setSelectedLocation(next)
|
||||
|
||||
// 尝试从地图返回的 address 文本解析省市区(best-effort)
|
||||
const regionResult = res?.provinceName || res?.cityName || res?.adName
|
||||
@@ -322,15 +336,22 @@ const AddUserAddress = () => {
|
||||
}
|
||||
: parseRegion(String(res.address || ''))
|
||||
|
||||
const province = String(regionResult?.province || '').trim()
|
||||
const city = String(regionResult?.city || '').trim()
|
||||
const region = String(regionResult?.region || '').trim()
|
||||
if (!province || !city || !region) {
|
||||
Taro.showToast({ title: '定位未识别到所在地区,请重新选择定位', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
setSelectedLocation(next)
|
||||
setRegionLocked(true)
|
||||
|
||||
// 将地图选点的地址同步到“收货地址”(不额外拼接省市区字段,省市区由独立字段保存)
|
||||
const nextDetailAddress = (() => {
|
||||
const rawAddr = String(res.address || '').trim()
|
||||
const name = String(res.name || '').trim()
|
||||
|
||||
const province = String(regionResult?.province || '').trim()
|
||||
const city = String(regionResult?.city || '').trim()
|
||||
const region = String(regionResult?.region || '').trim()
|
||||
|
||||
// 选择定位返回的 address 往往包含省市区,这里尽量剥离掉,避免和表单的省市区字段重复
|
||||
let detail = rawAddr
|
||||
for (const part of [province, city, region]) {
|
||||
@@ -350,20 +371,18 @@ const AddUserAddress = () => {
|
||||
lng: next.lng,
|
||||
lat: next.lat,
|
||||
address: nextDetailAddress || prev.address,
|
||||
province: regionResult?.province || prev.province,
|
||||
city: regionResult?.city || prev.city,
|
||||
region: regionResult?.region || prev.region
|
||||
province,
|
||||
city,
|
||||
region
|
||||
}))
|
||||
|
||||
if (regionResult?.province && regionResult?.city && regionResult?.region) {
|
||||
setText(`${regionResult.province} ${regionResult.city} ${regionResult.region}`)
|
||||
}
|
||||
setText(`${province} ${city} ${region}`)
|
||||
|
||||
// 更新表单展示值(Form initialValues 不会跟随 FormData 变化)
|
||||
if (formRef.current) {
|
||||
const patch: any = {}
|
||||
if (nextDetailAddress) patch.address = nextDetailAddress
|
||||
if (regionResult?.region) patch.region = regionResult.region
|
||||
patch.region = region
|
||||
formRef.current.setFieldsValue(patch)
|
||||
}
|
||||
}
|
||||
@@ -407,6 +426,14 @@ const AddUserAddress = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const openRegionPicker = () => {
|
||||
if (regionLocked) {
|
||||
Taro.showToast({ title: '所在地区已由定位确定,修改请重新选择定位', icon: 'none' })
|
||||
return
|
||||
}
|
||||
setVisible(true)
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitSucceed = async (values: any) => {
|
||||
const loc =
|
||||
@@ -416,6 +443,10 @@ const AddUserAddress = () => {
|
||||
Taro.showToast({ title: '请选择定位', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!FormData.province || !FormData.city || !FormData.region) {
|
||||
Taro.showToast({ title: '请先选择定位以自动填写所在地区', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备提交的数据
|
||||
@@ -487,6 +518,12 @@ const AddUserAddress = () => {
|
||||
})
|
||||
}, [fromWx, isEditMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!regionLocked) return
|
||||
if (!visible) return
|
||||
setVisible(false)
|
||||
}, [regionLocked, visible])
|
||||
|
||||
// NutUI Form 的 initialValues 在首次渲染后不再响应更新;微信导入时做一次 setFieldsValue 兜底回填。
|
||||
useEffect(() => {
|
||||
if (loading) return
|
||||
@@ -523,7 +560,7 @@ const AddUserAddress = () => {
|
||||
onFinishFailed={(errors) => submitFailed(errors)}
|
||||
>
|
||||
<CellGroup className={'px-3'}>
|
||||
<div
|
||||
<View
|
||||
style={{
|
||||
border: '1px dashed #22c55e',
|
||||
display: 'flex',
|
||||
@@ -549,7 +586,7 @@ const AddUserAddress = () => {
|
||||
>
|
||||
识别
|
||||
</Button>
|
||||
</div>
|
||||
</View>
|
||||
</CellGroup>
|
||||
<View className={'bg-gray-100 h-3'}></View>
|
||||
<CellGroup style={{padding: '4px 0'}}>
|
||||
@@ -581,10 +618,10 @@ const AddUserAddress = () => {
|
||||
rules={[{message: '请输入您的所在地区'}]}
|
||||
required
|
||||
>
|
||||
<div className={'flex justify-between items-center'} onClick={() => setVisible(true)}>
|
||||
<View className={'flex justify-between items-center'} onClick={openRegionPicker}>
|
||||
<Input placeholder="选择所在地区" value={text} disabled/>
|
||||
<ArrowRight className={'text-gray-400'}/>
|
||||
</div>
|
||||
</View>
|
||||
</Form.Item>
|
||||
<Form.Item name="address" label="收货地址" initialValue={FormData.address} required>
|
||||
<TextArea maxLength={50} placeholder="请输入详细收货地址"/>
|
||||
@@ -598,15 +635,15 @@ const AddUserAddress = () => {
|
||||
(selectedLocation ? `经纬度:${selectedLocation.lng}, ${selectedLocation.lat}` : '用于计算是否超出配送范围')
|
||||
}
|
||||
extra={(
|
||||
<div className={'flex items-center gap-2'}>
|
||||
<div
|
||||
<View className={'flex items-center gap-2'}>
|
||||
<View
|
||||
className={'text-gray-900 text-sm'}
|
||||
style={{maxWidth: '200px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap'}}
|
||||
>
|
||||
{selectedLocation?.name || (selectedLocation ? '已选择' : '请选择')}
|
||||
</div>
|
||||
</View>
|
||||
<ArrowRight className={'text-gray-400'}/>
|
||||
</div>
|
||||
</View>
|
||||
)}
|
||||
onClick={chooseGeoLocation}
|
||||
/>
|
||||
@@ -618,6 +655,10 @@ const AddUserAddress = () => {
|
||||
options={optionsDemo1}
|
||||
title="选择地址"
|
||||
onChange={(value, _) => {
|
||||
if (regionLocked) {
|
||||
Taro.showToast({ title: '所在地区已由定位确定,修改请重新选择定位', icon: 'none' })
|
||||
return
|
||||
}
|
||||
setFormData({
|
||||
...FormData,
|
||||
province: `${value[0]}`,
|
||||
|
||||
@@ -104,6 +104,10 @@ interface OrderListProps {
|
||||
baseParams?: ShopOrderParam;
|
||||
// 只读模式:隐藏“支付/取消/确认收货/退款”等用户操作按钮
|
||||
readOnly?: boolean;
|
||||
// 是否自动取消“支付已过期”的待支付订单(仅 user 模式生效)
|
||||
autoCancelExpired?: boolean;
|
||||
// 支付超时时间(小时),默认 24 小时
|
||||
paymentTimeoutHours?: number;
|
||||
}
|
||||
|
||||
function OrderList(props: OrderListProps) {
|
||||
@@ -111,6 +115,8 @@ function OrderList(props: OrderListProps) {
|
||||
const pageRef = useRef(1)
|
||||
const [hasMore, setHasMore] = useState(true)
|
||||
const [payingOrderId, setPayingOrderId] = useState<number | null>(null)
|
||||
const autoCanceledOrderIdsRef = useRef<Set<number>>(new Set())
|
||||
const autoCancelRunningRef = useRef(false)
|
||||
// 根据传入的statusFilter设置初始tab索引
|
||||
const getInitialTabIndex = () => {
|
||||
if (props.searchParams?.statusFilter !== undefined) {
|
||||
@@ -132,61 +138,92 @@ function OrderList(props: OrderListProps) {
|
||||
const [orderToConfirmReceive, setOrderToConfirmReceive] = useState<ShopOrder | null>(null)
|
||||
const isReadOnly = props.readOnly || props.mode === 'store' || props.mode === 'rider'
|
||||
|
||||
const isOrderCompleted = (order: ShopOrder) => Number(order.orderStatus) === 1 || order.formId === 10074;
|
||||
const toNum = (v: any): number | undefined => {
|
||||
if (v === null || v === undefined || v === '') return undefined;
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) ? n : undefined;
|
||||
};
|
||||
|
||||
const parseTime = (raw: any): dayjs.Dayjs | null => {
|
||||
const text = String(raw ?? '').trim();
|
||||
if (!text) return null;
|
||||
const t = /^\d+$/.test(text)
|
||||
? dayjs(Number(text) < 1e12 ? Number(text) * 1000 : Number(text))
|
||||
: dayjs(text);
|
||||
return t.isValid() ? t : null;
|
||||
};
|
||||
|
||||
const isOrderPaymentExpiredSafe = (order: ShopOrder, timeoutHours: number) => {
|
||||
if (order.payStatus) return false;
|
||||
if (toNum(order.orderStatus) === 2) return false;
|
||||
|
||||
const expiration = parseTime(order.expirationTime);
|
||||
if (expiration) return dayjs().isAfter(expiration);
|
||||
|
||||
if (order.createTime) return isPaymentExpired(order.createTime, timeoutHours);
|
||||
return false;
|
||||
};
|
||||
|
||||
// “已完成”应以订单状态为准;不要用商品ID等字段推断完成态,否则会造成 Tab(待发货/待收货) 与状态文案不同步
|
||||
const isOrderCompleted = (order: ShopOrder) => toNum(order.orderStatus) === 1;
|
||||
|
||||
// 获取订单状态文本
|
||||
const getOrderStatusText = (order: ShopOrder) => {
|
||||
const orderStatus = toNum(order.orderStatus);
|
||||
const deliveryStatus = toNum(order.deliveryStatus);
|
||||
|
||||
// 优先检查订单状态
|
||||
if (order.orderStatus === 2) return '已取消';
|
||||
if (order.orderStatus === 4) return '退款申请中';
|
||||
if (order.orderStatus === 5) return '退款被拒绝';
|
||||
if (order.orderStatus === 6) return '退款成功';
|
||||
if (order.orderStatus === 7) return '客户端申请退款';
|
||||
if (orderStatus === 2) return '已取消';
|
||||
if (orderStatus === 4) return '退款申请中';
|
||||
if (orderStatus === 5) return '退款被拒绝';
|
||||
if (orderStatus === 6) return '退款成功';
|
||||
if (orderStatus === 7) return '客户端申请退款';
|
||||
if (isOrderCompleted(order)) return '已完成';
|
||||
|
||||
// 检查支付状态 (payStatus为boolean类型,false/0表示未付款,true/1表示已付款)
|
||||
if (!order.payStatus) return '等待买家付款';
|
||||
|
||||
// 已付款后检查发货状态
|
||||
if (order.deliveryStatus === 10) return '待发货';
|
||||
if (order.deliveryStatus === 20) {
|
||||
if (deliveryStatus === 10) return '待发货';
|
||||
if (deliveryStatus === 20) {
|
||||
// 若订单没有配送员,沿用原“待收货”语义
|
||||
if (!order.riderId || Number(order.riderId) === 0) return '待收货';
|
||||
// 配送员确认送达后(sendEndTime有值),才进入“待确认收货”
|
||||
if (order.sendEndTime && !isOrderCompleted(order)) return '待确认收货';
|
||||
return '配送中';
|
||||
}
|
||||
if (order.deliveryStatus === 30) return '部分发货';
|
||||
if (deliveryStatus === 30) return '部分发货';
|
||||
|
||||
if (order.orderStatus === 0) return '未使用';
|
||||
if (orderStatus === 0) return '未使用';
|
||||
|
||||
return '未知状态';
|
||||
};
|
||||
|
||||
// 获取订单状态颜色
|
||||
const getOrderStatusColor = (order: ShopOrder) => {
|
||||
const orderStatus = toNum(order.orderStatus);
|
||||
const deliveryStatus = toNum(order.deliveryStatus);
|
||||
// 优先检查订单状态
|
||||
if (order.orderStatus === 2) return 'text-gray-500'; // 已取消
|
||||
if (order.orderStatus === 4) return 'text-orange-500'; // 退款申请中
|
||||
if (order.orderStatus === 5) return 'text-red-500'; // 退款被拒绝
|
||||
if (order.orderStatus === 6) return 'text-green-500'; // 退款成功
|
||||
if (order.orderStatus === 7) return 'text-orange-500'; // 客户端申请退款
|
||||
if (orderStatus === 2) return 'text-gray-500'; // 已取消
|
||||
if (orderStatus === 4) return 'text-orange-500'; // 退款申请中
|
||||
if (orderStatus === 5) return 'text-red-500'; // 退款被拒绝
|
||||
if (orderStatus === 6) return 'text-green-500'; // 退款成功
|
||||
if (orderStatus === 7) return 'text-orange-500'; // 客户端申请退款
|
||||
if (isOrderCompleted(order)) return 'text-green-600'; // 已完成
|
||||
|
||||
// 检查支付状态
|
||||
if (!order.payStatus) return 'text-orange-500'; // 等待买家付款
|
||||
|
||||
// 已付款后检查发货状态
|
||||
if (order.deliveryStatus === 10) return 'text-blue-500'; // 待发货
|
||||
if (order.deliveryStatus === 20) {
|
||||
if (deliveryStatus === 10) return 'text-blue-500'; // 待发货
|
||||
if (deliveryStatus === 20) {
|
||||
if (!order.riderId || Number(order.riderId) === 0) return 'text-purple-500'; // 待收货
|
||||
if (order.sendEndTime && !isOrderCompleted(order)) return 'text-purple-500'; // 待确认收货
|
||||
return 'text-blue-500'; // 配送中
|
||||
}
|
||||
if (order.deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
||||
if (deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
||||
|
||||
if (order.orderStatus === 0) return 'text-gray-500'; // 未使用
|
||||
if (orderStatus === 0) return 'text-gray-500'; // 未使用
|
||||
|
||||
return 'text-gray-600'; // 默认颜色
|
||||
};
|
||||
@@ -237,24 +274,82 @@ function OrderList(props: OrderListProps) {
|
||||
finalStatusFilter: searchConditions.statusFilter
|
||||
});
|
||||
|
||||
try {
|
||||
const res = await pageShopOrder(searchConditions);
|
||||
try {
|
||||
const timeoutHours = typeof props.paymentTimeoutHours === 'number' ? props.paymentTimeoutHours : 24;
|
||||
const canAutoCancelExpired =
|
||||
!!props.autoCancelExpired &&
|
||||
(!props.mode || props.mode === 'user') &&
|
||||
!props.readOnly;
|
||||
const isPendingPayList = statusParams.statusFilter === 0;
|
||||
|
||||
if (res?.list && res?.list.length > 0) {
|
||||
const fetchOrders = async () => pageShopOrder(searchConditions);
|
||||
|
||||
let res = await fetchOrders();
|
||||
let incoming = (res?.list || []) as ShopOrder[];
|
||||
let rawIncomingLength = incoming.length;
|
||||
|
||||
// 自动取消“支付已过期”的待支付订单(避免用户看到一堆不可支付的过期单)
|
||||
if (canAutoCancelExpired && incoming.length && !autoCancelRunningRef.current) {
|
||||
const expiredToCancel = incoming
|
||||
.filter(o => !!o?.orderId)
|
||||
.filter(o => !autoCanceledOrderIdsRef.current.has(o.orderId as number))
|
||||
.filter(o => isOrderPaymentExpiredSafe(o, timeoutHours));
|
||||
|
||||
if (expiredToCancel.length) {
|
||||
autoCancelRunningRef.current = true;
|
||||
const justCanceled = new Set<number>();
|
||||
try {
|
||||
// 单次最多处理 20 笔,避免接口风暴
|
||||
for (const order of expiredToCancel.slice(0, 20)) {
|
||||
try {
|
||||
await updateShopOrder({ orderId: order.orderId, orderStatus: 2 });
|
||||
autoCanceledOrderIdsRef.current.add(order.orderId as number);
|
||||
justCanceled.add(order.orderId as number);
|
||||
} catch (e) {
|
||||
console.warn('自动取消过期订单失败:', order?.orderId, e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
autoCancelRunningRef.current = false;
|
||||
}
|
||||
|
||||
if (justCanceled.size > 0) {
|
||||
if (resetPage) {
|
||||
// resetPage 时重新拉取一次,确保列表状态与服务端一致
|
||||
res = await fetchOrders();
|
||||
incoming = (res?.list || []) as ShopOrder[];
|
||||
rawIncomingLength = incoming.length;
|
||||
Taro.showToast({ title: '已自动取消过期订单', icon: 'none' });
|
||||
} else {
|
||||
// loadMore 时不重新拉取,避免破坏滚动;仅在本地列表中做最小同步
|
||||
if (isPendingPayList) {
|
||||
incoming = incoming.filter(o => !justCanceled.has(o.orderId as number));
|
||||
} else {
|
||||
incoming = incoming.map(o => (
|
||||
justCanceled.has(o.orderId as number) ? { ...o, orderStatus: 2 } : o
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rawIncomingLength > 0) {
|
||||
// 订单分页接口已返回 orderGoods:列表直接使用该字段
|
||||
const incoming = res.list as ShopOrder[];
|
||||
|
||||
// 使用函数式更新避免依赖 list
|
||||
setList(prevList => {
|
||||
const newList = resetPage ? incoming : (prevList || []).concat(incoming);
|
||||
return newList;
|
||||
});
|
||||
if (incoming.length > 0) {
|
||||
setList(prevList => (resetPage ? incoming : (prevList || []).concat(incoming)));
|
||||
} else {
|
||||
// 本页数据全部被自动取消过滤掉:不清空历史列表,仅保持现状
|
||||
setList(prevList => (resetPage ? [] : prevList));
|
||||
}
|
||||
|
||||
// 正确判断是否还有更多数据
|
||||
const hasMoreData = incoming.length >= 10; // 假设每页10条数据
|
||||
// 正确判断是否还有更多数据(以服务端返回条数为准)
|
||||
const hasMoreData = rawIncomingLength >= 10; // 假设每页10条数据
|
||||
setHasMore(hasMoreData);
|
||||
} else {
|
||||
setList(prevList => resetPage ? [] : prevList);
|
||||
// 服务端已无更多数据
|
||||
setList(prevList => (resetPage ? [] : prevList));
|
||||
setHasMore(false);
|
||||
}
|
||||
|
||||
@@ -270,7 +365,7 @@ function OrderList(props: OrderListProps) {
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}, [tapIndex, props.searchParams]); // 移除 list/page 依赖,避免useEffect触发循环
|
||||
}, [tapIndex, props.searchParams, props.baseParams, props.mode, props.readOnly, props.autoCancelExpired, props.paymentTimeoutHours]); // 移除 list/page 依赖,避免useEffect触发循环
|
||||
|
||||
const reloadMore = useCallback(async () => {
|
||||
if (loading || !hasMore) return; // 防止重复加载
|
||||
@@ -712,17 +807,20 @@ function OrderList(props: OrderListProps) {
|
||||
{/* 订单列表 */}
|
||||
{list.length > 0 && list
|
||||
?.filter((item) => {
|
||||
const orderStatus = toNum(item.orderStatus);
|
||||
// “待收货”不展示退款中的/已退款订单,这些订单统一放到“退货/售后”
|
||||
if (tapIndex === 3 && (item.orderStatus === 4 || item.orderStatus === 6)) {
|
||||
if (tapIndex === 3 && (orderStatus === 4 || orderStatus === 6)) {
|
||||
return false;
|
||||
}
|
||||
// “退货/售后”只展示售后相关状态
|
||||
if (tapIndex === 5) {
|
||||
return item.orderStatus === 4 || item.orderStatus === 5 || item.orderStatus === 6 || item.orderStatus === 7;
|
||||
return orderStatus === 4 || orderStatus === 5 || orderStatus === 6 || orderStatus === 7;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
?.map((item, index) => {
|
||||
const orderStatus = toNum(item.orderStatus);
|
||||
const deliveryStatus = toNum(item.deliveryStatus);
|
||||
return (
|
||||
<Cell key={item.orderId ?? item.orderNo ?? index} style={{padding: '16px'}}
|
||||
onClick={() => Taro.navigateTo({url: `/shop/orderDetail/index?orderId=${item.orderId}`})}>
|
||||
@@ -737,7 +835,7 @@ function OrderList(props: OrderListProps) {
|
||||
</View>
|
||||
{/* 右侧显示合并的状态和倒计时 */}
|
||||
<View className={`${getOrderStatusColor(item)} font-medium`}>
|
||||
{!item.payStatus && item.orderStatus !== 2 ? (
|
||||
{!item.payStatus && orderStatus !== 2 ? (
|
||||
<PaymentCountdown
|
||||
expirationTime={item.expirationTime}
|
||||
createTime={item.createTime}
|
||||
@@ -801,23 +899,23 @@ function OrderList(props: OrderListProps) {
|
||||
{!isReadOnly && (
|
||||
<Space className={'btn flex justify-end'}>
|
||||
{/* 待付款状态:显示取消订单和立即支付 */}
|
||||
{(!item.payStatus) && item.orderStatus !== 2 && (
|
||||
{(!item.payStatus) && orderStatus !== 2 && (
|
||||
<Space>
|
||||
<Button size={'small'} onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
void cancelOrder(item);
|
||||
}}>取消订单</Button>
|
||||
}}>取消</Button>
|
||||
{(!item.createTime || !isPaymentExpired(item.createTime, 24)) && (
|
||||
<Button size={'small'} type="primary" onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
void payOrder(item);
|
||||
}}>立即支付</Button>
|
||||
}}>继续支付</Button>
|
||||
)}
|
||||
</Space>
|
||||
)}
|
||||
|
||||
{/* 待发货状态:显示申请退款 */}
|
||||
{item.payStatus && isWithinRefundWindow(item.payTime, 60) && item.deliveryStatus === 10 && item.orderStatus !== 2 && item.orderStatus !== 4 && item.orderStatus !== 6 && item.orderStatus !== 7 && !isOrderCompleted(item) && (
|
||||
{item.payStatus && isWithinRefundWindow(item.payTime, 60) && deliveryStatus === 10 && orderStatus !== 2 && orderStatus !== 4 && orderStatus !== 6 && orderStatus !== 7 && !isOrderCompleted(item) && (
|
||||
<Button size={'small'} onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
applyRefund(item);
|
||||
@@ -825,7 +923,7 @@ function OrderList(props: OrderListProps) {
|
||||
)}
|
||||
|
||||
{/* 待收货状态:显示查看物流和确认收货 */}
|
||||
{item.deliveryStatus === 20 && (!item.riderId || Number(item.riderId) === 0 || !!item.sendEndTime) && item.orderStatus !== 2 && item.orderStatus !== 6 && !isOrderCompleted(item) && (
|
||||
{deliveryStatus === 20 && (!item.riderId || Number(item.riderId) === 0 || !!item.sendEndTime) && orderStatus !== 2 && orderStatus !== 6 && !isOrderCompleted(item) && (
|
||||
<Space>
|
||||
{/*<Button size={'small'} onClick={(e) => {*/}
|
||||
{/* e.stopPropagation();*/}
|
||||
@@ -839,7 +937,7 @@ function OrderList(props: OrderListProps) {
|
||||
)}
|
||||
|
||||
{/* 退款/售后状态:显示查看进度和撤销申请 */}
|
||||
{(item.orderStatus === 4 || item.orderStatus === 7) && (
|
||||
{(orderStatus === 4 || orderStatus === 7) && (
|
||||
<Space>
|
||||
{/*<Button size={'small'} onClick={(e) => {*/}
|
||||
{/* e.stopPropagation();*/}
|
||||
|
||||
@@ -164,6 +164,7 @@ function Order() {
|
||||
onReload={() => reload(searchParams)}
|
||||
searchParams={searchParams}
|
||||
showSearch={showSearch}
|
||||
autoCancelExpired
|
||||
onSearchParamsChange={(newParams) => {
|
||||
console.log('父组件接收到searchParams变化:', newParams);
|
||||
setSearchParams(newParams);
|
||||
|
||||
@@ -16,7 +16,7 @@ import { ArrowRight, Location, Ticket } from '@nutui/icons-react-taro'
|
||||
import dayjs from 'dayjs'
|
||||
import type { ShopGoods } from '@/api/shop/shopGoods/model'
|
||||
import { getShopGoods } from '@/api/shop/shopGoods'
|
||||
import { listShopUserAddress } from '@/api/shop/shopUserAddress'
|
||||
import { getShopUserAddress, listShopUserAddress } from '@/api/shop/shopUserAddress'
|
||||
import type { ShopUserAddress } from '@/api/shop/shopUserAddress/model'
|
||||
import './use.scss'
|
||||
import Gap from "@/components/Gap";
|
||||
@@ -27,6 +27,8 @@ import {getSelectedStoreFromStorage, saveSelectedStoreToStorage} from "@/utils/s
|
||||
import type { GltUserTicket } from '@/api/glt/gltUserTicket/model'
|
||||
import { listGltUserTicket } from '@/api/glt/gltUserTicket'
|
||||
import { addGltTicketOrder } from '@/api/glt/gltTicketOrder'
|
||||
import { pageGltTicketOrder } from '@/api/glt/gltTicketOrder'
|
||||
import type { GltTicketOrder } from '@/api/glt/gltTicketOrder/model'
|
||||
import type { ShopStoreRider } from '@/api/shop/shopStoreRider/model'
|
||||
import { listShopStoreRider } from '@/api/shop/shopStoreRider'
|
||||
import type { ShopStoreFence } from '@/api/shop/shopStoreFence/model'
|
||||
@@ -34,6 +36,7 @@ import { listShopStoreFence } from '@/api/shop/shopStoreFence'
|
||||
import { parseFencePoints, parseLngLatFromText, pointInAnyPolygon, pointInPolygon } from '@/utils/geofence'
|
||||
|
||||
const MIN_START_QTY = 10
|
||||
const ADDRESS_CHANGE_COOLDOWN_DAYS = 30
|
||||
|
||||
const OrderConfirm = () => {
|
||||
const [goods, setGoods] = useState<ShopGoods | null>(null);
|
||||
@@ -81,6 +84,8 @@ const OrderConfirm = () => {
|
||||
const [deliveryRangeChecking, setDeliveryRangeChecking] = useState(false)
|
||||
const deliveryRangeCheckingRef = useRef(false)
|
||||
const [inDeliveryRange, setInDeliveryRange] = useState<boolean | undefined>(undefined)
|
||||
// Prevent using stale `inDeliveryRange` from a previous address when user switches addresses.
|
||||
const [deliveryRangeCheckedAddressId, setDeliveryRangeCheckedAddressId] = useState<number | undefined>(undefined)
|
||||
|
||||
const router = Taro.getCurrentInstance().router;
|
||||
const goodsId = router?.params?.goodsId;
|
||||
@@ -95,6 +100,137 @@ const OrderConfirm = () => {
|
||||
return Number.isFinite(id) && id > 0 ? id : undefined
|
||||
}, [])
|
||||
|
||||
type TicketAddressModifyLimit = {
|
||||
loaded: boolean
|
||||
canModify: boolean
|
||||
nextAllowedText?: string
|
||||
lockedAddressId?: number
|
||||
}
|
||||
const [ticketAddressModifyLimit, setTicketAddressModifyLimit] = useState<TicketAddressModifyLimit>({
|
||||
loaded: false,
|
||||
canModify: true,
|
||||
})
|
||||
const ticketAddressModifyLimitPromiseRef = useRef<Promise<TicketAddressModifyLimit> | null>(null)
|
||||
|
||||
const parseTime = (raw?: unknown) => {
|
||||
if (raw === undefined || raw === null || raw === '') return null
|
||||
// Compatible with seconds/milliseconds timestamps.
|
||||
if (typeof raw === 'number' || (typeof raw === 'string' && /^\d+$/.test(raw))) {
|
||||
const n = Number(raw)
|
||||
if (!Number.isFinite(n)) return null
|
||||
return dayjs(n < 1e12 ? n * 1000 : n)
|
||||
}
|
||||
const d = dayjs(raw as any)
|
||||
return d.isValid() ? d : null
|
||||
}
|
||||
|
||||
const getOrderTime = (o?: Partial<GltTicketOrder> | null) => {
|
||||
return parseTime(o?.createTime) || parseTime(o?.updateTime)
|
||||
}
|
||||
|
||||
const getOrderAddressKey = (o?: Partial<GltTicketOrder> | null) => {
|
||||
const id = Number(o?.addressId)
|
||||
if (Number.isFinite(id) && id > 0) return `id:${id}`
|
||||
const txt = String(o?.address || '').trim()
|
||||
if (txt) return `txt:${txt}`
|
||||
return ''
|
||||
}
|
||||
|
||||
const loadTicketAddressModifyLimit = async (): Promise<TicketAddressModifyLimit> => {
|
||||
if (ticketAddressModifyLimitPromiseRef.current) return ticketAddressModifyLimitPromiseRef.current
|
||||
|
||||
ticketAddressModifyLimitPromiseRef.current = (async () => {
|
||||
if (!userId) return { loaded: true, canModify: true }
|
||||
|
||||
const now = dayjs()
|
||||
const pageSize = 20
|
||||
let page = 1
|
||||
const all: GltTicketOrder[] = []
|
||||
|
||||
let latestKey = ''
|
||||
let latestAddressId: number | undefined = undefined
|
||||
|
||||
while (true) {
|
||||
const res = await pageGltTicketOrder({ page, limit: pageSize, userId })
|
||||
const list = Array.isArray(res?.list) ? res.list : []
|
||||
if (page === 1) {
|
||||
const first = list[0]
|
||||
latestKey = getOrderAddressKey(first)
|
||||
const id = Number(first?.addressId)
|
||||
latestAddressId = Number.isFinite(id) && id > 0 ? id : undefined
|
||||
}
|
||||
|
||||
if (!list.length) break
|
||||
all.push(...list)
|
||||
|
||||
// Find the oldest order in the newest contiguous block of the latest address key.
|
||||
// That order's time represents the last time user "set/changed" the ticket delivery address.
|
||||
const currentKey = latestKey
|
||||
if (!currentKey) {
|
||||
return { loaded: true, canModify: true }
|
||||
}
|
||||
|
||||
let lastSameIndex = 0
|
||||
let foundDifferent = false
|
||||
for (let i = 1; i < all.length; i++) {
|
||||
const k = getOrderAddressKey(all[i])
|
||||
if (!k) continue
|
||||
if (k === currentKey) {
|
||||
lastSameIndex = i
|
||||
continue
|
||||
}
|
||||
foundDifferent = true
|
||||
break
|
||||
}
|
||||
|
||||
if (foundDifferent) {
|
||||
const lastSetAt = getOrderTime(all[lastSameIndex])
|
||||
if (!lastSetAt) return { loaded: true, canModify: true, lockedAddressId: latestAddressId }
|
||||
const nextAllowed = lastSetAt.add(ADDRESS_CHANGE_COOLDOWN_DAYS, 'day')
|
||||
const canModify = now.isAfter(nextAllowed)
|
||||
return {
|
||||
loaded: true,
|
||||
canModify,
|
||||
nextAllowedText: nextAllowed.format('YYYY-MM-DD'),
|
||||
lockedAddressId: latestAddressId,
|
||||
}
|
||||
}
|
||||
|
||||
const oldest = getOrderTime(all[all.length - 1])
|
||||
if (oldest && now.diff(oldest, 'day') >= ADDRESS_CHANGE_COOLDOWN_DAYS) {
|
||||
// We have enough history beyond the cooldown window, and still no different address found.
|
||||
return { loaded: true, canModify: true, lockedAddressId: latestAddressId }
|
||||
}
|
||||
|
||||
const totalCount = typeof (res as any)?.count === 'number' ? Number((res as any).count) : undefined
|
||||
if (totalCount !== undefined && all.length >= totalCount) break
|
||||
if (list.length < pageSize) break
|
||||
|
||||
page += 1
|
||||
if (page > 10) break // safety: avoid excessive paging
|
||||
}
|
||||
|
||||
if (!all.length) return { loaded: true, canModify: true }
|
||||
|
||||
// If we can't prove the last-set time is older than the cooldown window, be conservative and lock.
|
||||
const lastSetAt = getOrderTime(all[all.length - 1])
|
||||
if (!lastSetAt) return { loaded: true, canModify: true, lockedAddressId: latestAddressId }
|
||||
const nextAllowed = lastSetAt.add(ADDRESS_CHANGE_COOLDOWN_DAYS, 'day')
|
||||
const canModify = now.isAfter(nextAllowed)
|
||||
return {
|
||||
loaded: true,
|
||||
canModify,
|
||||
nextAllowedText: nextAllowed.format('YYYY-MM-DD'),
|
||||
lockedAddressId: latestAddressId,
|
||||
}
|
||||
})()
|
||||
.finally(() => {
|
||||
ticketAddressModifyLimitPromiseRef.current = null
|
||||
})
|
||||
|
||||
return ticketAddressModifyLimitPromiseRef.current
|
||||
}
|
||||
|
||||
const getTicketAvailableQty = (t?: Partial<GltUserTicket> | null) => {
|
||||
if (!t) return 0
|
||||
const anyT: any = t
|
||||
@@ -197,6 +333,22 @@ const OrderConfirm = () => {
|
||||
return parseLngLatFromText((s.lngAndLat || s.location || '').trim())
|
||||
}
|
||||
|
||||
const openAddressPage = async () => {
|
||||
const limit = ticketAddressModifyLimit.loaded
|
||||
? ticketAddressModifyLimit
|
||||
: await loadTicketAddressModifyLimit().catch(() => ({ loaded: true, canModify: true } as TicketAddressModifyLimit))
|
||||
if (!ticketAddressModifyLimit.loaded) setTicketAddressModifyLimit(limit)
|
||||
|
||||
if (!limit.canModify) {
|
||||
Taro.showToast({
|
||||
title: `送水地址每${ADDRESS_CHANGE_COOLDOWN_DAYS}天可修改一次${limit.nextAllowedText ? ',' + limit.nextAllowedText + ' 后可修改' : ''}`,
|
||||
icon: 'none',
|
||||
})
|
||||
return
|
||||
}
|
||||
Taro.navigateTo({ url: '/user/address/index' })
|
||||
}
|
||||
|
||||
const loadFences = async (): Promise<ShopStoreFence[]> => {
|
||||
if (fencesLoadedRef.current) return fences
|
||||
if (fencesPromiseRef.current) return fencesPromiseRef.current
|
||||
@@ -249,12 +401,11 @@ const OrderConfirm = () => {
|
||||
}
|
||||
|
||||
const getCheckPoint = async (): Promise<{ lng: number; lat: number }> => {
|
||||
// Prefer address coords (delivery location). Fallback to current GPS if address doesn't have coords.
|
||||
// Immediate water delivery must validate by the delivery address coordinates.
|
||||
// Falling back to current GPS may allow ordering with an out-of-fence address.
|
||||
const byAddress = parseLngLatFromText(`${address?.lng || ''},${address?.lat || ''}`)
|
||||
if (byAddress) return byAddress
|
||||
|
||||
const loc = await Taro.getLocation({ type: 'gcj02' })
|
||||
return { lng: loc.longitude, lat: loc.latitude }
|
||||
throw new Error('该收货地址缺少经纬度,请在地址里选择地图定位后重试')
|
||||
}
|
||||
|
||||
const ensureInDeliveryRange = async (): Promise<boolean> => {
|
||||
@@ -265,6 +416,7 @@ const OrderConfirm = () => {
|
||||
const p = await getCheckPoint()
|
||||
const ok = await isPointInFence(p)
|
||||
setInDeliveryRange(ok)
|
||||
setDeliveryRangeCheckedAddressId(address?.id)
|
||||
if (!ok) {
|
||||
Taro.showToast({ title: '不在配送范围内,暂不支持下单', icon: 'none' })
|
||||
}
|
||||
@@ -272,30 +424,8 @@ const OrderConfirm = () => {
|
||||
} catch (e: any) {
|
||||
console.error('配送范围校验失败:', e)
|
||||
setInDeliveryRange(undefined)
|
||||
|
||||
const msg = String(e?.errMsg || e?.message || '')
|
||||
const denied =
|
||||
msg.includes('auth deny') ||
|
||||
msg.includes('authorize') ||
|
||||
msg.includes('permission') ||
|
||||
msg.includes('denied') ||
|
||||
msg.includes('scope.userLocation')
|
||||
|
||||
if (denied) {
|
||||
const r = await Taro.showModal({
|
||||
title: '需要定位权限',
|
||||
content: '下单前需要校验是否在配送范围内,请在设置中开启定位权限后重试。',
|
||||
confirmText: '去设置'
|
||||
})
|
||||
if (r.confirm) {
|
||||
try {
|
||||
await Taro.openSetting()
|
||||
} catch (_e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
// Note: we validate by address coords only; no GPS permission prompt here.
|
||||
|
||||
Taro.showToast({ title: e?.message || '配送范围校验失败,请稍后重试', icon: 'none' })
|
||||
return false
|
||||
@@ -505,6 +635,29 @@ const OrderConfirm = () => {
|
||||
return
|
||||
}
|
||||
|
||||
// Ticket delivery address is based on order snapshot. Enforce "once per 30 days" by latest ticket-order history.
|
||||
const limit = ticketAddressModifyLimit.loaded
|
||||
? ticketAddressModifyLimit
|
||||
: await loadTicketAddressModifyLimit().catch(() => ({ loaded: true, canModify: true } as TicketAddressModifyLimit))
|
||||
if (!ticketAddressModifyLimit.loaded) setTicketAddressModifyLimit(limit)
|
||||
if (!limit.canModify && limit.lockedAddressId && address.id !== limit.lockedAddressId) {
|
||||
Taro.showToast({
|
||||
title: `送水地址每${ADDRESS_CHANGE_COOLDOWN_DAYS}天可修改一次,请使用上次下单地址${limit.nextAllowedText ? '(' + limit.nextAllowedText + ' 后可修改)' : ''}`,
|
||||
icon: 'none',
|
||||
})
|
||||
try {
|
||||
const locked = await getShopUserAddress(limit.lockedAddressId)
|
||||
if (locked?.id) setAddress(locked)
|
||||
} catch (_e) {
|
||||
// ignore: keep current address, but still block submission
|
||||
}
|
||||
return
|
||||
}
|
||||
if (!addressHasCoords) {
|
||||
Taro.showToast({ title: '该收货地址缺少经纬度,请在地址里选择地图定位后重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure ticket list is loaded.
|
||||
if (ticketLoading) {
|
||||
Taro.showToast({ title: '水票加载中,请稍后再试', icon: 'none' })
|
||||
@@ -634,6 +787,20 @@ const OrderConfirm = () => {
|
||||
if (addressRes && addressRes.length > 0) {
|
||||
setAddress(addressRes[0])
|
||||
}
|
||||
|
||||
// Load ticket-order history to enforce "address can be modified once per 30 days".
|
||||
// If currently locked, force using last ticket-order address (snapshot) to avoid getting stuck with a new default address.
|
||||
try {
|
||||
const limit = await loadTicketAddressModifyLimit()
|
||||
setTicketAddressModifyLimit(limit)
|
||||
if (!limit.canModify && limit.lockedAddressId) {
|
||||
const locked = await getShopUserAddress(limit.lockedAddressId)
|
||||
if (locked?.id) setAddress(locked)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载送水地址修改限制失败:', e)
|
||||
setTicketAddressModifyLimit({ loaded: true, canModify: true })
|
||||
}
|
||||
// Tickets are non-blocking for first paint; load in background.
|
||||
loadUserTickets()
|
||||
} catch (err) {
|
||||
@@ -655,6 +822,11 @@ const OrderConfirm = () => {
|
||||
loadAllData({ silent: hasInitialLoadedRef.current })
|
||||
})
|
||||
|
||||
const addressHasCoords = useMemo(() => {
|
||||
if (!address?.id) return false
|
||||
return !!parseLngLatFromText(`${address?.lng || ''},${address?.lat || ''}`)
|
||||
}, [address?.id, address?.lng, address?.lat])
|
||||
|
||||
// Auto-pick nearest store by delivery address (best-effort, won't override manual selection).
|
||||
useEffect(() => {
|
||||
if (!address?.id) return
|
||||
@@ -667,17 +839,35 @@ const OrderConfirm = () => {
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
if (!address?.id) {
|
||||
setInDeliveryRange(undefined)
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
return
|
||||
}
|
||||
const p = parseLngLatFromText(`${address?.lng || ''},${address?.lat || ''}`)
|
||||
if (!p) return
|
||||
if (!p) {
|
||||
// Cannot validate without address coords -> treat as out of range to block ordering.
|
||||
setInDeliveryRange(false)
|
||||
setDeliveryRangeCheckedAddressId(address.id)
|
||||
return
|
||||
}
|
||||
// Avoid keeping stale state from previous address while we validate this one.
|
||||
setInDeliveryRange(undefined)
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
let ok = true
|
||||
try {
|
||||
ok = await isPointInFence(p)
|
||||
} catch (_e) {
|
||||
// Pre-check is best-effort; don't block UI here.
|
||||
if (!cancelled) {
|
||||
setInDeliveryRange(undefined)
|
||||
setDeliveryRangeCheckedAddressId(undefined)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (cancelled) return
|
||||
setInDeliveryRange(ok)
|
||||
setDeliveryRangeCheckedAddressId(address.id)
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
@@ -685,6 +875,29 @@ const OrderConfirm = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [address?.id, address?.lng, address?.lat])
|
||||
|
||||
// When user changes the delivery address to an out-of-fence one, prompt immediately (once per address).
|
||||
const outOfRangePromptedAddressIdRef = useRef<number | undefined>(undefined)
|
||||
useEffect(() => {
|
||||
// Only prompt when user is allowed to change the ticket delivery address.
|
||||
// Otherwise this toast is noisy (they can't fix it within the cooldown window).
|
||||
if (!ticketAddressModifyLimit.loaded) return
|
||||
if (!ticketAddressModifyLimit.canModify) return
|
||||
const id = address?.id
|
||||
if (!id) return
|
||||
if (deliveryRangeCheckedAddressId !== id) return
|
||||
if (inDeliveryRange !== false) return
|
||||
if (outOfRangePromptedAddressIdRef.current === id) return
|
||||
outOfRangePromptedAddressIdRef.current = id
|
||||
Taro.showToast({ title: addressHasCoords ? '该地址不在配送范围,请更换围栏内地址' : '该地址缺少定位,请在地址里选择地图定位后重试', icon: 'none' })
|
||||
}, [
|
||||
address?.id,
|
||||
addressHasCoords,
|
||||
deliveryRangeCheckedAddressId,
|
||||
inDeliveryRange,
|
||||
ticketAddressModifyLimit.loaded,
|
||||
ticketAddressModifyLimit.canModify
|
||||
])
|
||||
|
||||
// When tickets/stock change, clamp quantity into [0..maxQuantity].
|
||||
useEffect(() => {
|
||||
setQuantity(prev => {
|
||||
@@ -758,10 +971,13 @@ const OrderConfirm = () => {
|
||||
{/* onClick={openStorePopup}*/}
|
||||
{/* />*/}
|
||||
{/*</CellGroup>*/}
|
||||
<CellGroup>
|
||||
{
|
||||
address && (
|
||||
<Cell className={'address-bottom-line'}>
|
||||
<CellGroup>
|
||||
{
|
||||
address && (
|
||||
<Cell
|
||||
className={'address-bottom-line'}
|
||||
onClick={openAddressPage}
|
||||
>
|
||||
<Space>
|
||||
<Location className={'text-gray-500'}/>
|
||||
<View className={'flex flex-col w-full justify-between items-start'}>
|
||||
@@ -773,14 +989,22 @@ const OrderConfirm = () => {
|
||||
<ArrowRight className={'text-gray-400'} size={14}/>
|
||||
</View>
|
||||
</Space>
|
||||
<View className={'pt-1 pb-3 text-gray-500'}>{address.name} {address.phone}</View>
|
||||
</View>
|
||||
</Space>
|
||||
</Cell>
|
||||
)
|
||||
}
|
||||
<View className={'pt-1 pb-3'}>
|
||||
<View className={'text-gray-500'}>{address.name} {address.phone}</View>
|
||||
{ticketAddressModifyLimit.loaded && !ticketAddressModifyLimit.canModify && (
|
||||
<View className={'pt-1 text-xs text-orange-500 hidden'}>
|
||||
送水地址每{ADDRESS_CHANGE_COOLDOWN_DAYS}天可修改一次
|
||||
{ticketAddressModifyLimit.nextAllowedText ? `,${ticketAddressModifyLimit.nextAllowedText} 后可修改` : ''}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
</Space>
|
||||
</Cell>
|
||||
)
|
||||
}
|
||||
{!address && (
|
||||
<Cell className={''} onClick={() => Taro.navigateTo({url: '/user/address/index'})}>
|
||||
<Cell className={''} onClick={openAddressPage}>
|
||||
<Space>
|
||||
<Location/>
|
||||
添加收货地址
|
||||
@@ -809,17 +1033,19 @@ const OrderConfirm = () => {
|
||||
: `最低起送 ${MIN_START_QTY} 桶(当前最多 ${maxQuantity} 桶)`
|
||||
}
|
||||
extra={(
|
||||
<ConfigProvider theme={customTheme}>
|
||||
<InputNumber
|
||||
value={displayQty}
|
||||
min={canStartOrder ? MIN_START_QTY : 0}
|
||||
max={canStartOrder ? maxQuantity : 0}
|
||||
disabled={!canStartOrder}
|
||||
onChange={handleQuantityChange}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
)}
|
||||
/>
|
||||
<ConfigProvider theme={customTheme}>
|
||||
<InputNumber
|
||||
value={displayQty}
|
||||
min={canStartOrder ? MIN_START_QTY : 0}
|
||||
max={canStartOrder ? maxQuantity : 0}
|
||||
step={10}
|
||||
readOnly
|
||||
disabled={!canStartOrder}
|
||||
onChange={handleQuantityChange}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
)}
|
||||
/>
|
||||
</CellGroup>
|
||||
|
||||
<CellGroup>
|
||||
@@ -1037,7 +1263,9 @@ const OrderConfirm = () => {
|
||||
loading={submitLoading || deliveryRangeChecking}
|
||||
disabled={
|
||||
deliveryRangeChecking ||
|
||||
inDeliveryRange === false ||
|
||||
!address?.id ||
|
||||
!addressHasCoords ||
|
||||
(deliveryRangeCheckedAddressId === address?.id && inDeliveryRange === false) ||
|
||||
availableTicketTotal <= 0 ||
|
||||
!canStartOrder
|
||||
}
|
||||
@@ -1045,7 +1273,16 @@ const OrderConfirm = () => {
|
||||
>
|
||||
{deliveryRangeChecking
|
||||
? '校验配送范围...'
|
||||
: (inDeliveryRange === false ? '不在配送范围' : (submitLoading ? '提交中...' : '立即提交'))
|
||||
: (!address?.id
|
||||
? '请选择地址'
|
||||
: (!addressHasCoords
|
||||
? '地址缺少定位'
|
||||
: ((deliveryRangeCheckedAddressId === address?.id && inDeliveryRange === false)
|
||||
? '不在配送范围'
|
||||
: (submitLoading ? '提交中...' : '立即提交')
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user