Compare commits
27 Commits
master
...
128a566162
| Author | SHA1 | Date | |
|---|---|---|---|
| 128a566162 | |||
| 54404aa48f | |||
| e0418df018 | |||
| e3181c8ade | |||
| 12917a4766 | |||
| 6fb8be275a | |||
| 190df391c3 | |||
| 5fe881b927 | |||
| 5ff710c6a0 | |||
| 6b1e506f43 | |||
| 4a45bc5242 | |||
| 0628a0f6b4 | |||
| 8b902be603 | |||
| 37ab933849 | |||
| e58a2fd915 | |||
| 4ffe3a8f4b | |||
| e7caee08c1 | |||
| cc58bd791d | |||
| ac194b93eb | |||
| 1cdb6404ad | |||
| ef6a55112f | |||
| 00f3954012 | |||
| 0c9a03d656 | |||
| 80d4db4156 | |||
| a6749bcedb | |||
| 49c801c751 | |||
| 3248315f6e |
72
.workbuddy/expert-history.json
Normal file
72
.workbuddy/expert-history.json
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"sessions": {
|
||||||
|
"bb17ec0263344400afb0ecfafefc1ab1": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775132175089,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"b1db410ffede4e03be74a98ac57ea478": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775753422786,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"3ad590301d144e91ac2d9497ad0b1a22": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775754410884,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"a07270b8a79e42f88a866c9e908129ad": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775755906815,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"c8760ea899514a1aae49666ae8a1f5e1": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775755982035,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"92099fa2ec454bf7b29102b6ab4b41a6": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775972794982,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"lastUpdated": 1775999935033
|
||||||
|
}
|
||||||
29
.workbuddy/memory/2026-03-31.md
Normal file
29
.workbuddy/memory/2026-03-31.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# 2026-03-31 工作日志
|
||||||
|
|
||||||
|
## 新增 dealer/index.tsx 配送员解冻资金功能
|
||||||
|
|
||||||
|
将 `/rider/index.tsx` 的 `handleFreezeMoneyClick` 功能复制到 `/dealer/index.tsx`:
|
||||||
|
- 导入 `useUser` hook 和 `updateShopDealerUser` API
|
||||||
|
- 添加 `isRider` 判断(只有 `hasRole('rider')` 才可操作)
|
||||||
|
- "待使用"卡片点击事件(仅配送员+有冻结金额时可用)
|
||||||
|
- 确认后冻结金额转入可提现
|
||||||
|
|
||||||
|
## 修改 rider/index.tsx (React Taro 项目)
|
||||||
|
|
||||||
|
修改了 `/Users/gxwebsoft/VUE/template-10584/src/rider/index.tsx`:
|
||||||
|
|
||||||
|
### 修改内容:
|
||||||
|
1. **统一显示格式** - 把"桶数"改成"待使用"
|
||||||
|
2. **添加配送员权限控制** - 只有 `hasRole('rider')` 的用户才能点击操作
|
||||||
|
3. **点击解冻功能**:
|
||||||
|
- 配送员点击"待使用"金额时显示蓝色高亮提示"(点击转入)"
|
||||||
|
- 弹出确认框:`确定要将 ¥xx.xx 待使用金额转入可提现吗?`
|
||||||
|
- 确认后调用 `updateShopDealerUser` API
|
||||||
|
- 将 `freezeMoney` 清零,加到 `money`
|
||||||
|
- 成功后提示"更新成功"并刷新数据
|
||||||
|
|
||||||
|
### 关键代码:
|
||||||
|
- 使用 `useUser` hook 获取 `hasRole` 函数
|
||||||
|
- `isRider` 判断是否为配送员
|
||||||
|
- `handleFreezeMoneyClick` 处理点击解冻逻辑
|
||||||
|
- 使用 `Taro.showModal` / `Taro.showToast` 提示用户
|
||||||
107
.workbuddy/memory/2026-04-10.md
Normal file
107
.workbuddy/memory/2026-04-10.md
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
# 2026-04-10 工作日志
|
||||||
|
|
||||||
|
## 完成的功能:四种用户分级标签
|
||||||
|
|
||||||
|
### 需求
|
||||||
|
用户 ID 下方"管理员"标签改为四种分级:
|
||||||
|
- 0: 普通用户
|
||||||
|
- 1: 超级管理员
|
||||||
|
- 2: 合伙人(总店)
|
||||||
|
- 3: 合伙人(分店)
|
||||||
|
|
||||||
|
### 修改的文件
|
||||||
|
|
||||||
|
#### 后端 (JAVA)
|
||||||
|
1. `ShopDealerUser.java` - 添加 `dealerLevel` 字段
|
||||||
|
2. `ShopDealerUserMapper.xml` - 添加 dealerLevel 查询条件
|
||||||
|
|
||||||
|
#### 前端 (VUE)
|
||||||
|
1. `src/api/shop/shopDealerUser/model/index.ts` - 添加 dealerLevel 字段
|
||||||
|
2. `src/utils/userLevel.ts` - 新建用户等级配置工具文件
|
||||||
|
3. `src/pages/user/components/UserCard.tsx` - 修改角色标签显示逻辑
|
||||||
|
|
||||||
|
### 注意事项
|
||||||
|
- 需要在数据库中添加 `dealer_level` 字段
|
||||||
|
- 后端需要重启生效
|
||||||
|
- 前端通过 dealerLevel 字段判断显示对应样式
|
||||||
|
|
||||||
|
## 配送员订单通知功能
|
||||||
|
|
||||||
|
### 需求
|
||||||
|
客户下单后,配送员手机声音提示和红点提示功能
|
||||||
|
|
||||||
|
### 实现方案
|
||||||
|
1. **红点提示**:在配送员首页「配送订单」图标上显示待配送订单数量
|
||||||
|
2. **声音提示**:收到新订单时播放微信官方提示音
|
||||||
|
3. **设置功能**:支持开启/关闭声音提醒
|
||||||
|
|
||||||
|
### 新增/修改的文件
|
||||||
|
1. `src/api/glt/gltTicketOrder/index.ts` - 添加 `getRiderPendingCount` 接口
|
||||||
|
2. `src/hooks/useRiderNotification.ts` - 新建配送员通知 Hook
|
||||||
|
3. `src/rider/index.tsx` - 添加 Badge 红点和设置入口
|
||||||
|
|
||||||
|
### 技术实现
|
||||||
|
- 使用 30 秒轮询获取待配送订单数量
|
||||||
|
- 使用 NutUI 的 Badge 组件显示红点
|
||||||
|
- 使用 Taro.createInnerAudioContext 播放提示音
|
||||||
|
- 声音设置保存在本地存储 `rider_sound_enabled`
|
||||||
|
|
||||||
|
### 待后端配合
|
||||||
|
- 需要后端提供 `/glt/glt-ticket-order/rider/count` 接口(可选,使用现有 page 接口也行)
|
||||||
|
- 需要配置微信订阅消息模板(可选)
|
||||||
|
|
||||||
|
## 下单页配送方式 + 配送费功能
|
||||||
|
|
||||||
|
### 需求
|
||||||
|
1. 下单页必选配送方式:电梯 / 步梯 / 一楼商铺·其他
|
||||||
|
2. 步梯需二级选择是否送上楼,送上楼需选楼层
|
||||||
|
3. 配送费计算:每桶每层1元,第1层不收费(即 `(楼层-1) × 数量`)
|
||||||
|
4. 自提模式隐藏配送方式选择器
|
||||||
|
|
||||||
|
### 修改的文件
|
||||||
|
1. `src/api/shop/shopOrder/model/index.ts` - OrderCreateRequest 新增 deliveryMethod、deliveryFloor 字段
|
||||||
|
2. `src/utils/payment.ts` - buildSingleGoodsOrder 透传配送方式字段
|
||||||
|
3. `src/shop/orderConfirm/index.tsx` - 配送方式选择UI、配送费计算、楼层选择弹窗、支付校验
|
||||||
|
4. `src/shop/orderConfirm/index.scss` - 配送方式选择器、楼层网格样式
|
||||||
|
|
||||||
|
### 后端需配合
|
||||||
|
- 订单表新增 `delivery_method` 和 `delivery_floor` 字段
|
||||||
|
- 订单创建接口接收并存储这两个字段
|
||||||
|
- 骑手端/后台展示配送方式和楼层信息
|
||||||
|
|
||||||
|
## 配送方式功能迁移:orderConfirm → user/ticket/use
|
||||||
|
|
||||||
|
### 原因
|
||||||
|
配送方式选择功能从购买下单页(orderConfirm)迁移到水票核销/立即送水页面(user/ticket/use)。
|
||||||
|
|
||||||
|
### 修改的文件
|
||||||
|
1. `src/shop/orderConfirm/index.tsx` - 回滚:移除配送方式状态变量、UI、校验、楼层选择弹窗、配送费计算
|
||||||
|
2. `src/shop/orderConfirm/index.scss` - 回滚:移除配送方式/楼层选择相关样式
|
||||||
|
3. `src/api/glt/gltTicketOrder/model/index.ts` - GltTicketOrder 新增 deliveryMethod、deliveryFloor、deliveryFee 字段
|
||||||
|
4. `src/user/ticket/use.tsx` - 新增:配送方式选择UI、配送费计算、楼层选择弹窗、提交校验、编辑模式回显
|
||||||
|
5. `src/user/ticket/use.scss` - 新增:配送方式/楼层选择样式
|
||||||
|
|
||||||
|
### 关键差异
|
||||||
|
- orderConfirm 页面是付费购买,配送费加到实付金额中
|
||||||
|
- use 页面是水票核销(不付费),配送费以"到付"形式展示在底部栏
|
||||||
|
- use 页面同时支持新建和编辑模式,编辑时回显配送信息
|
||||||
|
|
||||||
|
## 微信订阅消息配置(补充)
|
||||||
|
|
||||||
|
### 需要做的配置
|
||||||
|
|
||||||
|
#### 后端配置
|
||||||
|
1. `GltSubscribeMessageServiceImpl.java` - 订阅消息发送服务
|
||||||
|
- 需要配置 `SUBSCRIBE_TEMPLATE_ID` 为实际模板ID
|
||||||
|
|
||||||
|
2. `GltTicketOrderController.java` - 订单创建时通知配送员
|
||||||
|
- 注入 `GltSubscribeMessageService` 和 `UserMapper`
|
||||||
|
- 添加 `notifyRidersOfNewOrder` 方法
|
||||||
|
|
||||||
|
#### 前端配置
|
||||||
|
1. `src/rider/index.tsx`
|
||||||
|
- `handleRequestSubscribeMessage` 函数需要配置实际的模板ID
|
||||||
|
|
||||||
|
### 微信后台需要申请的模板
|
||||||
|
模板名称:订单配送通知
|
||||||
|
关键词:订单状态、订单编号、配送地址、商品数量、通知时间
|
||||||
25
.workbuddy/memory/2026-04-12.md
Normal file
25
.workbuddy/memory/2026-04-12.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# 2026-04-12 工作日志
|
||||||
|
|
||||||
|
## 配送方式功能完善:全链路入库+展示
|
||||||
|
|
||||||
|
### 问题
|
||||||
|
配送方式(deliveryMethod)、楼层(deliveryFloor)、配送费(deliveryFee)在小程序端用户下单页面已可选择并提交,但后端数据库表没有对应字段,数据实际没有保存。骑手端和后台管理端也没有展示这些信息。
|
||||||
|
|
||||||
|
### 修改的文件
|
||||||
|
|
||||||
|
#### 后端(/Users/gxwebsoft/JAVA/java-10584)
|
||||||
|
1. `src/main/java/com/gxwebsoft/glt/entity/GltTicketOrder.java` - 新增 deliveryMethod(String)、deliveryFloor(Integer)、deliveryFee(BigDecimal) 三个数据库字段
|
||||||
|
2. `sql/glt_ticket_order_delivery_fields.sql` - 新增 ALTER TABLE SQL,给 glt_ticket_order 表添加三个字段
|
||||||
|
|
||||||
|
#### 小程序端(/Users/gxwebsoft/VUE/template-10584)
|
||||||
|
3. `src/rider/orders/index.tsx` - 骑手送水订单页面:新增配送方式中文映射函数,订单卡片中展示配送方式、楼层、配送费
|
||||||
|
|
||||||
|
#### 后台管理端(/Users/gxwebsoft/VUE/mp-10584)
|
||||||
|
4. `src/api/glt/gltTicketOrder/model/index.ts` - GltTicketOrder 接口新增 deliveryMethod、deliveryFloor、deliveryFee 字段
|
||||||
|
5. `src/views/glt/gltTicketOrder/index.vue` - 列表页"配送信息"列中展示配送方式、楼层、配送费
|
||||||
|
6. `src/views/glt/gltTicketOrder/components/gltTicketOrderEdit.vue` - 编辑弹窗中新增配送方式只读展示
|
||||||
|
|
||||||
|
### 部署注意事项
|
||||||
|
- **必须先执行 SQL**:`java-10584/sql/glt_ticket_order_delivery_fields.sql`
|
||||||
|
- MyBatis-Plus 使用驼峰自动映射,`delivery_method` → `deliveryMethod`,无需修改 Mapper XML
|
||||||
|
- 后端 save/updateById 自动包含新字段,无需修改 Controller/Service
|
||||||
0
.workbuddy/memory/MEMORY.md
Normal file
0
.workbuddy/memory/MEMORY.md
Normal file
@@ -10,5 +10,6 @@ export const BaseUrl = API_BASE_URL;
|
|||||||
export const Version = 'v3.0.8';
|
export const Version = 'v3.0.8';
|
||||||
// 版权信息
|
// 版权信息
|
||||||
export const Copyright = '桂乐淘·购享无界 乐惠万家';
|
export const Copyright = '桂乐淘·购享无界 乐惠万家';
|
||||||
|
// export const Copyright = '测试环境 v3.2.6';
|
||||||
|
|
||||||
// java -jar CertificateDownloader.jar -k 0kF5OlPr482EZwtn9zGufUcqa7ovgxRL -m 1723321338 -f ./apiclient_key.pem -s 2B933F7C35014A1C363642623E4A62364B34C4EB -o ./
|
// java -jar CertificateDownloader.jar -k 0kF5OlPr482EZwtn9zGufUcqa7ovgxRL -m 1723321338 -f ./apiclient_key.pem -s 2B933F7C35014A1C363642623E4A62364B34C4EB -o ./
|
||||||
|
|||||||
@@ -1,44 +1,43 @@
|
|||||||
// 环境变量配置
|
// 环境变量配置
|
||||||
|
|
||||||
|
// ============ 环境切换开关(修改这里即可切换环境)============
|
||||||
|
// 可选值: 'development' | 'test' | 'production'
|
||||||
|
const CURRENT_ENV = 'production'
|
||||||
|
// ===========================================================
|
||||||
|
|
||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
// API_BASE_URL: 'http://127.0.0.1:9200/api',
|
|
||||||
API_BASE_URL: 'https://glt-api.websoft.top/api',
|
API_BASE_URL: 'https://glt-api.websoft.top/api',
|
||||||
|
SERVER_API_URL: 'https://glt-server.websoft.top/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
|
// 测试环境
|
||||||
|
test: {
|
||||||
|
API_BASE_URL: 'https://glt-api.websoft.top/api',
|
||||||
|
SERVER_API_URL: 'https://glt-server.websoft.top/api',
|
||||||
|
APP_NAME: '测试环境',
|
||||||
|
DEBUG: 'true',
|
||||||
|
},
|
||||||
// 生产环境
|
// 生产环境
|
||||||
production: {
|
production: {
|
||||||
API_BASE_URL: 'https://glt-api.websoft.top/api',
|
API_BASE_URL: 'https://glt-api.websoft.top/api',
|
||||||
|
SERVER_API_URL: 'https://glt-server.websoft.top/api',
|
||||||
APP_NAME: '桂乐淘',
|
APP_NAME: '桂乐淘',
|
||||||
DEBUG: 'false',
|
DEBUG: 'false',
|
||||||
},
|
},
|
||||||
// 测试环境
|
|
||||||
test: {
|
|
||||||
// API_BASE_URL: 'http://127.0.0.1:9200/api',
|
|
||||||
API_BASE_URL: 'https://glt-api.websoft.top/api',
|
|
||||||
APP_NAME: '测试环境',
|
|
||||||
DEBUG: 'true',
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前环境配置
|
// 获取当前环境配置
|
||||||
export function getEnvConfig() {
|
export function getEnvConfig() {
|
||||||
const env = process.env.NODE_ENV || 'development'
|
return ENV_CONFIG[CURRENT_ENV]
|
||||||
if (env === 'production') {
|
|
||||||
return ENV_CONFIG.production
|
|
||||||
} else { // @ts-ignore
|
|
||||||
if (env === 'test') {
|
|
||||||
return ENV_CONFIG.test
|
|
||||||
} else {
|
|
||||||
return ENV_CONFIG.development
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出环境变量
|
// 导出环境变量
|
||||||
export const {
|
export const {
|
||||||
API_BASE_URL,
|
API_BASE_URL,
|
||||||
|
SERVER_API_URL,
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
DEBUG
|
DEBUG
|
||||||
} = getEnvConfig()
|
} = getEnvConfig()
|
||||||
@@ -2,7 +2,7 @@ import { defineConfig, type UserConfigExport } from '@tarojs/cli'
|
|||||||
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
|
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
|
||||||
import devConfig from './dev'
|
import devConfig from './dev'
|
||||||
import prodConfig from './prod'
|
import prodConfig from './prod'
|
||||||
import { getEnvConfig } from './env'
|
import { getEnvConfig } from './env.js'
|
||||||
|
|
||||||
// import vitePluginImp from 'vite-plugin-imp'
|
// import vitePluginImp from 'vite-plugin-imp'
|
||||||
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
|
// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
|
||||||
|
|||||||
@@ -16,6 +16,21 @@ export async function pageGltTicketOrder(params: GltTicketOrderParam) {
|
|||||||
return Promise.reject(new Error(res.message));
|
return Promise.reject(new Error(res.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配送员待处理订单数量
|
||||||
|
* @param riderId 配送员ID
|
||||||
|
*/
|
||||||
|
export async function getRiderPendingCount(riderId: number) {
|
||||||
|
const res = await request.get<ApiResult<{ pendingCount: number; totalCount: number }>>(
|
||||||
|
'/glt/glt-ticket-order/rider/count',
|
||||||
|
{ riderId }
|
||||||
|
);
|
||||||
|
if (res.code === 0) {
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
return { pendingCount: 0, totalCount: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询送水订单列表
|
* 查询送水订单列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ export interface GltTicketOrder {
|
|||||||
createTime?: string;
|
createTime?: string;
|
||||||
// 修改时间
|
// 修改时间
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
|
// 配送方式:elevator(电梯) / stairs(步梯) / groundFloor(一楼商铺/其他)
|
||||||
|
deliveryMethod?: string;
|
||||||
|
// 楼层(步梯+送上楼时有值,从2开始)
|
||||||
|
deliveryFloor?: number;
|
||||||
|
// 配送费(步梯+送上楼时计算:数量 × (楼层-1))
|
||||||
|
deliveryFee?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export interface GltTicketTemplate {
|
|||||||
unitName?: string;
|
unitName?: string;
|
||||||
// 最小购买数量
|
// 最小购买数量
|
||||||
minBuyQty?: number;
|
minBuyQty?: number;
|
||||||
|
// 购买步长(如:5 的倍数)
|
||||||
|
step?: number;
|
||||||
// 起始发送数量
|
// 起始发送数量
|
||||||
startSendQty?: number;
|
startSendQty?: number;
|
||||||
// 买赠:买1送4 => gift_multiplier=4
|
// 买赠:买1送4 => gift_multiplier=4
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import type { GltUserTicketRelease, GltUserTicketReleaseParam } from './model';
|
|||||||
export async function pageGltUserTicketRelease(params: GltUserTicketReleaseParam) {
|
export async function pageGltUserTicketRelease(params: GltUserTicketReleaseParam) {
|
||||||
const res = await request.get<ApiResult<PageResult<GltUserTicketRelease>>>(
|
const res = await request.get<ApiResult<PageResult<GltUserTicketRelease>>>(
|
||||||
'/glt/glt-user-ticket-release/page',
|
'/glt/glt-user-ticket-release/page',
|
||||||
{
|
params
|
||||||
params
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
return res.data;
|
return res.data;
|
||||||
@@ -24,9 +22,7 @@ export async function pageGltUserTicketRelease(params: GltUserTicketReleaseParam
|
|||||||
export async function listGltUserTicketRelease(params?: GltUserTicketReleaseParam) {
|
export async function listGltUserTicketRelease(params?: GltUserTicketReleaseParam) {
|
||||||
const res = await request.get<ApiResult<GltUserTicketRelease[]>>(
|
const res = await request.get<ApiResult<GltUserTicketRelease[]>>(
|
||||||
'/glt/glt-user-ticket-release',
|
'/glt/glt-user-ticket-release',
|
||||||
{
|
params
|
||||||
params
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ export interface ShopDealerUser {
|
|||||||
createTime?: string;
|
createTime?: string;
|
||||||
// 修改时间
|
// 修改时间
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
|
// 分销商等级:0-普通用户 1-超级管理员 2-合伙人(总店) 3-合伙人(分店)
|
||||||
|
dealerLevel?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ export interface ShopGoods {
|
|||||||
isNew?: number;
|
isNew?: number;
|
||||||
// 库存
|
// 库存
|
||||||
stock?: number;
|
stock?: number;
|
||||||
|
// 步长
|
||||||
|
step?: number;
|
||||||
// 商品重量
|
// 商品重量
|
||||||
goodsWeight?: number;
|
goodsWeight?: number;
|
||||||
// 消费赚取积分
|
// 消费赚取积分
|
||||||
@@ -126,6 +128,10 @@ export interface ShopGoods {
|
|||||||
expiredDay?: number;
|
expiredDay?: number;
|
||||||
// 可购买数量
|
// 可购买数量
|
||||||
canBuyNumber?: number;
|
canBuyNumber?: number;
|
||||||
|
// 活动方式:0全平台 1新用户专享
|
||||||
|
activityType?: number;
|
||||||
|
// 配送方式:0送上门 1限自提
|
||||||
|
deliveryMode?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BathSet {
|
export interface BathSet {
|
||||||
|
|||||||
@@ -201,6 +201,10 @@ export interface OrderCreateRequest {
|
|||||||
selfTakeMerchantId?: number;
|
selfTakeMerchantId?: number;
|
||||||
// 订单标题(可选,后端会自动生成)
|
// 订单标题(可选,后端会自动生成)
|
||||||
title?: string;
|
title?: string;
|
||||||
|
// 配送方式:elevator(电梯) / stairs(步梯) / groundFloor(一楼商铺/其他)
|
||||||
|
deliveryMethod?: string;
|
||||||
|
// 楼层(步梯+送上楼时有值,从2开始)
|
||||||
|
deliveryFloor?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export default {
|
|||||||
"points/points",
|
"points/points",
|
||||||
"ticket/index",
|
"ticket/index",
|
||||||
"ticket/use",
|
"ticket/use",
|
||||||
|
"ticket/release/index",
|
||||||
"ticket/orders/index",
|
"ticket/orders/index",
|
||||||
// "gift/index",
|
// "gift/index",
|
||||||
// "gift/redeem",
|
// "gift/redeem",
|
||||||
|
|||||||
98
src/dealer/components/FreezeMoneyModal.tsx
Normal file
98
src/dealer/components/FreezeMoneyModal.tsx
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { View, Text } from '@tarojs/components'
|
||||||
|
import { Popup, Button } from '@nutui/nutui-react-taro'
|
||||||
|
import { Close } from '@nutui/icons-react-taro'
|
||||||
|
|
||||||
|
interface FreezeMoneyModalProps {
|
||||||
|
visible: boolean
|
||||||
|
amount: string
|
||||||
|
onClose: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待使用明细弹窗组件
|
||||||
|
* 展示待使用(冻结中)金额和解冻规则说明
|
||||||
|
*/
|
||||||
|
const FreezeMoneyModal: React.FC<FreezeMoneyModalProps> = ({
|
||||||
|
visible,
|
||||||
|
amount,
|
||||||
|
onClose
|
||||||
|
}) => {
|
||||||
|
// 格式化金额,保留2位小数
|
||||||
|
const formatAmount = (value: string | number): string => {
|
||||||
|
const num = typeof value === 'string' ? parseFloat(value) : value
|
||||||
|
if (isNaN(num)) return '0.00'
|
||||||
|
return num.toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popup
|
||||||
|
visible={visible}
|
||||||
|
style={{ padding: '0', borderRadius: '16px', overflow: 'hidden' }}
|
||||||
|
onClose={onClose}
|
||||||
|
closeOnOverlayClick={true}
|
||||||
|
position="center"
|
||||||
|
>
|
||||||
|
<View className="w-72 bg-white">
|
||||||
|
{/* 头部标题 */}
|
||||||
|
<View className="relative px-4 py-4 border-b border-gray-100">
|
||||||
|
<Text className="text-lg font-semibold text-gray-800 text-center block">
|
||||||
|
待使用明细
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
className="absolute right-3 top-1 -translate-y-1 p-1"
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
<Close size={20} className="text-gray-400" />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* 金额展示区域 */}
|
||||||
|
<View className="px-6 py-8 text-center">
|
||||||
|
<Text className="text-sm text-gray-500 mb-2 block">
|
||||||
|
待使用(冻结中)
|
||||||
|
</Text>
|
||||||
|
<View className="flex items-baseline justify-center">
|
||||||
|
<Text className="text-2xl font-bold text-gray-800">¥</Text>
|
||||||
|
<Text className="text-4xl font-bold text-gray-800 ml-1">
|
||||||
|
{formatAmount(amount)}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* 分隔线 */}
|
||||||
|
<View className="mx-6 h-px bg-gray-100" />
|
||||||
|
|
||||||
|
{/* 温馨提示区域 */}
|
||||||
|
<View className="px-6 py-6">
|
||||||
|
<Text className="text-sm font-medium text-gray-700 mb-3 block">
|
||||||
|
温馨提示:
|
||||||
|
</Text>
|
||||||
|
<Text className="text-sm text-gray-500 leading-relaxed block">
|
||||||
|
需要直推用户进行下单配送后方可解冻到待提现资金组
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* 底部按钮 */}
|
||||||
|
<View className="px-6 pb-6">
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
block
|
||||||
|
onClick={onClose}
|
||||||
|
style={{
|
||||||
|
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '8px',
|
||||||
|
height: '44px',
|
||||||
|
lineHeight: '44px'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
关闭
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Popup>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FreezeMoneyModal
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
import {View, Text} from '@tarojs/components'
|
import {View, Text} from '@tarojs/components'
|
||||||
import {ConfigProvider, Button, Grid, Avatar} from '@nutui/nutui-react-taro'
|
import {ConfigProvider, Button, Grid, Avatar} from '@nutui/nutui-react-taro'
|
||||||
import {
|
import {
|
||||||
@@ -10,8 +10,11 @@ import {
|
|||||||
People
|
People
|
||||||
} from '@nutui/icons-react-taro'
|
} from '@nutui/icons-react-taro'
|
||||||
import {useDealerUser} from '@/hooks/useDealerUser'
|
import {useDealerUser} from '@/hooks/useDealerUser'
|
||||||
|
import {useUser} from '@/hooks/useUser'
|
||||||
import { useThemeStyles } from '@/hooks/useTheme'
|
import { useThemeStyles } from '@/hooks/useTheme'
|
||||||
import {businessGradients, cardGradients, gradientUtils} from '@/styles/gradients'
|
import {businessGradients, cardGradients, gradientUtils} from '@/styles/gradients'
|
||||||
|
import {updateShopDealerUser} from '@/api/shop/shopDealerUser'
|
||||||
|
import FreezeMoneyModal from './components/FreezeMoneyModal'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
|
|
||||||
const DealerIndex: React.FC = () => {
|
const DealerIndex: React.FC = () => {
|
||||||
@@ -21,6 +24,12 @@ const DealerIndex: React.FC = () => {
|
|||||||
refresh,
|
refresh,
|
||||||
} = useDealerUser()
|
} = useDealerUser()
|
||||||
|
|
||||||
|
// 待使用明细弹窗显示状态
|
||||||
|
const [freezeMoneyModalVisible, setFreezeMoneyModalVisible] = useState(false)
|
||||||
|
|
||||||
|
// 获取用户角色信息
|
||||||
|
const { hasRole } = useUser()
|
||||||
|
|
||||||
// 使用主题样式
|
// 使用主题样式
|
||||||
const themeStyles = useThemeStyles()
|
const themeStyles = useThemeStyles()
|
||||||
|
|
||||||
@@ -55,6 +64,75 @@ const DealerIndex: React.FC = () => {
|
|||||||
|
|
||||||
console.log(getGradientBackground(),'getGradientBackground()')
|
console.log(getGradientBackground(),'getGradientBackground()')
|
||||||
|
|
||||||
|
// 判断是否是配送员
|
||||||
|
const isRider = hasRole('rider')
|
||||||
|
|
||||||
|
// 点击待使用金额 - 显示待使用明细弹窗
|
||||||
|
const handleFreezeMoneyClick = () => {
|
||||||
|
console.log('点击待使用金额', dealerUser?.freezeMoney)
|
||||||
|
const freezeMoney = Number(dealerUser?.freezeMoney ?? 0)
|
||||||
|
// 只要有金额就显示弹窗,包括0元也显示(让用户知道当前状态)
|
||||||
|
setFreezeMoneyModalVisible(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭待使用明细弹窗
|
||||||
|
const handleCloseFreezeMoneyModal = () => {
|
||||||
|
setFreezeMoneyModalVisible(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 配送员专用:将冻结金额转入可提现
|
||||||
|
const handleTransferFreezeMoney = async () => {
|
||||||
|
// 检查是否是配送员
|
||||||
|
if (!isRider) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查冻结金额是否为 0
|
||||||
|
const freezeMoney = Number(dealerUser?.freezeMoney ?? 0)
|
||||||
|
if (freezeMoney <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
setFreezeMoneyModalVisible(false)
|
||||||
|
|
||||||
|
// 弹出确认框
|
||||||
|
Taro.showModal({
|
||||||
|
title: '确认操作',
|
||||||
|
content: `确定要将 ¥${freezeMoney.toFixed(2)} 转入钱包吗?`,
|
||||||
|
confirmText: '确定',
|
||||||
|
cancelText: '取消',
|
||||||
|
success: async (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
try {
|
||||||
|
Taro.showLoading({ title: '处理中...' })
|
||||||
|
const currentMoney = Number(dealerUser?.money ?? 0)
|
||||||
|
await updateShopDealerUser({
|
||||||
|
id: dealerUser?.id,
|
||||||
|
money: (currentMoney + freezeMoney).toFixed(2),
|
||||||
|
freezeMoney: '0.00'
|
||||||
|
})
|
||||||
|
Taro.hideLoading()
|
||||||
|
Taro.showToast({
|
||||||
|
title: '更新成功',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 1500
|
||||||
|
})
|
||||||
|
// 刷新数据
|
||||||
|
refresh()
|
||||||
|
} catch (error) {
|
||||||
|
Taro.hideLoading()
|
||||||
|
Taro.showToast({
|
||||||
|
title: '更新失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 1500
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<View className="p-4">
|
<View className="p-4">
|
||||||
@@ -140,13 +218,20 @@ const DealerIndex: React.FC = () => {
|
|||||||
</Text>
|
</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>
|
||||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
<View
|
||||||
background: businessGradients.money.frozen
|
className="text-center p-3 rounded-lg flex flex-col"
|
||||||
}}>
|
style={{
|
||||||
|
background: businessGradients.money.frozen,
|
||||||
|
opacity: Number(dealerUser.freezeMoney ?? 0) > 0 ? 1 : 0.8
|
||||||
|
}}
|
||||||
|
onClick={handleFreezeMoneyClick}
|
||||||
|
>
|
||||||
<Text className="text-lg font-bold mb-1 text-white">
|
<Text className="text-lg font-bold mb-1 text-white">
|
||||||
{formatMoney(dealerUser.freezeMoney)}
|
{formatMoney(dealerUser.freezeMoney)}
|
||||||
</Text>
|
</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>
|
||||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
||||||
background: businessGradients.money.total
|
background: businessGradients.money.total
|
||||||
@@ -286,6 +371,13 @@ const DealerIndex: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* 待使用明细弹窗 */}
|
||||||
|
<FreezeMoneyModal
|
||||||
|
visible={freezeMoneyModalVisible}
|
||||||
|
amount={dealerUser?.freezeMoney || '0'}
|
||||||
|
onClose={handleCloseFreezeMoneyModal}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* 底部安全区域 */}
|
{/* 底部安全区域 */}
|
||||||
<View className="h-20"></View>
|
<View className="h-20"></View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
<Form.Item name="amount" label="提现金额">
|
<Form.Item name="amount" label="提现金额">
|
||||||
<Input
|
<Input
|
||||||
placeholder="请输入提现金额"
|
placeholder="请输入提现金额"
|
||||||
type="number"
|
type="digit"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
|||||||
277
src/hooks/useRiderNotification.ts
Normal file
277
src/hooks/useRiderNotification.ts
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
/**
|
||||||
|
* 配送员订单通知 Hook
|
||||||
|
* 功能:
|
||||||
|
* 1. 轮询获取待配送订单数量
|
||||||
|
* 2. 新订单时播放提示音
|
||||||
|
* 3. 支持声音开关设置
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useState, useEffect, useRef, useCallback } from 'react'
|
||||||
|
import Taro from '@tarojs/taro'
|
||||||
|
import { pageGltTicketOrder } from '@/api/glt/gltTicketOrder'
|
||||||
|
|
||||||
|
// 轮询间隔(毫秒)- 30秒
|
||||||
|
const POLL_INTERVAL = 30000
|
||||||
|
|
||||||
|
// 提示音 URL(使用微信官方提示音)
|
||||||
|
const NOTIFICATION_SOUND_URL = 'https://res.wx.qq.com/wechatApp/pkg/notice/notice.mp3'
|
||||||
|
|
||||||
|
interface RiderNotificationState {
|
||||||
|
/** 待配送订单数量 */
|
||||||
|
pendingCount: number
|
||||||
|
/** 所有配送中订单数量 */
|
||||||
|
totalCount: number
|
||||||
|
/** 是否正在轮询 */
|
||||||
|
isPolling: boolean
|
||||||
|
/** 最后更新的订单ID */
|
||||||
|
lastOrderId: number | null
|
||||||
|
/** 声音是否开启 */
|
||||||
|
soundEnabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UseRiderNotificationReturn extends RiderNotificationState {
|
||||||
|
/** 开始轮询 */
|
||||||
|
startPolling: () => void
|
||||||
|
/** 停止轮询 */
|
||||||
|
stopPolling: () => void
|
||||||
|
/** 刷新数据 */
|
||||||
|
refresh: () => Promise<void>
|
||||||
|
/** 切换声音开关 */
|
||||||
|
toggleSound: () => void
|
||||||
|
/** 手动播放提示音 */
|
||||||
|
playSound: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配送员通知 Hook
|
||||||
|
* @param autoStart 是否自动开始轮询,默认 true
|
||||||
|
*/
|
||||||
|
export const useRiderNotification = (autoStart = true): UseRiderNotificationReturn => {
|
||||||
|
const [state, setState] = useState<RiderNotificationState>({
|
||||||
|
pendingCount: 0,
|
||||||
|
totalCount: 0,
|
||||||
|
isPolling: false,
|
||||||
|
lastOrderId: null,
|
||||||
|
soundEnabled: true
|
||||||
|
})
|
||||||
|
|
||||||
|
const pollTimerRef = useRef<number | null>(null)
|
||||||
|
const audioContextRef = useRef<any>(null)
|
||||||
|
const lastCountRef = useRef(0)
|
||||||
|
const isMountedRef = useRef(true)
|
||||||
|
|
||||||
|
// 获取配送员ID
|
||||||
|
const getRiderId = useCallback(() => {
|
||||||
|
const riderId = Taro.getStorageSync('UserId')
|
||||||
|
return Number(riderId) || undefined
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 从本地存储加载声音设置
|
||||||
|
const loadSoundSetting = useCallback(() => {
|
||||||
|
try {
|
||||||
|
const enabled = Taro.getStorageSync('rider_sound_enabled')
|
||||||
|
return enabled !== '0' // 默认开启
|
||||||
|
} catch {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 保存声音设置到本地存储
|
||||||
|
const saveSoundSetting = useCallback((enabled: boolean) => {
|
||||||
|
try {
|
||||||
|
Taro.setStorageSync('rider_sound_enabled', enabled ? '1' : '0')
|
||||||
|
} catch (e) {
|
||||||
|
console.error('保存声音设置失败', e)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 播放提示音
|
||||||
|
const playSound = useCallback(() => {
|
||||||
|
if (!state.soundEnabled) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 停止之前的音频
|
||||||
|
if (audioContextRef.current) {
|
||||||
|
audioContextRef.current.stop()
|
||||||
|
audioContextRef.current.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新的音频实例
|
||||||
|
const audioContext = Taro.createInnerAudioContext()
|
||||||
|
audioContextRef.current = audioContext
|
||||||
|
|
||||||
|
audioContext.src = NOTIFICATION_SOUND_URL
|
||||||
|
audioContext.volume = 0.8
|
||||||
|
|
||||||
|
audioContext.play()
|
||||||
|
audioContext.onPlay(() => {
|
||||||
|
console.log('📢 新订单提示音播放中')
|
||||||
|
})
|
||||||
|
|
||||||
|
audioContext.onError((err: any) => {
|
||||||
|
console.error('提示音播放失败', err)
|
||||||
|
// 播放失败时尝试使用本地提示音
|
||||||
|
tryFallbackSound()
|
||||||
|
})
|
||||||
|
|
||||||
|
audioContext.onEnded(() => {
|
||||||
|
audioContext.destroy()
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.error('播放提示音异常', e)
|
||||||
|
}
|
||||||
|
}, [state.soundEnabled])
|
||||||
|
|
||||||
|
// 备用提示音方案(使用微信震动)
|
||||||
|
const tryFallbackSound = useCallback(() => {
|
||||||
|
try {
|
||||||
|
// 震动提示
|
||||||
|
Taro.vibrateShort({ type: 'heavy' })
|
||||||
|
} catch (e) {
|
||||||
|
console.error('震动提示失败', e)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 获取未读订单数量
|
||||||
|
const fetchUnreadCount = useCallback(async () => {
|
||||||
|
const riderId = getRiderId()
|
||||||
|
if (!riderId) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await pageGltTicketOrder({
|
||||||
|
riderId,
|
||||||
|
deliveryStatus: 10, // 待配送状态
|
||||||
|
page: 1,
|
||||||
|
limit: 1
|
||||||
|
} as any)
|
||||||
|
|
||||||
|
const pendingCount = res?.count || 0
|
||||||
|
const currentLastId = res?.list?.[0]?.id
|
||||||
|
|
||||||
|
// 如果数量增加,说明有新订单,播放提示音
|
||||||
|
if (pendingCount > lastCountRef.current && lastCountRef.current > 0) {
|
||||||
|
playSound()
|
||||||
|
}
|
||||||
|
|
||||||
|
lastCountRef.current = pendingCount
|
||||||
|
|
||||||
|
if (isMountedRef.current) {
|
||||||
|
setState(prev => ({
|
||||||
|
...prev,
|
||||||
|
pendingCount,
|
||||||
|
lastOrderId: currentLastId || prev.lastOrderId
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('获取未读订单失败', e)
|
||||||
|
}
|
||||||
|
}, [getRiderId, playSound])
|
||||||
|
|
||||||
|
// 开始轮询
|
||||||
|
const startPolling = useCallback(() => {
|
||||||
|
if (pollTimerRef.current) return
|
||||||
|
|
||||||
|
// 立即执行一次
|
||||||
|
fetchUnreadCount()
|
||||||
|
|
||||||
|
// 设置定时器
|
||||||
|
pollTimerRef.current = setInterval(() => {
|
||||||
|
fetchUnreadCount()
|
||||||
|
}, POLL_INTERVAL)
|
||||||
|
|
||||||
|
setState(prev => ({ ...prev, isPolling: true }))
|
||||||
|
}, [fetchUnreadCount])
|
||||||
|
|
||||||
|
// 停止轮询
|
||||||
|
const stopPolling = useCallback(() => {
|
||||||
|
if (pollTimerRef.current) {
|
||||||
|
clearInterval(pollTimerRef.current)
|
||||||
|
pollTimerRef.current = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 停止音频
|
||||||
|
if (audioContextRef.current) {
|
||||||
|
audioContextRef.current.stop()
|
||||||
|
audioContextRef.current.destroy()
|
||||||
|
audioContextRef.current = null
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(prev => ({ ...prev, isPolling: false }))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 刷新数据
|
||||||
|
const refresh = useCallback(async () => {
|
||||||
|
lastCountRef.current = 0 // 重置计数,强制刷新
|
||||||
|
await fetchUnreadCount()
|
||||||
|
}, [fetchUnreadCount])
|
||||||
|
|
||||||
|
// 切换声音开关
|
||||||
|
const toggleSound = useCallback(() => {
|
||||||
|
setState(prev => {
|
||||||
|
const newEnabled = !prev.soundEnabled
|
||||||
|
saveSoundSetting(newEnabled)
|
||||||
|
return { ...prev, soundEnabled: newEnabled }
|
||||||
|
})
|
||||||
|
}, [saveSoundSetting])
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
useEffect(() => {
|
||||||
|
isMountedRef.current = true
|
||||||
|
|
||||||
|
// 加载声音设置
|
||||||
|
const soundEnabled = loadSoundSetting()
|
||||||
|
setState(prev => ({ ...prev, soundEnabled }))
|
||||||
|
|
||||||
|
// 自动开始轮询
|
||||||
|
if (autoStart) {
|
||||||
|
startPolling()
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMountedRef.current = false
|
||||||
|
stopPolling()
|
||||||
|
}
|
||||||
|
}, [autoStart, loadSoundSetting, startPolling, stopPolling])
|
||||||
|
|
||||||
|
// 监听页面显示/隐藏
|
||||||
|
useEffect(() => {
|
||||||
|
const onShow = () => {
|
||||||
|
if (!state.isPolling) {
|
||||||
|
startPolling()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onHide = () => {
|
||||||
|
// 页面隐藏时停止轮询节省电量
|
||||||
|
// stopPolling()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信小程序监听
|
||||||
|
if (typeof Taro.onAppShow === 'function') {
|
||||||
|
Taro.onAppShow(onShow)
|
||||||
|
}
|
||||||
|
if (typeof Taro.onAppHide === 'function') {
|
||||||
|
Taro.onAppHide(onHide)
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (typeof Taro.offAppShow === 'function') {
|
||||||
|
Taro.offAppShow(onShow)
|
||||||
|
}
|
||||||
|
if (typeof Taro.offAppHide === 'function') {
|
||||||
|
Taro.offAppHide(onHide)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [state.isPolling, startPolling])
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
startPolling,
|
||||||
|
stopPolling,
|
||||||
|
refresh,
|
||||||
|
toggleSound,
|
||||||
|
playSound
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useRiderNotification
|
||||||
@@ -217,8 +217,8 @@ function Home() {
|
|||||||
title: '立即送水',
|
title: '立即送水',
|
||||||
icon: <Cart size={30} />,
|
icon: <Cart size={30} />,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (!ensureLoggedIn('/user/ticket/use?goodsId=10074')) return
|
if (!ensureLoggedIn('/user/ticket/use')) return
|
||||||
Taro.navigateTo({ url: '/user/ticket/use?goodsId=10074' })
|
Taro.navigateTo({ url: '/user/ticket/use' })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -226,8 +226,9 @@ function Home() {
|
|||||||
title: '送水订单',
|
title: '送水订单',
|
||||||
icon: <Agenda size={30} />,
|
icon: <Agenda size={30} />,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (!ensureLoggedIn('/user/ticket/index')) return
|
const url = '/user/ticket/index?tab=order'
|
||||||
Taro.navigateTo({ url: '/user/ticket/index' })
|
if (!ensureLoggedIn(url)) return
|
||||||
|
Taro.navigateTo({ url })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {useThemeStyles} from "@/hooks/useTheme";
|
|||||||
import {getRootDomain} from "@/utils/domain";
|
import {getRootDomain} from "@/utils/domain";
|
||||||
import { getMyGltUserTicketTotal } from '@/api/glt/gltUserTicket'
|
import { getMyGltUserTicketTotal } from '@/api/glt/gltUserTicket'
|
||||||
import { saveStorageByLoginUser } from '@/utils/server'
|
import { saveStorageByLoginUser } from '@/utils/server'
|
||||||
|
import { getUserLevelName, getUserLevelConfig } from '@/utils/userLevel'
|
||||||
|
|
||||||
const UserCard = forwardRef<any, any>((_, ref) => {
|
const UserCard = forwardRef<any, any>((_, ref) => {
|
||||||
const {data, refresh} = useUserData()
|
const {data, refresh} = useUserData()
|
||||||
@@ -33,11 +34,26 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
return userInfo.nickname || (userInfo as any).realName || (userInfo as any).username || (IsLogin ? '用户' : '点击登录')
|
return userInfo.nickname || (userInfo as any).realName || (userInfo as any).username || (IsLogin ? '用户' : '点击登录')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 角色名称:优先取用户 roles 数组的第一个角色名称
|
// 角色名称:优先使用 dealerLevel 显示四种分级,否则取用户 roles 数组的第一个角色名称
|
||||||
const getRoleName = () => {
|
const getRoleName = () => {
|
||||||
|
const dealerLevel = (userInfo as any)?.dealerLevel
|
||||||
|
if (dealerLevel !== undefined && dealerLevel !== null) {
|
||||||
|
return getUserLevelName(dealerLevel)
|
||||||
|
}
|
||||||
return userInfo?.roles?.[0]?.roleName || userInfo?.roleName || '注册用户'
|
return userInfo?.roles?.[0]?.roleName || userInfo?.roleName || '注册用户'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户等级配置(用于自定义样式)
|
||||||
|
const getRoleLevelConfig = () => {
|
||||||
|
const dealerLevel = (userInfo as any)?.dealerLevel
|
||||||
|
if (dealerLevel !== undefined && dealerLevel !== null) {
|
||||||
|
return getUserLevelConfig(dealerLevel)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleLevelConfig = getRoleLevelConfig()
|
||||||
|
|
||||||
// 下拉刷新
|
// 下拉刷新
|
||||||
const reloadStats = async (showToast = false) => {
|
const reloadStats = async (showToast = false) => {
|
||||||
await refresh()
|
await refresh()
|
||||||
@@ -267,7 +283,22 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
<View className={'flex flex-col'}>
|
<View className={'flex flex-col'}>
|
||||||
<Text style={{color: '#ffffff'}}>{getDisplayName() || '点击登录'}</Text>
|
<Text style={{color: '#ffffff'}}>{getDisplayName() || '点击登录'}</Text>
|
||||||
{getRootDomain() && (
|
{getRootDomain() && (
|
||||||
<View><Tag type="success">{getRoleName()}</Tag></View>
|
<View>
|
||||||
|
{roleLevelConfig ? (
|
||||||
|
<Tag
|
||||||
|
type={roleLevelConfig.tagType as any}
|
||||||
|
style={{
|
||||||
|
backgroundColor: roleLevelConfig.bgColor,
|
||||||
|
color: roleLevelConfig.textColor,
|
||||||
|
borderColor: roleLevelConfig.borderColor,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{getRoleName()}
|
||||||
|
</Tag>
|
||||||
|
) : (
|
||||||
|
<Tag type="success">{getRoleName()}</Tag>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import {loginBySms} from "@/api/passport/login";
|
import {loginBySms} from "@/api/passport/login";
|
||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
|
import {View,Text} from '@tarojs/components'
|
||||||
import {Popup} from '@nutui/nutui-react-taro'
|
import {Popup} from '@nutui/nutui-react-taro'
|
||||||
import {UserParam} from "@/api/system/user/model";
|
import {UserParam} from "@/api/system/user/model";
|
||||||
import {Button} from '@nutui/nutui-react-taro'
|
import {Button, Image} from '@nutui/nutui-react-taro'
|
||||||
import {Form, Input} from '@nutui/nutui-react-taro'
|
import {Form, Input} from '@nutui/nutui-react-taro'
|
||||||
import {Copyright, Version} from "@/config/app";
|
import {Copyright} from "@/config/app";
|
||||||
const UserFooter = () => {
|
const UserFooter = () => {
|
||||||
const [openLoginByPhone, setOpenLoginByPhone] = useState(false)
|
const [openLoginByPhone, setOpenLoginByPhone] = useState(false)
|
||||||
const [clickNum, setClickNum] = useState<number>(0)
|
const [clickNum, setClickNum] = useState<number>(0)
|
||||||
@@ -46,11 +47,14 @@ const UserFooter = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={'text-center py-4 w-full text-gray-300'} onClick={onLoginByPhone}>
|
<View className={'text-center py-4 w-full text-gray-300'} onClick={onLoginByPhone}>
|
||||||
{/*<div className={'text-xs text-gray-400 py-1'}>当前版本:{Version}</div>*/}
|
{/*<View className={'text-xs text-gray-400 py-1'}>当前版本:{Version}</View>*/}
|
||||||
{/*<div className={'text-xs text-gray-400 py-1'}>Copyright © { new Date().getFullYear() } {Copyright}</div>*/}
|
{/*<View className={'text-xs text-gray-400 py-1'}>Copyright © { new Date().getFullYear() } {Copyright}</View>*/}
|
||||||
<div className={'text-xs text-gray-400 py-1'}>{Copyright}</div>
|
<View className={'text-xs text-gray-400 py-1 flex justify-center items-center gap-2'}>
|
||||||
</div>
|
<Image src={'https://oss.wsdns.cn/20260412/7d03ec2a05964c3e926c4eac12ee5835.png'} mode={'aspectFit'} width={20} height={20} />
|
||||||
|
<Text>{Copyright}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
<Popup
|
<Popup
|
||||||
style={{width: '350px', padding: '10px'}}
|
style={{width: '350px', padding: '10px'}}
|
||||||
@@ -66,7 +70,7 @@ const UserFooter = () => {
|
|||||||
labelPosition="left"
|
labelPosition="left"
|
||||||
onFinish={(values) => submitByPhone(values)}
|
onFinish={(values) => submitByPhone(values)}
|
||||||
footer={
|
footer={
|
||||||
<div
|
<View
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
@@ -76,7 +80,7 @@ const UserFooter = () => {
|
|||||||
<Button nativeType="submit" block style={{backgroundColor: '#000000',color: '#ffffff'}}>
|
<Button nativeType="submit" block style={{backgroundColor: '#000000',color: '#ffffff'}}>
|
||||||
提交
|
提交
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</View>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import {View, Text} from '@tarojs/components'
|
import {View, Text} from '@tarojs/components'
|
||||||
import {ConfigProvider, Button, Grid, Avatar} from '@nutui/nutui-react-taro'
|
import {ConfigProvider, Button, Grid, Avatar, Badge} from '@nutui/nutui-react-taro'
|
||||||
import {
|
import {
|
||||||
User,
|
User,
|
||||||
Shopping,
|
Shopping,
|
||||||
@@ -8,11 +8,15 @@ import {
|
|||||||
ArrowRight,
|
ArrowRight,
|
||||||
Purse,
|
Purse,
|
||||||
People,
|
People,
|
||||||
Scan
|
Scan,
|
||||||
|
Setting
|
||||||
} from '@nutui/icons-react-taro'
|
} from '@nutui/icons-react-taro'
|
||||||
import {useDealerUser} from '@/hooks/useDealerUser'
|
import {useDealerUser} from '@/hooks/useDealerUser'
|
||||||
|
import {useUser} from '@/hooks/useUser'
|
||||||
import { useThemeStyles } from '@/hooks/useTheme'
|
import { useThemeStyles } from '@/hooks/useTheme'
|
||||||
|
import { useRiderNotification } from '@/hooks/useRiderNotification'
|
||||||
import {businessGradients, cardGradients, gradientUtils} from '@/styles/gradients'
|
import {businessGradients, cardGradients, gradientUtils} from '@/styles/gradients'
|
||||||
|
import {updateShopDealerUser} from '@/api/shop/shopDealerUser'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
|
|
||||||
const DealerIndex: React.FC = () => {
|
const DealerIndex: React.FC = () => {
|
||||||
@@ -22,6 +26,18 @@ const DealerIndex: React.FC = () => {
|
|||||||
refresh,
|
refresh,
|
||||||
} = useDealerUser()
|
} = useDealerUser()
|
||||||
|
|
||||||
|
// 获取用户角色信息
|
||||||
|
const { hasRole } = useUser()
|
||||||
|
|
||||||
|
// 配送员通知功能
|
||||||
|
const { pendingCount, startPolling, stopPolling, soundEnabled, toggleSound } = useRiderNotification()
|
||||||
|
|
||||||
|
// 页面生命周期管理
|
||||||
|
useEffect(() => {
|
||||||
|
startPolling()
|
||||||
|
return () => stopPolling()
|
||||||
|
}, [startPolling, stopPolling])
|
||||||
|
|
||||||
// 使用主题样式
|
// 使用主题样式
|
||||||
const themeStyles = useThemeStyles()
|
const themeStyles = useThemeStyles()
|
||||||
|
|
||||||
@@ -56,6 +72,109 @@ const DealerIndex: React.FC = () => {
|
|||||||
|
|
||||||
console.log(getGradientBackground(),'getGradientBackground()')
|
console.log(getGradientBackground(),'getGradientBackground()')
|
||||||
|
|
||||||
|
// 判断是否是配送员
|
||||||
|
const isRider = hasRole('rider')
|
||||||
|
|
||||||
|
// 请求订阅消息授权
|
||||||
|
const handleRequestSubscribeMessage = () => {
|
||||||
|
// 微信订阅消息模板ID(需在微信公众平台配置后替换)
|
||||||
|
const templateIds = [
|
||||||
|
'YOUR_TEMPLATE_ID', // TODO: 替换为实际的订阅消息模板ID
|
||||||
|
]
|
||||||
|
|
||||||
|
// 过滤出有效的模板ID
|
||||||
|
const validTemplateIds = templateIds.filter(id => id && !id.includes('YOUR_'))
|
||||||
|
|
||||||
|
if (validTemplateIds.length === 0) {
|
||||||
|
Taro.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '订阅消息功能尚未配置,请联系管理员',
|
||||||
|
showCancel: false
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求订阅
|
||||||
|
Taro.requestSubscribeMessage({
|
||||||
|
tmplIds: validTemplateIds,
|
||||||
|
entityIds: [], // 支付宝模板ID(微信端不需要,仅满足类型要求)
|
||||||
|
success: (res) => {
|
||||||
|
console.log('订阅消息授权结果:', res)
|
||||||
|
const accepted = Object.values(res).some(v => v === 'accept')
|
||||||
|
if (accepted) {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '订阅成功',
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
// 保存授权状态到本地
|
||||||
|
Taro.setStorageSync('rider_subscribed', '1')
|
||||||
|
} else {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '您已拒绝订阅',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('订阅消息授权失败:', err)
|
||||||
|
Taro.showToast({
|
||||||
|
title: '授权失败',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} as Taro.requestSubscribeMessage.Option)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击待使用金额 - 配送员专用:将冻结金额转入可提现
|
||||||
|
const handleFreezeMoneyClick = async () => {
|
||||||
|
// 检查是否是配送员
|
||||||
|
if (!isRider) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查冻结金额是否为 0
|
||||||
|
const freezeMoney = Number(dealerUser?.freezeMoney ?? 0)
|
||||||
|
if (freezeMoney <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 弹出确认框
|
||||||
|
Taro.showModal({
|
||||||
|
title: '确认操作',
|
||||||
|
content: `确定要将 ¥${freezeMoney.toFixed(2)} 转入钱包吗?`,
|
||||||
|
confirmText: '确定',
|
||||||
|
cancelText: '取消',
|
||||||
|
success: async (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
try {
|
||||||
|
Taro.showLoading({ title: '处理中...' })
|
||||||
|
const currentMoney = Number(dealerUser?.money ?? 0)
|
||||||
|
await updateShopDealerUser({
|
||||||
|
id: dealerUser?.id,
|
||||||
|
money: (currentMoney + freezeMoney).toFixed(2),
|
||||||
|
freezeMoney: '0.00'
|
||||||
|
})
|
||||||
|
Taro.hideLoading()
|
||||||
|
Taro.showToast({
|
||||||
|
title: '更新成功',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 1500
|
||||||
|
})
|
||||||
|
// 刷新数据
|
||||||
|
refresh()
|
||||||
|
} catch (error) {
|
||||||
|
Taro.hideLoading()
|
||||||
|
Taro.showToast({
|
||||||
|
title: '更新失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 1500
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<View className="p-4">
|
<View className="p-4">
|
||||||
@@ -74,7 +193,14 @@ const DealerIndex: React.FC = () => {
|
|||||||
<View>
|
<View>
|
||||||
{/*头部信息*/}
|
{/*头部信息*/}
|
||||||
{dealerUser && (
|
{dealerUser && (
|
||||||
<View className="px-4 py-6 relative overflow-hidden" style={themeStyles.primaryBackground}>
|
<View
|
||||||
|
className="px-4 py-6 relative overflow-hidden"
|
||||||
|
style={{
|
||||||
|
...themeStyles.primaryBackground,
|
||||||
|
background: businessGradients.order.processing,
|
||||||
|
color: '#ffffff'
|
||||||
|
}}
|
||||||
|
>
|
||||||
{/* 装饰性背景元素 - 小程序兼容版本 */}
|
{/* 装饰性背景元素 - 小程序兼容版本 */}
|
||||||
<View className="absolute w-32 h-32 rounded-full" style={{
|
<View className="absolute w-32 h-32 rounded-full" style={{
|
||||||
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
backgroundColor: 'rgba(255, 255, 255, 0.1)',
|
||||||
@@ -141,13 +267,20 @@ const DealerIndex: React.FC = () => {
|
|||||||
</Text>
|
</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>
|
||||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
<View
|
||||||
background: businessGradients.money.frozen
|
className="text-center p-3 rounded-lg flex flex-col"
|
||||||
}}>
|
style={{
|
||||||
|
background: businessGradients.money.frozen,
|
||||||
|
opacity: isRider && Number(dealerUser.freezeMoney ?? 0) > 0 ? 1 : 0.8
|
||||||
|
}}
|
||||||
|
onClick={isRider && Number(dealerUser.freezeMoney ?? 0) > 0 ? handleFreezeMoneyClick : undefined}
|
||||||
|
>
|
||||||
<Text className="text-lg font-bold mb-1 text-white">
|
<Text className="text-lg font-bold mb-1 text-white">
|
||||||
{formatMoney(dealerUser.freezeMoney)}
|
{formatMoney(dealerUser.freezeMoney)}
|
||||||
</Text>
|
</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)' }}>
|
||||||
|
{isRider && Number(dealerUser.freezeMoney ?? 0) > 0 ? '待使用' : '待使用'}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
||||||
background: businessGradients.money.total
|
background: businessGradients.money.total
|
||||||
@@ -212,13 +345,20 @@ const DealerIndex: React.FC = () => {
|
|||||||
>
|
>
|
||||||
<Grid.Item text="配送订单" onClick={() => navigateToPage('/rider/orders/index')}>
|
<Grid.Item text="配送订单" onClick={() => navigateToPage('/rider/orders/index')}>
|
||||||
<View className="text-center">
|
<View className="text-center">
|
||||||
<View className="w-12 h-12 bg-blue-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
<View className="w-12 h-12 bg-blue-50 rounded-xl flex items-center justify-center mx-auto mb-2 relative">
|
||||||
<Shopping color="#3b82f6" size="20"/>
|
<Shopping color="#3b82f6" size="20"/>
|
||||||
|
{pendingCount > 0 && (
|
||||||
|
<Badge
|
||||||
|
value={pendingCount > 99 ? '99+' : pendingCount}
|
||||||
|
max={99}
|
||||||
|
style={{ position: 'absolute', top: '-4px', right: '-4px' }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</Grid.Item>
|
</Grid.Item>
|
||||||
|
|
||||||
<Grid.Item text={'工资明细'} onClick={() => navigateToPage('/rider/withdraw/index')}>
|
<Grid.Item text={'收入明细'} onClick={() => navigateToPage('/rider/withdraw/index')}>
|
||||||
<View className="text-center">
|
<View className="text-center">
|
||||||
<View className="w-12 h-12 bg-green-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
<View className="w-12 h-12 bg-green-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
||||||
<Purse color="#10b981" size="20"/>
|
<Purse color="#10b981" size="20"/>
|
||||||
@@ -251,46 +391,96 @@ const DealerIndex: React.FC = () => {
|
|||||||
</Grid.Item>
|
</Grid.Item>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
{/* 第二行功能 */}
|
{/* 第二行功能 - 通知设置 */}
|
||||||
{/*<Grid*/}
|
<Grid
|
||||||
{/* columns={4}*/}
|
columns={4}
|
||||||
{/* className="no-border-grid mt-4"*/}
|
className="no-border-grid mt-4"
|
||||||
{/* style={{*/}
|
style={{
|
||||||
{/* '--nutui-grid-border-color': 'transparent',*/}
|
'--nutui-grid-border-color': 'transparent',
|
||||||
{/* '--nutui-grid-item-border-width': '0px',*/}
|
'--nutui-grid-item-border-width': '0px',
|
||||||
{/* border: 'none'*/}
|
border: 'none'
|
||||||
{/* } as React.CSSProperties}*/}
|
} as React.CSSProperties}
|
||||||
{/*>*/}
|
>
|
||||||
{/* <Grid.Item text={'邀请统计'} onClick={() => navigateToPage('/dealer/invite-stats/index')}>*/}
|
<Grid.Item text={'通知设置'} onClick={() => {
|
||||||
{/* <View className="text-center">*/}
|
const isSubscribed = Taro.getStorageSync('rider_subscribed') === '1'
|
||||||
{/* <View className="w-12 h-12 bg-indigo-50 rounded-xl flex items-center justify-center mx-auto mb-2">*/}
|
Taro.showModal({
|
||||||
{/* <Presentation color="#6366f1" size="20"/>*/}
|
title: '通知设置',
|
||||||
{/* </View>*/}
|
content: `声音提醒:${soundEnabled ? '已开启' : '已关闭'}\n订阅消息:${isSubscribed ? '已订阅' : '未订阅'}`,
|
||||||
{/* </View>*/}
|
confirmText: '更多设置',
|
||||||
{/* </Grid.Item>*/}
|
cancelText: '关闭',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
// 显示更多设置选项
|
||||||
|
Taro.showActionSheet({
|
||||||
|
itemList: [
|
||||||
|
soundEnabled ? '关闭声音提醒' : '开启声音提醒',
|
||||||
|
isSubscribed ? '订阅状态正常' : '订阅消息通知',
|
||||||
|
'检查更新'
|
||||||
|
],
|
||||||
|
success: (sheetRes) => {
|
||||||
|
if (sheetRes.tapIndex === 0) {
|
||||||
|
// 切换声音
|
||||||
|
toggleSound()
|
||||||
|
Taro.showToast({
|
||||||
|
title: soundEnabled ? '已关闭声音' : '已开启声音',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
} else if (sheetRes.tapIndex === 1) {
|
||||||
|
// 订阅消息
|
||||||
|
if (!isSubscribed) {
|
||||||
|
handleRequestSubscribeMessage()
|
||||||
|
} else {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '已订阅消息通知',
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if (sheetRes.tapIndex === 2) {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '已是最新版本',
|
||||||
|
icon: 'success'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}>
|
||||||
|
<View className="text-center">
|
||||||
|
<View className="w-12 h-12 bg-indigo-50 rounded-xl flex items-center justify-center mx-auto mb-2 relative">
|
||||||
|
<Setting color={soundEnabled ? '#6366f1' : '#9ca3af'} size="20"/>
|
||||||
|
{soundEnabled ? (
|
||||||
|
<View className="absolute -bottom-1 -right-1 w-3 h-3 bg-green-500 rounded-full border-2 border-white"></View>
|
||||||
|
) : (
|
||||||
|
<View className="absolute -bottom-1 -right-1 w-3 h-3 bg-gray-400 rounded-full border-2 border-white"></View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Grid.Item>
|
||||||
|
|
||||||
{/* /!* 预留其他功能位置 *!/*/}
|
{/* 预留功能位置 */}
|
||||||
{/* <Grid.Item text={''}>*/}
|
<Grid.Item text={''}>
|
||||||
{/* <View className="text-center">*/}
|
<View className="text-center">
|
||||||
{/* <View className="w-12 h-12 bg-gray-50 rounded-xl flex items-center justify-center mx-auto mb-2">*/}
|
<View className="w-12 h-12 bg-gray-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
||||||
{/* </View>*/}
|
</View>
|
||||||
{/* </View>*/}
|
</View>
|
||||||
{/* </Grid.Item>*/}
|
</Grid.Item>
|
||||||
|
|
||||||
{/* <Grid.Item text={''}>*/}
|
<Grid.Item text={''}>
|
||||||
{/* <View className="text-center">*/}
|
<View className="text-center">
|
||||||
{/* <View className="w-12 h-12 bg-gray-50 rounded-xl flex items-center justify-center mx-auto mb-2">*/}
|
<View className="w-12 h-12 bg-gray-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
||||||
{/* </View>*/}
|
</View>
|
||||||
{/* </View>*/}
|
</View>
|
||||||
{/* </Grid.Item>*/}
|
</Grid.Item>
|
||||||
|
|
||||||
{/* <Grid.Item text={''}>*/}
|
<Grid.Item text={''}>
|
||||||
{/* <View className="text-center">*/}
|
<View className="text-center">
|
||||||
{/* <View className="w-12 h-12 bg-gray-50 rounded-xl flex items-center justify-center mx-auto mb-2">*/}
|
<View className="w-12 h-12 bg-gray-50 rounded-xl flex items-center justify-center mx-auto mb-2">
|
||||||
{/* </View>*/}
|
</View>
|
||||||
{/* </View>*/}
|
</View>
|
||||||
{/* </Grid.Item>*/}
|
</Grid.Item>
|
||||||
{/*</Grid>*/}
|
</Grid>
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -73,6 +73,14 @@ export default function RiderOrders() {
|
|||||||
return '待派单'
|
return '待派单'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 配送方式中文映射
|
||||||
|
const getDeliveryMethodText = (method?: string) => {
|
||||||
|
if (method === 'elevator') return '电梯'
|
||||||
|
if (method === 'stairs') return '步梯'
|
||||||
|
if (method === 'groundFloor') return '一楼商铺/其他'
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
const getOrderStatusColor = (order: GltTicketOrder) => {
|
const getOrderStatusColor = (order: GltTicketOrder) => {
|
||||||
const text = getOrderStatusText(order)
|
const text = getOrderStatusText(order)
|
||||||
if (text === '已完成') return 'text-green-600'
|
if (text === '已完成') return 'text-green-600'
|
||||||
@@ -383,6 +391,10 @@ export default function RiderOrders() {
|
|||||||
const pickupName = o.warehouseName || o.storeName
|
const pickupName = o.warehouseName || o.storeName
|
||||||
const pickupAddr = o.warehouseAddress || o.storeAddress
|
const pickupAddr = o.warehouseAddress || o.storeAddress
|
||||||
|
|
||||||
|
// 配送方式信息
|
||||||
|
const deliveryMethodText = getDeliveryMethodText(o.deliveryMethod)
|
||||||
|
const hasDeliveryInfo = !!deliveryMethodText
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Cell key={String(o.id)} style={{ padding: '16px' }}>
|
<Cell key={String(o.id)} style={{ padding: '16px' }}>
|
||||||
<View className="w-full">
|
<View className="w-full">
|
||||||
@@ -418,6 +430,24 @@ export default function RiderOrders() {
|
|||||||
<Text>¥{o.price || '-'}</Text>
|
<Text>¥{o.price || '-'}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{hasDeliveryInfo && (
|
||||||
|
<View className="text-sm text-gray-700 mt-1">
|
||||||
|
<Text className="text-gray-500">配送方式:</Text>
|
||||||
|
<Text className={o.deliveryMethod === 'stairs' ? 'text-orange-500' : ''}>
|
||||||
|
{deliveryMethodText}
|
||||||
|
</Text>
|
||||||
|
{o.deliveryMethod === 'stairs' && o.deliveryFloor && o.deliveryFloor > 1 && (
|
||||||
|
<Text className="ml-1 text-orange-500">({o.deliveryFloor}楼)</Text>
|
||||||
|
)}
|
||||||
|
{o.deliveryMethod === 'stairs' && !o.deliveryFloor && (
|
||||||
|
<Text className="ml-1 text-gray-400">(不送上楼)</Text>
|
||||||
|
)}
|
||||||
|
{!!o.deliveryFee && o.deliveryFee > 0 && (
|
||||||
|
<Text className="ml-3 text-red-500">配送费 ¥{o.deliveryFee}</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
<View className="text-sm text-gray-700 mt-1">
|
<View className="text-sm text-gray-700 mt-1">
|
||||||
<Text className="text-gray-500">配送时间:</Text>
|
<Text className="text-gray-500">配送时间:</Text>
|
||||||
<Text>{o.sendTime ? dayjs(o.sendTime).format('YYYY-MM-DD HH:mm') : '-'}</Text>
|
<Text>{o.sendTime ? dayjs(o.sendTime).format('YYYY-MM-DD HH:mm') : '-'}</Text>
|
||||||
|
|||||||
@@ -377,6 +377,17 @@ const GoodsDetail = () => {
|
|||||||
<View className={"car-no text-lg"}>
|
<View className={"car-no text-lg"}>
|
||||||
{goods.name}
|
{goods.name}
|
||||||
</View>
|
</View>
|
||||||
|
{/* 活动/配送标签 */}
|
||||||
|
{(goods.activityType === 1 || goods.deliveryMode === 1) && (
|
||||||
|
<View className={"flex gap-1 py-1"}>
|
||||||
|
{goods.activityType === 1 && (
|
||||||
|
<Text className={"text-xs bg-red-500 text-white px-2 py-1 rounded-full"}>新用户专享</Text>
|
||||||
|
)}
|
||||||
|
{goods.deliveryMode === 1 && (
|
||||||
|
<Text className={"text-xs bg-orange-500 text-white px-2 py-1 rounded-full"}>仅限自提</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
<View className={"flex justify-between text-xs py-1"}>
|
<View className={"flex justify-between text-xs py-1"}>
|
||||||
<span className={"text-orange-500"}>
|
<span className={"text-orange-500"}>
|
||||||
{goods.comments}
|
{goods.comments}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.address-bottom-line{
|
.address-bottom-line{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 12rpx 12rpx 0 0;
|
border-radius: 12rpx 12rpx 0 0;
|
||||||
|
|||||||
@@ -9,10 +9,9 @@ import {
|
|||||||
ActionSheet,
|
ActionSheet,
|
||||||
Popup,
|
Popup,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
DatePicker,
|
|
||||||
ConfigProvider
|
ConfigProvider
|
||||||
} from '@nutui/nutui-react-taro'
|
} from '@nutui/nutui-react-taro'
|
||||||
import {Location, ArrowRight} from '@nutui/icons-react-taro'
|
import {Location, ArrowRight, Shop} from '@nutui/icons-react-taro'
|
||||||
import Taro, {useDidShow} from '@tarojs/taro'
|
import Taro, {useDidShow} from '@tarojs/taro'
|
||||||
import {ShopGoods} from "@/api/shop/shopGoods/model";
|
import {ShopGoods} from "@/api/shop/shopGoods/model";
|
||||||
import {getShopGoods} from "@/api/shop/shopGoods";
|
import {getShopGoods} from "@/api/shop/shopGoods";
|
||||||
@@ -39,7 +38,6 @@ import {
|
|||||||
filterUsableCoupons,
|
filterUsableCoupons,
|
||||||
filterUnusableCoupons
|
filterUnusableCoupons
|
||||||
} from "@/utils/couponUtils";
|
} from "@/utils/couponUtils";
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import type {ShopStore} from "@/api/shop/shopStore/model";
|
import type {ShopStore} from "@/api/shop/shopStore/model";
|
||||||
import {getShopStore, listShopStore} from "@/api/shop/shopStore";
|
import {getShopStore, listShopStore} from "@/api/shop/shopStore";
|
||||||
import {getSelectedStoreFromStorage, saveSelectedStoreToStorage} from "@/utils/storeSelection";
|
import {getSelectedStoreFromStorage, saveSelectedStoreToStorage} from "@/utils/storeSelection";
|
||||||
@@ -57,18 +55,6 @@ const OrderConfirm = () => {
|
|||||||
const [loading, setLoading] = useState<boolean>(true)
|
const [loading, setLoading] = useState<boolean>(true)
|
||||||
const [error, setError] = useState<string>('')
|
const [error, setError] = useState<string>('')
|
||||||
const [payLoading, setPayLoading] = useState<boolean>(false)
|
const [payLoading, setPayLoading] = useState<boolean>(false)
|
||||||
// 配送时间(仅水票套票商品需要)
|
|
||||||
// 当日截单时间:超过该时间下单,最早配送日顺延到次日(避免 21:00 下单仍显示“当天配送”)
|
|
||||||
const DELIVERY_CUTOFF_HOUR = 21
|
|
||||||
const getMinSendDate = () => {
|
|
||||||
const now = dayjs()
|
|
||||||
const cutoff = now.hour(DELIVERY_CUTOFF_HOUR).minute(0).second(0).millisecond(0)
|
|
||||||
const startOfToday = now.startOf('day')
|
|
||||||
// >= 截单时间则最早只能选次日
|
|
||||||
return now.isSame(cutoff) || now.isAfter(cutoff) ? startOfToday.add(1, 'day') : startOfToday
|
|
||||||
}
|
|
||||||
const [sendTime, setSendTime] = useState<Date>(() => getMinSendDate().toDate())
|
|
||||||
const [sendTimePickerVisible, setSendTimePickerVisible] = useState(false)
|
|
||||||
|
|
||||||
// 水票套票活动(若存在则按规则限制最小购买量等)
|
// 水票套票活动(若存在则按规则限制最小购买量等)
|
||||||
const [ticketTemplate, setTicketTemplate] = useState<GltTicketTemplate | null>(null)
|
const [ticketTemplate, setTicketTemplate] = useState<GltTicketTemplate | null>(null)
|
||||||
@@ -89,24 +75,69 @@ const OrderConfirm = () => {
|
|||||||
const [availableCoupons, setAvailableCoupons] = useState<CouponCardProps[]>([])
|
const [availableCoupons, setAvailableCoupons] = useState<CouponCardProps[]>([])
|
||||||
const [couponLoading, setCouponLoading] = useState<boolean>(false)
|
const [couponLoading, setCouponLoading] = useState<boolean>(false)
|
||||||
|
|
||||||
// 门店选择:用于在下单页展示当前“已选门店”,并允许用户切换(写入 SelectedStore Storage)
|
// 门店选择:用于在下单页展示当前"已选门店",并允许用户切换(写入 SelectedStore Storage)
|
||||||
const [storePopupVisible, setStorePopupVisible] = useState(false)
|
const [storePopupVisible, setStorePopupVisible] = useState(false)
|
||||||
const [stores, setStores] = useState<ShopStore[]>([])
|
const [stores, setStores] = useState<ShopStore[]>([])
|
||||||
const [storeLoading, setStoreLoading] = useState(false)
|
const [storeLoading, setStoreLoading] = useState(false)
|
||||||
const [selectedStore, setSelectedStore] = useState<ShopStore | null>(getSelectedStoreFromStorage())
|
const [selectedStore, setSelectedStore] = useState<ShopStore | null>(getSelectedStoreFromStorage())
|
||||||
|
|
||||||
const router = Taro.getCurrentInstance().router;
|
const router = Taro.getCurrentInstance().router;
|
||||||
const goodsId = router?.params?.goodsId;
|
const params = router?.params || ({} as Record<string, any>)
|
||||||
|
const goodsIdParam = params?.goodsId
|
||||||
|
const orderDataRaw = params?.orderData
|
||||||
|
|
||||||
|
type OrderDataParam = {
|
||||||
|
goodsId?: number | string
|
||||||
|
skuId?: number | string
|
||||||
|
quantity?: number | string
|
||||||
|
price?: number | string
|
||||||
|
specInfo?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderDataParam: OrderDataParam | null = useMemo(() => {
|
||||||
|
if (!orderDataRaw) return null
|
||||||
|
const rawText = String(orderDataRaw)
|
||||||
|
try {
|
||||||
|
return JSON.parse(decodeURIComponent(rawText)) as OrderDataParam
|
||||||
|
} catch (_e1) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(rawText) as OrderDataParam
|
||||||
|
} catch (_e2) {
|
||||||
|
console.error('orderData 参数解析失败:', orderDataRaw)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [orderDataRaw])
|
||||||
|
|
||||||
|
const resolvedGoodsId = (() => {
|
||||||
|
const id1 = Number(goodsIdParam)
|
||||||
|
if (Number.isFinite(id1) && id1 > 0) return id1
|
||||||
|
const id2 = Number(orderDataParam?.goodsId)
|
||||||
|
if (Number.isFinite(id2) && id2 > 0) return id2
|
||||||
|
return undefined
|
||||||
|
})()
|
||||||
|
|
||||||
|
const resolvedSkuId = (() => {
|
||||||
|
const n = Number(orderDataParam?.skuId)
|
||||||
|
return Number.isFinite(n) && n > 0 ? n : undefined
|
||||||
|
})()
|
||||||
|
|
||||||
|
const quantityFromParam = (() => {
|
||||||
|
const n = Number(orderDataParam?.quantity)
|
||||||
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : undefined
|
||||||
|
})()
|
||||||
|
|
||||||
// 页面级兜底:未登录直接进入下单页时,引导去注册/登录并回跳
|
// 页面级兜底:未登录直接进入下单页时,引导去注册/登录并回跳
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!goodsId) {
|
// 兼容 goodsId / orderData 两种进入方式(goodsDetail 有规格时会走 orderData)
|
||||||
// 也可能是 orderData 模式;这里只做最小兜底
|
const backUrl =
|
||||||
if (!ensureLoggedIn('/shop/orderConfirm/index')) return
|
orderDataRaw
|
||||||
return
|
? `/shop/orderConfirm/index?orderData=${orderDataRaw}`
|
||||||
}
|
: resolvedGoodsId
|
||||||
if (!ensureLoggedIn(`/shop/orderConfirm/index?goodsId=${goodsId}`)) return
|
? `/shop/orderConfirm/index?goodsId=${resolvedGoodsId}`
|
||||||
}, [goodsId])
|
: '/shop/orderConfirm/index'
|
||||||
|
if (!ensureLoggedIn(backUrl)) return
|
||||||
|
}, [resolvedGoodsId, orderDataRaw])
|
||||||
|
|
||||||
const isTicketTemplateActive =
|
const isTicketTemplateActive =
|
||||||
!!ticketTemplate &&
|
!!ticketTemplate &&
|
||||||
@@ -122,10 +153,6 @@ const OrderConfirm = () => {
|
|||||||
})()
|
})()
|
||||||
const minBuyQty = isTicketTemplateActive ? ticketMinBuyQty : 1
|
const minBuyQty = isTicketTemplateActive ? ticketMinBuyQty : 1
|
||||||
|
|
||||||
const sendTimeText = useMemo(() => {
|
|
||||||
return dayjs(sendTime).format('YYYY-MM-DD')
|
|
||||||
}, [sendTime])
|
|
||||||
|
|
||||||
const getGiftTicketQty = (buyQty: number) => {
|
const getGiftTicketQty = (buyQty: number) => {
|
||||||
if (!isTicketTemplateActive) return 0
|
if (!isTicketTemplateActive) return 0
|
||||||
const multiplier = Number(ticketTemplate?.giftMultiplier || 0)
|
const multiplier = Number(ticketTemplate?.giftMultiplier || 0)
|
||||||
@@ -160,7 +187,9 @@ const OrderConfirm = () => {
|
|||||||
// 计算商品总价
|
// 计算商品总价
|
||||||
const getGoodsTotal = () => {
|
const getGoodsTotal = () => {
|
||||||
if (!goods) return 0
|
if (!goods) return 0
|
||||||
const price = parseFloat(goods.price || '0')
|
const rawPrice = String(orderDataParam?.price ?? goods.price ?? '0')
|
||||||
|
const priceNum = parseFloat(rawPrice)
|
||||||
|
const price = Number.isFinite(priceNum) ? priceNum : 0
|
||||||
// const total = price * quantity
|
// const total = price * quantity
|
||||||
|
|
||||||
// 🔍 详细日志,用于排查数值精度问题
|
// 🔍 详细日志,用于排查数值精度问题
|
||||||
@@ -201,12 +230,21 @@ const OrderConfirm = () => {
|
|||||||
const handleQuantityChange = (value: string | number) => {
|
const handleQuantityChange = (value: string | number) => {
|
||||||
const fallback = isTicketTemplateActive ? minBuyQty : 1
|
const fallback = isTicketTemplateActive ? minBuyQty : 1
|
||||||
const newQuantity = typeof value === 'string' ? parseInt(value, 10) || fallback : value
|
const newQuantity = typeof value === 'string' ? parseInt(value, 10) || fallback : value
|
||||||
const finalQuantity = Math.max(fallback, Math.min(newQuantity, goods?.stock || 999))
|
const step = goods?.step || 1
|
||||||
|
const stockMax = goods?.stock ?? 999
|
||||||
|
const maxMultiple = step > 1 ? Math.floor(stockMax / step) * step : stockMax
|
||||||
|
const maxAllowed = maxMultiple > 0 ? maxMultiple : stockMax
|
||||||
|
const effectiveMin = Math.min(fallback, maxAllowed)
|
||||||
|
const clamped = Math.max(effectiveMin, Math.min(Number(newQuantity) || fallback, maxAllowed))
|
||||||
|
const snapped = step > 1 ? Math.ceil(clamped / step) * step : clamped
|
||||||
|
const finalQuantity = Math.max(effectiveMin, Math.min(snapped, maxAllowed))
|
||||||
setQuantity(finalQuantity)
|
setQuantity(finalQuantity)
|
||||||
|
|
||||||
// 数量变化时,重新排序优惠券并检查当前选中的优惠券是否还可用
|
// 数量变化时,重新排序优惠券并检查当前选中的优惠券是否还可用
|
||||||
if (availableCoupons.length > 0) {
|
if (availableCoupons.length > 0) {
|
||||||
const newTotal = parseFloat(goods?.price || '0') * finalQuantity
|
const priceNum = parseFloat(String(orderDataParam?.price ?? goods?.price ?? '0'))
|
||||||
|
const unitPrice = Number.isFinite(priceNum) ? priceNum : 0
|
||||||
|
const newTotal = unitPrice * finalQuantity
|
||||||
const sortedCoupons = sortCoupons(availableCoupons, newTotal)
|
const sortedCoupons = sortCoupons(availableCoupons, newTotal)
|
||||||
const usableCoupons = filterUsableCoupons(sortedCoupons, newTotal)
|
const usableCoupons = filterUsableCoupons(sortedCoupons, newTotal)
|
||||||
setAvailableCoupons(sortedCoupons)
|
setAvailableCoupons(sortedCoupons)
|
||||||
@@ -451,22 +489,7 @@ const OrderConfirm = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 水票套票商品:保存配送时间到 ShopOrder.sendStartTime
|
// 购买水票(囤券预付费)与水票核销(下单履约)为两个独立动作:下单页不再选择配送时间。
|
||||||
if (hasTicketTemplate && !sendTime) {
|
|
||||||
Taro.showToast({ title: '请选择配送时间', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (hasTicketTemplate) {
|
|
||||||
const min = getMinSendDate()
|
|
||||||
if (dayjs(sendTime).isBefore(min, 'day')) {
|
|
||||||
setSendTime(min.toDate())
|
|
||||||
Taro.showToast({
|
|
||||||
title: `已过当日${DELIVERY_CUTOFF_HOUR}点截单,最早配送:${min.format('YYYY-MM-DD')}`,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 水票套票活动:最小购买量校验
|
// 水票套票活动:最小购买量校验
|
||||||
if (isTicketTemplateActive && quantity < minBuyQty) {
|
if (isTicketTemplateActive && quantity < minBuyQty) {
|
||||||
@@ -528,19 +551,43 @@ const OrderConfirm = () => {
|
|||||||
address.id,
|
address.id,
|
||||||
{
|
{
|
||||||
comments: goods.name,
|
comments: goods.name,
|
||||||
deliveryType: 0,
|
deliveryType: goods.deliveryMode === 1 ? 1 : 0,
|
||||||
buyerRemarks: orderRemark,
|
buyerRemarks: orderRemark,
|
||||||
sendStartTime: hasTicketTemplate
|
couponId: parseInt(String(bestCoupon.id), 10),
|
||||||
? dayjs(sendTime).startOf('day').format('YYYY-MM-DD HH:mm:ss')
|
skuId: resolvedSkuId,
|
||||||
: undefined,
|
specInfo: orderDataParam?.specInfo
|
||||||
couponId: parseInt(String(bestCoupon.id), 10)
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('🎯 使用推荐优惠券的订单数据:', updatedOrderData);
|
console.log('🎯 使用推荐优惠券的订单数据:', updatedOrderData);
|
||||||
|
|
||||||
// 执行支付
|
// 执行支付
|
||||||
await PaymentHandler.pay(updatedOrderData, currentPaymentType);
|
await PaymentHandler.pay(updatedOrderData, currentPaymentType, hasTicketTemplate ? {
|
||||||
|
onSuccess: async () => {
|
||||||
|
const id = goods.goodsId
|
||||||
|
const ticketIndexUrl = `/user/ticket/index?fromPayAt=${Date.now()}`
|
||||||
|
try {
|
||||||
|
const res = await Taro.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '是否立刻送水?',
|
||||||
|
confirmText: '立刻送水',
|
||||||
|
cancelText: '稍后'
|
||||||
|
})
|
||||||
|
if (res?.confirm) {
|
||||||
|
if (id) {
|
||||||
|
await Taro.redirectTo({ url: `/user/ticket/use?goodsId=${id}` })
|
||||||
|
} else {
|
||||||
|
await Taro.redirectTo({ url: ticketIndexUrl })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await Taro.redirectTo({ url: ticketIndexUrl })
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
await Taro.redirectTo({ url: ticketIndexUrl })
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} : undefined);
|
||||||
return; // 提前返回,避免重复执行支付
|
return; // 提前返回,避免重复执行支付
|
||||||
} else {
|
} else {
|
||||||
// 用户选择不使用优惠券,继续支付
|
// 用户选择不使用优惠券,继续支付
|
||||||
@@ -556,13 +603,12 @@ const OrderConfirm = () => {
|
|||||||
address.id,
|
address.id,
|
||||||
{
|
{
|
||||||
comments: '桂乐淘',
|
comments: '桂乐淘',
|
||||||
deliveryType: 0,
|
deliveryType: goods.deliveryMode === 1 ? 1 : 0,
|
||||||
buyerRemarks: orderRemark,
|
buyerRemarks: orderRemark,
|
||||||
sendStartTime: hasTicketTemplate
|
|
||||||
? dayjs(sendTime).startOf('day').format('YYYY-MM-DD HH:mm:ss')
|
|
||||||
: undefined,
|
|
||||||
// 🔧 确保 couponId 是正确的数字类型,且不传递 undefined
|
// 🔧 确保 couponId 是正确的数字类型,且不传递 undefined
|
||||||
couponId: selectedCoupon ? parseInt(String(selectedCoupon.id), 10) : undefined
|
couponId: selectedCoupon ? parseInt(String(selectedCoupon.id), 10) : undefined,
|
||||||
|
skuId: resolvedSkuId,
|
||||||
|
specInfo: orderDataParam?.specInfo
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -595,7 +641,32 @@ const OrderConfirm = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 执行支付 - 移除这里的成功提示,让PaymentHandler统一处理
|
// 执行支付 - 移除这里的成功提示,让PaymentHandler统一处理
|
||||||
await PaymentHandler.pay(orderData, paymentType);
|
await PaymentHandler.pay(orderData, paymentType, hasTicketTemplate ? {
|
||||||
|
onSuccess: async () => {
|
||||||
|
const id = goods.goodsId
|
||||||
|
const ticketIndexUrl = `/user/ticket/index?fromPayAt=${Date.now()}`
|
||||||
|
try {
|
||||||
|
const res = await Taro.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '是否立刻送水?',
|
||||||
|
confirmText: '立刻送水',
|
||||||
|
cancelText: '稍后'
|
||||||
|
})
|
||||||
|
if (res?.confirm) {
|
||||||
|
if (id) {
|
||||||
|
await Taro.redirectTo({ url: `/user/ticket/use?goodsId=${id}` })
|
||||||
|
} else {
|
||||||
|
await Taro.redirectTo({ url: ticketIndexUrl })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await Taro.redirectTo({ url: ticketIndexUrl })
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
await Taro.redirectTo({ url: ticketIndexUrl })
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} : undefined);
|
||||||
|
|
||||||
// ✅ 移除双重成功提示 - PaymentHandler会处理成功提示
|
// ✅ 移除双重成功提示 - PaymentHandler会处理成功提示
|
||||||
// Taro.showToast({
|
// Taro.showToast({
|
||||||
@@ -633,7 +704,7 @@ const OrderConfirm = () => {
|
|||||||
message.includes('电子围栏') ||
|
message.includes('电子围栏') ||
|
||||||
message.includes('围栏')
|
message.includes('围栏')
|
||||||
|
|
||||||
// “配送范围”类错误给出更友好的解释,并提供快捷入口去更换收货地址
|
// "配送范围"类错误给出更友好的解释,并提供快捷入口去更换收货地址
|
||||||
if (isOutOfDeliveryRange) {
|
if (isOutOfDeliveryRange) {
|
||||||
try {
|
try {
|
||||||
const res = await Taro.showModal({
|
const res = await Taro.showModal({
|
||||||
@@ -673,8 +744,8 @@ const OrderConfirm = () => {
|
|||||||
|
|
||||||
// 分别加载数据,避免类型推断问题
|
// 分别加载数据,避免类型推断问题
|
||||||
let goodsRes: ShopGoods | null = null
|
let goodsRes: ShopGoods | null = null
|
||||||
if (goodsId) {
|
if (resolvedGoodsId) {
|
||||||
goodsRes = await getShopGoods(Number(goodsId))
|
goodsRes = await getShopGoods(resolvedGoodsId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const [addressRes, paymentRes] = await Promise.all([
|
const [addressRes, paymentRes] = await Promise.all([
|
||||||
@@ -685,9 +756,9 @@ const OrderConfirm = () => {
|
|||||||
// 设置商品信息
|
// 设置商品信息
|
||||||
// 查询当前商品是否存在水票套票活动(失败/无数据时不影响正常下单)
|
// 查询当前商品是否存在水票套票活动(失败/无数据时不影响正常下单)
|
||||||
let tpl: GltTicketTemplate | null = null
|
let tpl: GltTicketTemplate | null = null
|
||||||
if (goodsId) {
|
if (resolvedGoodsId) {
|
||||||
try {
|
try {
|
||||||
tpl = await getGltTicketTemplateByGoodsId(Number(goodsId))
|
tpl = await getGltTicketTemplateByGoodsId(resolvedGoodsId)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tpl = null
|
tpl = null
|
||||||
}
|
}
|
||||||
@@ -703,18 +774,41 @@ const OrderConfirm = () => {
|
|||||||
const n = Number(tpl?.minBuyQty)
|
const n = Number(tpl?.minBuyQty)
|
||||||
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 1
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 1
|
||||||
})()
|
})()
|
||||||
|
const tplStep = (() => {
|
||||||
|
const n = Number(tpl?.step)
|
||||||
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : undefined
|
||||||
|
})()
|
||||||
|
|
||||||
// 设置商品信息(若存在套票模板,则默认 canBuyNumber 使用模板最小购买量)
|
// 设置商品信息(若存在套票模板,则默认 canBuyNumber 使用模板最小购买量)
|
||||||
if (goodsRes) {
|
if (goodsRes) {
|
||||||
const patchedGoods: ShopGoods = { ...goodsRes }
|
const patchedGoods: ShopGoods = { ...goodsRes }
|
||||||
|
// 兜底:确保 step 为合法正整数;若存在套票模板则优先使用模板 step
|
||||||
|
const goodsStepNum = Number((patchedGoods as any)?.step)
|
||||||
|
const goodsStep = Number.isFinite(goodsStepNum) && goodsStepNum > 0 ? Math.floor(goodsStepNum) : 1
|
||||||
|
patchedGoods.step = tplActive && tplStep ? tplStep : goodsStep
|
||||||
|
|
||||||
|
// 规格商品(orderData 模式)下单时,用 sku 价格覆盖展示与计算金额
|
||||||
|
if (orderDataParam?.price !== undefined && orderDataParam?.price !== null && orderDataParam?.price !== '') {
|
||||||
|
patchedGoods.price = String(orderDataParam.price)
|
||||||
|
}
|
||||||
|
|
||||||
if (tplActive && ((patchedGoods.canBuyNumber ?? 0) === 0)) {
|
if (tplActive && ((patchedGoods.canBuyNumber ?? 0) === 0)) {
|
||||||
patchedGoods.canBuyNumber = tplMinBuyQty
|
patchedGoods.canBuyNumber = tplMinBuyQty
|
||||||
}
|
}
|
||||||
setGoods(patchedGoods)
|
setGoods(patchedGoods)
|
||||||
|
|
||||||
// 设置默认购买数量:优先使用 canBuyNumber,否则使用 1
|
// 设置默认购买数量:优先使用 canBuyNumber,其次使用路由参数 quantity,否则使用 1
|
||||||
const initQty = (patchedGoods.canBuyNumber ?? 0) > 0 ? (patchedGoods.canBuyNumber as number) : 1
|
const fixedQty = (patchedGoods.canBuyNumber ?? 0) > 0 ? Number(patchedGoods.canBuyNumber) : undefined
|
||||||
setQuantity(initQty)
|
const rawQty = fixedQty ?? quantityFromParam ?? 1
|
||||||
|
const minQty = tplActive ? tplMinBuyQty : 1
|
||||||
|
const step = patchedGoods.step || 1
|
||||||
|
const stockMax = patchedGoods.stock ?? 999
|
||||||
|
const maxMultiple = step > 1 ? Math.floor(stockMax / step) * step : stockMax
|
||||||
|
const maxAllowed = maxMultiple > 0 ? maxMultiple : stockMax
|
||||||
|
const effectiveMin = Math.min(minQty, maxAllowed)
|
||||||
|
const clamped = Math.max(effectiveMin, Math.min(Math.floor(rawQty), maxAllowed))
|
||||||
|
const stepped = step > 1 ? Math.ceil(clamped / step) * step : clamped
|
||||||
|
setQuantity(Math.min(maxAllowed, Math.max(effectiveMin, stepped)))
|
||||||
}
|
}
|
||||||
|
|
||||||
setTicketTemplate(tpl)
|
setTicketTemplate(tpl)
|
||||||
@@ -733,15 +827,26 @@ const OrderConfirm = () => {
|
|||||||
setPayment(paymentRes[0])
|
setPayment(paymentRes[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载优惠券:使用“初始数量”对应的总价做推荐,避免默认数量变化导致推荐不准
|
// 加载优惠券:使用"初始数量"对应的总价做推荐,避免默认数量变化导致推荐不准
|
||||||
if (goodsRes) {
|
if (goodsRes) {
|
||||||
const initQty = (() => {
|
const initQty = (() => {
|
||||||
const n = Number(goodsRes?.canBuyNumber)
|
const n = Number(goodsRes?.canBuyNumber)
|
||||||
if (Number.isFinite(n) && n > 0) return Math.floor(n)
|
if (Number.isFinite(n) && n > 0) return Math.floor(n)
|
||||||
if (tplActive) return tplMinBuyQty
|
if (tplActive) return tplMinBuyQty
|
||||||
return 1
|
return quantityFromParam || 1
|
||||||
})()
|
})()
|
||||||
const total = parseFloat(goodsRes.price || '0') * initQty
|
const stepForInit = tplActive && tplStep ? tplStep : (() => {
|
||||||
|
const n = Number((goodsRes as any)?.step)
|
||||||
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 1
|
||||||
|
})()
|
||||||
|
const stockMax = goodsRes.stock ?? 999
|
||||||
|
const maxMultiple = stepForInit > 1 ? Math.floor(stockMax / stepForInit) * stepForInit : stockMax
|
||||||
|
const maxAllowed = maxMultiple > 0 ? maxMultiple : stockMax
|
||||||
|
const initQtySnapped = stepForInit > 1 ? Math.ceil(initQty / stepForInit) * stepForInit : initQty
|
||||||
|
const effectiveMin = Math.min(tplActive ? tplMinBuyQty : 1, maxAllowed)
|
||||||
|
const safeInitQty = Math.max(effectiveMin, Math.min(initQtySnapped, maxAllowed))
|
||||||
|
const unitPrice = parseFloat(String(orderDataParam?.price ?? goodsRes.price ?? '0'))
|
||||||
|
const total = unitPrice * safeInitQty
|
||||||
await loadUserCoupons(total)
|
await loadUserCoupons(total)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -760,12 +865,9 @@ const OrderConfirm = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 切换商品时重置配送时间,避免沿用上一次选择
|
|
||||||
if (!isLoggedIn()) return
|
if (!isLoggedIn()) return
|
||||||
setSendTime(getMinSendDate().toDate())
|
|
||||||
setSendTimePickerVisible(false)
|
|
||||||
loadAllData()
|
loadAllData()
|
||||||
}, [goodsId]);
|
}, [resolvedGoodsId, orderDataRaw]);
|
||||||
|
|
||||||
// 重新加载数据
|
// 重新加载数据
|
||||||
const handleRetry = () => {
|
const handleRetry = () => {
|
||||||
@@ -791,56 +893,50 @@ const OrderConfirm = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'order-confirm-page'}>
|
<div className={'order-confirm-page'}>
|
||||||
<CellGroup>
|
{goods.deliveryMode === 1 ? (
|
||||||
{
|
// 自提模式:显示到店自提提示
|
||||||
address && (
|
<CellGroup>
|
||||||
<Cell className={'address-bottom-line'} onClick={() => Taro.navigateTo({url: '/user/address/index'})}>
|
<Cell>
|
||||||
<Space>
|
|
||||||
<Location className={'text-gray-500'}/>
|
|
||||||
<View className={'flex flex-col w-full justify-between items-start'}>
|
|
||||||
<Space className={'flex flex-row w-full'}>
|
|
||||||
<View className={'flex-wrap text-nowrap whitespace-nowrap text-gray-500'}>送至</View>
|
|
||||||
<View className={'font-medium text-sm flex items-center w-full'}>
|
|
||||||
<View
|
|
||||||
style={{width: '64%'}}>{address.province} {address.city} {address.region} {address.address}</View>
|
|
||||||
<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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{!address && (
|
|
||||||
<Cell className={''} onClick={() => Taro.navigateTo({url: '/user/address/index'})}>
|
|
||||||
<Space>
|
<Space>
|
||||||
<Location/>
|
<Shop className={'text-orange-500'}/>
|
||||||
添加收货地址
|
<View className={'flex flex-col w-full'}>
|
||||||
|
<Text className={'font-medium text-orange-600'}>到店自提</Text>
|
||||||
|
<Text className={'text-gray-500 text-sm mt-1'}>请到店取货或出示核销码</Text>
|
||||||
|
</View>
|
||||||
</Space>
|
</Space>
|
||||||
</Cell>
|
</Cell>
|
||||||
)}
|
</CellGroup>
|
||||||
</CellGroup>
|
) : (
|
||||||
|
// 送货上门模式:显示地址选择
|
||||||
{hasTicketTemplate && (
|
|
||||||
<CellGroup>
|
<CellGroup>
|
||||||
<Cell
|
{
|
||||||
title={'配送时间'}
|
address && (
|
||||||
extra={(
|
<Cell className={'address-bottom-line'} onClick={() => Taro.navigateTo({url: '/user/address/index'})}>
|
||||||
<View className={'flex items-center gap-2'}>
|
<Space>
|
||||||
<View className={'text-gray-900'}>{sendTimeText}</View>
|
<Location className={'text-gray-500'}/>
|
||||||
<ArrowRight className={'text-gray-400'} size={14}/>
|
<View className={'flex flex-col w-full justify-between items-start'}>
|
||||||
</View>
|
<Space className={'flex flex-row w-full'}>
|
||||||
)}
|
<View className={'flex-wrap text-nowrap whitespace-nowrap text-gray-500'}>送至</View>
|
||||||
onClick={() => {
|
<View className={'font-medium text-sm flex items-center w-full'}>
|
||||||
// 若页面停留跨过截单时间,打开选择器前再校正一次最早可选日期
|
<View
|
||||||
const min = getMinSendDate()
|
style={{width: '64%'}}>{address.province} {address.city} {address.region} {address.address}</View>
|
||||||
if (dayjs(sendTime).isBefore(min, 'day')) {
|
<ArrowRight className={'text-gray-400'} size={14}/>
|
||||||
setSendTime(min.toDate())
|
</View>
|
||||||
}
|
</Space>
|
||||||
setSendTimePickerVisible(true)
|
<View className={'pt-1 pb-3 text-gray-500'}>{address.name} {address.phone}</View>
|
||||||
}}
|
</View>
|
||||||
/>
|
</Space>
|
||||||
|
</Cell>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{!address && (
|
||||||
|
<Cell className={''} onClick={() => Taro.navigateTo({url: '/user/address/index'})}>
|
||||||
|
<Space>
|
||||||
|
<Location/>
|
||||||
|
添加收货地址
|
||||||
|
</Space>
|
||||||
|
</Cell>
|
||||||
|
)}
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -884,7 +980,7 @@ const OrderConfirm = () => {
|
|||||||
value={quantity}
|
value={quantity}
|
||||||
min={isTicketTemplateActive ? minBuyQty : 1}
|
min={isTicketTemplateActive ? minBuyQty : 1}
|
||||||
max={goods.stock || 999}
|
max={goods.stock || 999}
|
||||||
step={minBuyQty === 1 ? 1 : 10}
|
step={goods.step || 1}
|
||||||
readOnly
|
readOnly
|
||||||
disabled={((goods.canBuyNumber ?? 0) !== 0) && !isTicketTemplateActive}
|
disabled={((goods.canBuyNumber ?? 0) !== 0) && !isTicketTemplateActive}
|
||||||
onChange={handleQuantityChange}
|
onChange={handleQuantityChange}
|
||||||
@@ -1138,23 +1234,6 @@ const OrderConfirm = () => {
|
|||||||
|
|
||||||
<Gap height={50}/>
|
<Gap height={50}/>
|
||||||
|
|
||||||
<DatePicker
|
|
||||||
visible={sendTimePickerVisible}
|
|
||||||
title="选择配送时间"
|
|
||||||
type="date"
|
|
||||||
startDate={getMinSendDate().toDate()}
|
|
||||||
endDate={dayjs().add(30, 'day').toDate()}
|
|
||||||
value={sendTime}
|
|
||||||
onClose={() => setSendTimePickerVisible(false)}
|
|
||||||
onCancel={() => setSendTimePickerVisible(false)}
|
|
||||||
onConfirm={(_options, selectedValue) => {
|
|
||||||
const [y, m, d] = (selectedValue || []).map(v => Number(v))
|
|
||||||
const next = new Date(y, (m || 1) - 1, d || 1, 0, 0, 0)
|
|
||||||
setSendTime(next)
|
|
||||||
setSendTimePickerVisible(false)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className={'fixed z-50 bg-white w-full bottom-0 left-0 pt-4 pb-10 border-t border-gray-200'}>
|
<div className={'fixed z-50 bg-white w-full bottom-0 left-0 pt-4 pb-10 border-t border-gray-200'}>
|
||||||
<View className={'btn-bar flex justify-between items-center'}>
|
<View className={'btn-bar flex justify-between items-center'}>
|
||||||
<div className={'flex flex-col justify-center items-start mx-4'}>
|
<div className={'flex flex-col justify-center items-start mx-4'}>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {listShopOrderGoods} from "@/api/shop/shopOrderGoods";
|
|||||||
import {ShopOrderGoods} from "@/api/shop/shopOrderGoods/model";
|
import {ShopOrderGoods} from "@/api/shop/shopOrderGoods/model";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import PaymentCountdown from "@/components/PaymentCountdown";
|
import PaymentCountdown from "@/components/PaymentCountdown";
|
||||||
|
import {getShopOrderStatusText} from "@/utils/shopOrderStatus";
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
||||||
// 申请退款:支付成功后仅允许在指定时间窗内发起(前端展示层限制,后端仍应校验)
|
// 申请退款:支付成功后仅允许在指定时间窗内发起(前端展示层限制,后端仍应校验)
|
||||||
@@ -114,37 +115,6 @@ const OrderDetail = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOrderStatusText = (order: ShopOrder) => {
|
|
||||||
// 优先检查订单状态
|
|
||||||
if (order.orderStatus === 2) return '已取消';
|
|
||||||
if (order.orderStatus === 3) return '取消中';
|
|
||||||
if (order.orderStatus === 4) return '退款申请中';
|
|
||||||
if (order.orderStatus === 5) return '退款被拒绝';
|
|
||||||
if (order.orderStatus === 6) return '退款成功';
|
|
||||||
if (order.orderStatus === 7) return '客户端申请退款';
|
|
||||||
|
|
||||||
// 检查支付状态 (payStatus为boolean类型)
|
|
||||||
if (!order.payStatus) return '待付款';
|
|
||||||
|
|
||||||
// 已付款后检查发货状态
|
|
||||||
if (order.deliveryStatus === 10) return '待发货';
|
|
||||||
if (order.deliveryStatus === 20) {
|
|
||||||
// 若订单有配送员,则以配送员送达时间作为“可确认收货”的依据
|
|
||||||
if (order.riderId) {
|
|
||||||
if (order.sendEndTime && order.orderStatus !== 1) return '待确认收货';
|
|
||||||
return '配送中';
|
|
||||||
}
|
|
||||||
return '待收货';
|
|
||||||
}
|
|
||||||
if (order.deliveryStatus === 30) return '部分发货';
|
|
||||||
|
|
||||||
// 最后检查订单完成状态
|
|
||||||
if (order.orderStatus === 1) return '已完成';
|
|
||||||
if (order.orderStatus === 0) return '未使用';
|
|
||||||
|
|
||||||
return '未知状态';
|
|
||||||
};
|
|
||||||
|
|
||||||
const getPayTypeText = (payType?: number) => {
|
const getPayTypeText = (payType?: number) => {
|
||||||
switch (payType) {
|
switch (payType) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -194,7 +164,7 @@ const OrderDetail = () => {
|
|||||||
order.payStatus &&
|
order.payStatus &&
|
||||||
order.orderStatus !== 1 &&
|
order.orderStatus !== 1 &&
|
||||||
order.deliveryStatus === 20 &&
|
order.deliveryStatus === 20 &&
|
||||||
(!order.riderId || !!order.sendEndTime)
|
(!order.riderId || Number(order.riderId) === 0 || !!order.sendEndTime)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'order-detail-page'}>
|
<div className={'order-detail-page'}>
|
||||||
@@ -232,7 +202,7 @@ const OrderDetail = () => {
|
|||||||
<CellGroup>
|
<CellGroup>
|
||||||
<Cell title="订单编号" description={order.orderNo}/>
|
<Cell title="订单编号" description={order.orderNo}/>
|
||||||
<Cell title="下单时间" description={dayjs(order.createTime).format('YYYY-MM-DD HH:mm:ss')}/>
|
<Cell title="下单时间" description={dayjs(order.createTime).format('YYYY-MM-DD HH:mm:ss')}/>
|
||||||
<Cell title="订单状态" description={getOrderStatusText(order)}/>
|
<Cell title="订单状态" description={getShopOrderStatusText(order)}/>
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
|
|
||||||
<CellGroup>
|
<CellGroup>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {copyText} from "@/utils/common";
|
|||||||
import PaymentCountdown from "@/components/PaymentCountdown";
|
import PaymentCountdown from "@/components/PaymentCountdown";
|
||||||
import {PaymentType} from "@/utils/payment";
|
import {PaymentType} from "@/utils/payment";
|
||||||
import {ErrorType, RequestError} from "@/utils/request";
|
import {ErrorType, RequestError} from "@/utils/request";
|
||||||
|
import {getShopOrderStatusColor, getShopOrderStatusText, isShopOrderCompleted} from "@/utils/shopOrderStatus";
|
||||||
|
|
||||||
// 判断订单是否支付已过期
|
// 判断订单是否支付已过期
|
||||||
const isPaymentExpired = (createTime: string, timeoutHours: number = 24): boolean => {
|
const isPaymentExpired = (createTime: string, timeoutHours: number = 24): boolean => {
|
||||||
@@ -165,68 +166,11 @@ function OrderList(props: OrderListProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// “已完成”应以订单状态为准;不要用商品ID等字段推断完成态,否则会造成 Tab(待发货/待收货) 与状态文案不同步
|
// “已完成”应以订单状态为准;不要用商品ID等字段推断完成态,否则会造成 Tab(待发货/待收货) 与状态文案不同步
|
||||||
const isOrderCompleted = (order: ShopOrder) => toNum(order.orderStatus) === 1;
|
const isOrderCompleted = (order: ShopOrder) => isShopOrderCompleted(order);
|
||||||
|
|
||||||
// 获取订单状态文本
|
const getOrderStatusText = (order: ShopOrder) => getShopOrderStatusText(order);
|
||||||
const getOrderStatusText = (order: ShopOrder) => {
|
|
||||||
const orderStatus = toNum(order.orderStatus);
|
|
||||||
const deliveryStatus = toNum(order.deliveryStatus);
|
|
||||||
|
|
||||||
// 优先检查订单状态
|
const getOrderStatusColor = (order: ShopOrder) => getShopOrderStatusColor(order);
|
||||||
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 (deliveryStatus === 10) return '待发货';
|
|
||||||
if (deliveryStatus === 20) {
|
|
||||||
// 若订单没有配送员,沿用原“待收货”语义
|
|
||||||
if (!order.riderId || Number(order.riderId) === 0) return '待收货';
|
|
||||||
// 配送员确认送达后(sendEndTime有值),才进入“待确认收货”
|
|
||||||
if (order.sendEndTime && !isOrderCompleted(order)) return '待确认收货';
|
|
||||||
return '配送中';
|
|
||||||
}
|
|
||||||
if (deliveryStatus === 30) return '部分发货';
|
|
||||||
|
|
||||||
if (orderStatus === 0) return '未使用';
|
|
||||||
|
|
||||||
return '未知状态';
|
|
||||||
};
|
|
||||||
|
|
||||||
// 获取订单状态颜色
|
|
||||||
const getOrderStatusColor = (order: ShopOrder) => {
|
|
||||||
const orderStatus = toNum(order.orderStatus);
|
|
||||||
const deliveryStatus = toNum(order.deliveryStatus);
|
|
||||||
// 优先检查订单状态
|
|
||||||
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 (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 (deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
|
||||||
|
|
||||||
if (orderStatus === 0) return 'text-gray-500'; // 未使用
|
|
||||||
|
|
||||||
return 'text-gray-600'; // 默认颜色
|
|
||||||
};
|
|
||||||
|
|
||||||
// 使用后端统一的 statusFilter 进行筛选
|
// 使用后端统一的 statusFilter 进行筛选
|
||||||
const getOrderStatusParams = (index: string | number) => {
|
const getOrderStatusParams = (index: string | number) => {
|
||||||
|
|||||||
@@ -14,15 +14,16 @@ import {
|
|||||||
Tag
|
Tag
|
||||||
} from '@nutui/nutui-react-taro';
|
} from '@nutui/nutui-react-taro';
|
||||||
import { View, Text, Image } from '@tarojs/components';
|
import { View, Text, Image } from '@tarojs/components';
|
||||||
import { pageGltUserTicket } from '@/api/glt/gltUserTicket';
|
import { getGltUserTicket, pageGltUserTicket, updateGltUserTicket } from '@/api/glt/gltUserTicket';
|
||||||
import type { GltUserTicket } from '@/api/glt/gltUserTicket/model';
|
import type { GltUserTicket } from '@/api/glt/gltUserTicket/model';
|
||||||
import { pageGltTicketOrder, updateGltTicketOrder } from '@/api/glt/gltTicketOrder';
|
import { pageGltTicketOrder, removeGltTicketOrder, updateGltTicketOrder } from '@/api/glt/gltTicketOrder';
|
||||||
import type { GltTicketOrder } from '@/api/glt/gltTicketOrder/model';
|
import type { GltTicketOrder } from '@/api/glt/gltTicketOrder/model';
|
||||||
import { getShopUserAddress } from '@/api/shop/shopUserAddress';
|
|
||||||
import { BaseUrl } from '@/config/app';
|
import { BaseUrl } from '@/config/app';
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
import { ensureLoggedIn } from '@/utils/auth';
|
||||||
|
|
||||||
const PAGE_SIZE = 10;
|
const PAGE_SIZE = 10;
|
||||||
|
const PAY_REFRESH_HANDLED_KEY = 'user_ticket_from_pay_at_handled';
|
||||||
|
|
||||||
const UserTicketList = () => {
|
const UserTicketList = () => {
|
||||||
const [ticketList, setTicketList] = useState<GltUserTicket[]>([]);
|
const [ticketList, setTicketList] = useState<GltUserTicket[]>([]);
|
||||||
@@ -37,6 +38,7 @@ const UserTicketList = () => {
|
|||||||
const [orderHasMore, setOrderHasMore] = useState(true);
|
const [orderHasMore, setOrderHasMore] = useState(true);
|
||||||
const [orderPage, setOrderPage] = useState(1);
|
const [orderPage, setOrderPage] = useState(1);
|
||||||
const [orderTotal, setOrderTotal] = useState(0);
|
const [orderTotal, setOrderTotal] = useState(0);
|
||||||
|
const [orderCancelLoadingById, setOrderCancelLoadingById] = useState<Record<number, boolean>>({});
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState<'ticket' | 'order'>(() => {
|
const [activeTab, setActiveTab] = useState<'ticket' | 'order'>(() => {
|
||||||
const tab = Taro.getCurrentInstance().router?.params?.tab
|
const tab = Taro.getCurrentInstance().router?.params?.tab
|
||||||
@@ -46,8 +48,25 @@ const UserTicketList = () => {
|
|||||||
const [qrVisible, setQrVisible] = useState(false);
|
const [qrVisible, setQrVisible] = useState(false);
|
||||||
const [qrTicket, setQrTicket] = useState<GltUserTicket | null>(null);
|
const [qrTicket, setQrTicket] = useState<GltUserTicket | null>(null);
|
||||||
const [qrImageUrl, setQrImageUrl] = useState('');
|
const [qrImageUrl, setQrImageUrl] = useState('');
|
||||||
|
const payAutoRefreshRunningRef = useRef(false);
|
||||||
|
|
||||||
const addressCacheRef = useRef<Record<number, { lng: number; lat: number; fullAddress?: string } | null>>({});
|
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
const parsePositiveNumberParam = (v: unknown) => {
|
||||||
|
const n = Number(v);
|
||||||
|
return Number.isFinite(n) && n > 0 ? n : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFromPayAtParam = () => {
|
||||||
|
const params = Taro.getCurrentInstance().router?.params;
|
||||||
|
return parsePositiveNumberParam((params as any)?.fromPayAt);
|
||||||
|
};
|
||||||
|
|
||||||
|
const shouldAutoRefreshAfterPay = (fromPayAt?: number) => {
|
||||||
|
if (!fromPayAt) return false;
|
||||||
|
const handled = parsePositiveNumberParam(Taro.getStorageSync(PAY_REFRESH_HANDLED_KEY)) || 0;
|
||||||
|
return handled !== fromPayAt;
|
||||||
|
};
|
||||||
|
|
||||||
const getUserId = () => {
|
const getUserId = () => {
|
||||||
const raw = Taro.getStorageSync('UserId');
|
const raw = Taro.getStorageSync('UserId');
|
||||||
@@ -97,6 +116,41 @@ const UserTicketList = () => {
|
|||||||
setQrVisible(true);
|
setQrVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const goSendWater = async (ticket: GltUserTicket) => {
|
||||||
|
if (!ticket?.id) {
|
||||||
|
Taro.showToast({ title: '水票信息不完整', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Number(ticket.status) === 1) {
|
||||||
|
Taro.showToast({ title: '该水票已冻结,无法下单', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const avail = Number(ticket.availableQty ?? 0);
|
||||||
|
if (!Number.isFinite(avail) || avail <= 0) {
|
||||||
|
Taro.showToast({ title: '可用次数不足', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const gid = Number(ticket.goodsId);
|
||||||
|
const url =
|
||||||
|
Number.isFinite(gid) && gid > 0 ? `/user/ticket/use?goodsId=${gid}` : '/user/ticket/use';
|
||||||
|
if (!ensureLoggedIn(url)) return;
|
||||||
|
await Taro.navigateTo({ url });
|
||||||
|
};
|
||||||
|
|
||||||
|
const goReleasePlanDetail = async (ticket: GltUserTicket) => {
|
||||||
|
if (!ticket?.id) {
|
||||||
|
Taro.showToast({ title: '水票信息不完整', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const url = `/user/ticket/release/index?userTicketId=${encodeURIComponent(String(ticket.id))}&templateName=${encodeURIComponent(
|
||||||
|
String(ticket.templateName ?? '')
|
||||||
|
)}&frozenQty=${encodeURIComponent(String(ticket.frozenQty ?? 0))}&releasedQty=${encodeURIComponent(
|
||||||
|
String(ticket.releasedQty ?? 0)
|
||||||
|
)}`;
|
||||||
|
if (!ensureLoggedIn(url)) return;
|
||||||
|
await Taro.navigateTo({ url });
|
||||||
|
};
|
||||||
|
|
||||||
const showTicketDetail = (ticket: GltUserTicket) => {
|
const showTicketDetail = (ticket: GltUserTicket) => {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
if (ticket.templateName) lines.push(`水票:${ticket.templateName}`);
|
if (ticket.templateName) lines.push(`水票:${ticket.templateName}`);
|
||||||
@@ -188,17 +242,16 @@ const UserTicketList = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const resList = res?.list || [];
|
const resList = res?.list || [];
|
||||||
const nextList = isRefresh ? resList : [...orderList, ...resList];
|
const safeList = resList.filter((o) => Number((o as any)?.deleted) !== 1);
|
||||||
|
const nextList = isRefresh ? safeList : [...orderList, ...safeList];
|
||||||
setOrderList(nextList);
|
setOrderList(nextList);
|
||||||
const count = typeof res?.count === 'number' ? res.count : nextList.length;
|
const serverCount = typeof res?.count === 'number' ? res.count : undefined;
|
||||||
setOrderTotal(count);
|
const total = typeof serverCount === 'number' ? serverCount : nextList.length;
|
||||||
setOrderHasMore(nextList.length < count);
|
setOrderTotal(total);
|
||||||
|
setOrderHasMore(typeof serverCount === 'number' ? nextList.length < serverCount : resList.length >= PAGE_SIZE);
|
||||||
|
|
||||||
if (resList.length > 0) {
|
if (resList.length > 0) setOrderPage(currentPage + 1);
|
||||||
setOrderPage(currentPage + 1);
|
else setOrderHasMore(false);
|
||||||
} else {
|
|
||||||
setOrderHasMore(false);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取送水订单失败:', error);
|
console.error('获取送水订单失败:', error);
|
||||||
Taro.showToast({ title: '获取送水订单失败', icon: 'error' });
|
Taro.showToast({ title: '获取送水订单失败', icon: 'error' });
|
||||||
@@ -265,78 +318,184 @@ const UserTicketList = () => {
|
|||||||
return d.isValid() ? d.format('YYYY年MM月DD日') : v;
|
return d.isValid() ? d.format('YYYY年MM月DD日') : v;
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseLatLng = (latRaw?: unknown, lngRaw?: unknown) => {
|
const getTicketAvailableQty = (t?: Partial<GltUserTicket> | null) => {
|
||||||
const lat = typeof latRaw === 'number' ? latRaw : parseFloat(String(latRaw ?? ''));
|
if (!t) return 0;
|
||||||
const lng = typeof lngRaw === 'number' ? lngRaw : parseFloat(String(lngRaw ?? ''));
|
const anyT: any = t;
|
||||||
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return null;
|
const raw =
|
||||||
if (Math.abs(lat) > 90 || Math.abs(lng) > 180) return null;
|
anyT.availableQty ??
|
||||||
return { lat, lng };
|
anyT.availableNum ??
|
||||||
|
anyT.availableCount ??
|
||||||
|
anyT.remainQty ??
|
||||||
|
anyT.remainNum ??
|
||||||
|
anyT.remainCount;
|
||||||
|
const n = Number(raw);
|
||||||
|
if (Number.isFinite(n)) return n;
|
||||||
|
|
||||||
|
const total = Number(anyT.totalQty ?? anyT.totalNum ?? anyT.totalCount ?? 0);
|
||||||
|
const used = Number(anyT.usedQty ?? anyT.usedNum ?? anyT.usedCount ?? 0);
|
||||||
|
const frozen = Number(anyT.frozenQty ?? anyT.frozenNum ?? anyT.frozenCount ?? 0);
|
||||||
|
const computed =
|
||||||
|
(Number.isFinite(total) ? total : 0) -
|
||||||
|
(Number.isFinite(used) ? used : 0) -
|
||||||
|
(Number.isFinite(frozen) ? frozen : 0);
|
||||||
|
return Number.isFinite(computed) ? computed : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNavigateToAddress = async (order: GltTicketOrder) => {
|
const getTicketUsedQty = (t?: Partial<GltUserTicket> | null) => {
|
||||||
try {
|
if (!t) return 0;
|
||||||
// Prefer coordinates from backend if present (non-typed fields), otherwise fetch by addressId.
|
const anyT: any = t;
|
||||||
const anyOrder = order as any;
|
const raw = anyT.usedQty ?? anyT.usedNum ?? anyT.usedCount;
|
||||||
const direct =
|
const n = Number(raw);
|
||||||
parseLatLng(anyOrder?.addressLat ?? anyOrder?.lat, anyOrder?.addressLng ?? anyOrder?.lng) ||
|
return Number.isFinite(n) ? n : 0;
|
||||||
parseLatLng(anyOrder?.receiverLat, anyOrder?.receiverLng);
|
};
|
||||||
|
|
||||||
let coords = direct;
|
const rollbackUserTicketAfterOrderCancel = async (order: GltTicketOrder, before?: GltUserTicket | null) => {
|
||||||
let fullAddress: string | undefined = order.address || undefined;
|
const orderId = Number(order?.id);
|
||||||
|
const ticketId = Number(order?.userTicketId);
|
||||||
|
const qty = Math.max(0, Math.floor(Number((order as any)?.totalNum ?? 0)));
|
||||||
|
if (!Number.isFinite(orderId) || orderId <= 0) return;
|
||||||
|
if (!Number.isFinite(ticketId) || ticketId <= 0) return;
|
||||||
|
if (!Number.isFinite(qty) || qty <= 0) return;
|
||||||
|
|
||||||
if (!coords && order.addressId) {
|
const rollbackKey = `glt_ticket_order_rollback:${orderId}`;
|
||||||
const cached = addressCacheRef.current[order.addressId];
|
if (Taro.getStorageSync(rollbackKey)) return;
|
||||||
if (cached) {
|
|
||||||
coords = { lat: cached.lat, lng: cached.lng };
|
const after = await getGltUserTicket(ticketId);
|
||||||
fullAddress = fullAddress || cached.fullAddress;
|
if (!after?.id) return;
|
||||||
} else if (cached === null) {
|
|
||||||
coords = null;
|
const beforeAvail = before ? getTicketAvailableQty(before) : undefined;
|
||||||
} else {
|
const afterAvail = getTicketAvailableQty(after);
|
||||||
const addr = await getShopUserAddress(order.addressId);
|
const beforeUsed = before ? getTicketUsedQty(before) : undefined;
|
||||||
const parsed = parseLatLng(addr?.lat, addr?.lng);
|
const afterUsed = getTicketUsedQty(after);
|
||||||
if (parsed) {
|
|
||||||
coords = parsed;
|
let needAvail = qty;
|
||||||
fullAddress = fullAddress || addr?.fullAddress || addr?.address || undefined;
|
if (typeof beforeAvail === 'number') {
|
||||||
addressCacheRef.current[order.addressId] = { ...parsed, fullAddress };
|
const delta = afterAvail - beforeAvail;
|
||||||
} else {
|
if (delta >= qty) {
|
||||||
addressCacheRef.current[order.addressId] = null;
|
Taro.setStorageSync(rollbackKey, Date.now());
|
||||||
}
|
return; // backend already rolled back
|
||||||
}
|
}
|
||||||
|
if (delta > 0) needAvail = Math.max(0, qty - delta);
|
||||||
|
}
|
||||||
|
let needUsed = qty;
|
||||||
|
if (typeof beforeUsed === 'number') {
|
||||||
|
const delta = beforeUsed - afterUsed;
|
||||||
|
if (delta >= qty) {
|
||||||
|
needUsed = 0; // backend already rolled back used qty
|
||||||
|
} else if (delta > 0) {
|
||||||
|
needUsed = Math.max(0, qty - delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!coords) {
|
|
||||||
if (fullAddress) {
|
|
||||||
await Taro.setClipboardData({ data: fullAddress });
|
|
||||||
Taro.showToast({ title: '未配置定位,地址已复制', icon: 'none' });
|
|
||||||
} else {
|
|
||||||
Taro.showToast({ title: '暂无可导航的地址', icon: 'none' });
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Taro.openLocation({
|
|
||||||
latitude: coords.lat,
|
|
||||||
longitude: coords.lng,
|
|
||||||
name: '收货地址',
|
|
||||||
address: fullAddress || ''
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error('一键导航失败:', e);
|
|
||||||
Taro.showToast({ title: '导航失败,请重试', icon: 'none' });
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleOneClickCall = async (order: GltTicketOrder) => {
|
if (needAvail <= 0 && needUsed <= 0) {
|
||||||
const phone = (order.riderPhone || order.storePhone || '').trim();
|
Taro.setStorageSync(rollbackKey, Date.now());
|
||||||
if (!phone) {
|
|
||||||
Taro.showToast({ title: '暂无可呼叫的电话', icon: 'none' });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentAvailRaw = Number((after as any)?.availableQty);
|
||||||
|
const baseAvail = Number.isFinite(currentAvailRaw) ? currentAvailRaw : afterAvail;
|
||||||
|
const safeBaseAvail = Number.isFinite(baseAvail) ? baseAvail : 0;
|
||||||
|
|
||||||
|
const totalRaw = Number((after as any)?.totalQty ?? 0);
|
||||||
|
const total = Number.isFinite(totalRaw) ? totalRaw : undefined;
|
||||||
|
const frozenRaw = Number((after as any)?.frozenQty ?? 0);
|
||||||
|
const frozen = Number.isFinite(frozenRaw) ? frozenRaw : 0;
|
||||||
|
|
||||||
|
const currentUsedRaw = Number((after as any)?.usedQty);
|
||||||
|
const baseUsed = Number.isFinite(currentUsedRaw) ? currentUsedRaw : afterUsed;
|
||||||
|
const safeBaseUsed = Number.isFinite(baseUsed) ? baseUsed : 0;
|
||||||
|
let nextUsed = safeBaseUsed - needUsed;
|
||||||
|
if (nextUsed < 0) nextUsed = 0;
|
||||||
|
|
||||||
|
const maxAvail = typeof total === 'number' ? Math.max(0, total - frozen - nextUsed) : undefined;
|
||||||
|
|
||||||
|
let nextAvail = safeBaseAvail + needAvail;
|
||||||
|
if (typeof maxAvail === 'number' && Number.isFinite(maxAvail) && nextAvail > maxAvail) nextAvail = maxAvail;
|
||||||
|
if (nextAvail < 0) nextAvail = 0;
|
||||||
|
|
||||||
|
await updateGltUserTicket({
|
||||||
|
...after,
|
||||||
|
availableQty: nextAvail,
|
||||||
|
usedQty: nextUsed
|
||||||
|
});
|
||||||
|
|
||||||
|
Taro.setStorageSync(rollbackKey, Date.now());
|
||||||
|
};
|
||||||
|
|
||||||
|
// Allow users to modify/cancel before delivery starts (e.g. 待派单 / 待配送).
|
||||||
|
const isTicketOrderPendingDelivery = (order: GltTicketOrder) => {
|
||||||
|
if (!order?.id) return false;
|
||||||
|
if (Number(order.status) === 1) return false;
|
||||||
|
if (Number((order as any)?.deleted) === 1) return false;
|
||||||
|
if (order.receiveConfirmTime || order.sendEndTime || order.sendStartTime) return false;
|
||||||
|
|
||||||
|
const ds = Number((order as any)?.deliveryStatus);
|
||||||
|
// If backend didn't set deliveryStatus yet, treat it as pending.
|
||||||
|
if (!Number.isFinite(ds)) return true;
|
||||||
|
// 0/10: before delivery starts
|
||||||
|
return ds === 0 || ds === 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOrderModify = async (order: GltTicketOrder) => {
|
||||||
|
if (!order?.id) {
|
||||||
|
Taro.showToast({ title: '订单信息不完整', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isTicketOrderPendingDelivery(order)) {
|
||||||
|
Taro.showToast({ title: '仅配送未开始的订单可修改', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Taro.navigateTo({ url: `/user/ticket/use?orderId=${order.id}` });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOrderCancel = async (order: GltTicketOrder) => {
|
||||||
|
if (!order?.id) {
|
||||||
|
Taro.showToast({ title: '订单信息不完整', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isTicketOrderPendingDelivery(order)) {
|
||||||
|
Taro.showToast({ title: '仅配送未开始的订单可取消', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (orderCancelLoadingById[order.id]) return;
|
||||||
|
|
||||||
|
const modal = await Taro.showModal({
|
||||||
|
title: '取消订单',
|
||||||
|
content: '确定要取消该订单吗?取消后无法恢复。',
|
||||||
|
confirmText: '确认取消'
|
||||||
|
});
|
||||||
|
if (!modal.confirm) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Taro.makePhoneCall({ phoneNumber: phone });
|
setOrderCancelLoadingById((prev) => ({ ...prev, [order.id as number]: true }));
|
||||||
|
Taro.showLoading({ title: '取消中...' });
|
||||||
|
let beforeTicket: GltUserTicket | null = null;
|
||||||
|
if (order.userTicketId) {
|
||||||
|
beforeTicket = await getGltUserTicket(Number(order.userTicketId)).catch(() => null);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await updateGltTicketOrder({ id: order.id, deleted: 1 });
|
||||||
|
} catch (e) {
|
||||||
|
await removeGltTicketOrder(order.id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await rollbackUserTicketAfterOrderCancel(order, beforeTicket);
|
||||||
|
Taro.showToast({ title: '订单已取消,水票已退回', icon: 'none' });
|
||||||
|
} catch (e) {
|
||||||
|
console.error('取消订单后退回水票失败:', e);
|
||||||
|
await Taro.showModal({
|
||||||
|
title: '取消成功',
|
||||||
|
content: '订单已取消,但水票退回失败,请稍后刷新“我的水票”确认,或联系客服处理。',
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await reloadOrders(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('一键呼叫失败:', e);
|
console.error('取消送水订单失败:', e);
|
||||||
Taro.showToast({ title: '呼叫失败,请手动拨打', icon: 'none' });
|
Taro.showToast({ title: '取消失败,请重试', icon: 'none' });
|
||||||
|
} finally {
|
||||||
|
Taro.hideLoading();
|
||||||
|
setOrderCancelLoadingById((prev) => ({ ...prev, [order.id as number]: false }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -391,12 +550,37 @@ const UserTicketList = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
if (activeTab === 'ticket') {
|
void (async () => {
|
||||||
reloadTickets(true).then();
|
const tabParam = Taro.getCurrentInstance().router?.params?.tab;
|
||||||
} else {
|
const nextTab = tabParam === 'ticket' || tabParam === 'order' ? tabParam : undefined;
|
||||||
reloadOrders(true).then();
|
|
||||||
}
|
if (nextTab && nextTab !== activeTab) {
|
||||||
});
|
setActiveTab(nextTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tabToLoad = nextTab || activeTab;
|
||||||
|
if (tabToLoad === 'ticket') {
|
||||||
|
await reloadTickets(true);
|
||||||
|
|
||||||
|
const fromPayAt = getFromPayAtParam();
|
||||||
|
if (shouldAutoRefreshAfterPay(fromPayAt) && !payAutoRefreshRunningRef.current) {
|
||||||
|
payAutoRefreshRunningRef.current = true;
|
||||||
|
try {
|
||||||
|
Taro.setStorageSync(PAY_REFRESH_HANDLED_KEY, fromPayAt);
|
||||||
|
// 支付后水票可能异步入账:自动再刷新几次,避免用户手动下拉刷新。
|
||||||
|
for (const delayMs of [800, 1500, 2500]) {
|
||||||
|
await sleep(delayMs);
|
||||||
|
await reloadTickets(true);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
payAutoRefreshRunningRef.current = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await reloadOrders(true);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigProvider>
|
<ConfigProvider>
|
||||||
@@ -479,6 +663,9 @@ const UserTicketList = () => {
|
|||||||
<Text className="text-base font-semibold text-gray-900">
|
<Text className="text-base font-semibold text-gray-900">
|
||||||
票号:{item.id}
|
票号:{item.id}
|
||||||
</Text>
|
</Text>
|
||||||
|
<View className="mt-1">
|
||||||
|
<Text className="text-xs text-gray-500">套票名称:{item.templateName}</Text>
|
||||||
|
</View>
|
||||||
{item.orderNo && (
|
{item.orderNo && (
|
||||||
<View className="mt-1">
|
<View className="mt-1">
|
||||||
<Text className="text-xs text-gray-500">订单编号:{item.orderNo}</Text>
|
<Text className="text-xs text-gray-500">订单编号:{item.orderNo}</Text>
|
||||||
@@ -490,13 +677,25 @@ const UserTicketList = () => {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
<View className="flex flex-col items-end gap-2 hidden">
|
<View className="flex flex-col items-end gap-2">
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
disabled={(item.availableQty ?? 0) <= 0 || item.status === 1}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
void goSendWater(item);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
立即送水
|
||||||
|
</Button>
|
||||||
{/*<Tag type={item.status === 1 ? 'danger' : 'success'}>*/}
|
{/*<Tag type={item.status === 1 ? 'danger' : 'success'}>*/}
|
||||||
{/* {item.status === 1 ? '冻结' : '正常'}*/}
|
{/* {item.status === 1 ? '冻结' : '正常'}*/}
|
||||||
{/*</Tag>*/}
|
{/*</Tag>*/}
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
type="primary"
|
type="primary"
|
||||||
|
style={{ display: 'none'}}
|
||||||
disabled={(item.availableQty ?? 0) <= 0 || item.status === 1}
|
disabled={(item.availableQty ?? 0) <= 0 || item.status === 1}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
// Avoid triggering card click.
|
// Avoid triggering card click.
|
||||||
@@ -518,7 +717,14 @@ const UserTicketList = () => {
|
|||||||
<Text className="text-lg text-gray-900 text-center">{item.usedQty ?? 0}</Text>
|
<Text className="text-lg text-gray-900 text-center">{item.usedQty ?? 0}</Text>
|
||||||
<Text className="text-xs text-gray-500">已用水票</Text>
|
<Text className="text-xs text-gray-500">已用水票</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className="flex flex-col items-center">
|
<View
|
||||||
|
className="flex flex-col items-center"
|
||||||
|
hoverClass="opacity-70"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
void goReleasePlanDetail(item);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Text className="text-lg text-gray-900 text-center">{item.frozenQty ?? 0}</Text>
|
<Text className="text-lg text-gray-900 text-center">{item.frozenQty ?? 0}</Text>
|
||||||
<Text className="text-xs text-gray-500">剩余赠票</Text>
|
<Text className="text-xs text-gray-500">剩余赠票</Text>
|
||||||
</View>
|
</View>
|
||||||
@@ -576,32 +782,6 @@ const UserTicketList = () => {
|
|||||||
<View className="mt-1">
|
<View className="mt-1">
|
||||||
<Text className="text-xs text-gray-500">下单时间:{formatDateTime(item.createTime)}</Text>
|
<Text className="text-xs text-gray-500">下单时间:{formatDateTime(item.createTime)}</Text>
|
||||||
</View>
|
</View>
|
||||||
{(!!item.addressId || !!item.address || !!item.riderPhone || !!item.storePhone) ? (
|
|
||||||
<View className="mt-3 flex justify-end gap-2">
|
|
||||||
{(!!item.addressId || !!item.address) ? (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
void handleNavigateToAddress(item);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
一键导航
|
|
||||||
</Button>
|
|
||||||
) : null}
|
|
||||||
{(!!item.riderPhone || !!item.storePhone) ? (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
void handleOneClickCall(item);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
一键呼叫
|
|
||||||
</Button>
|
|
||||||
) : null}
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
{/*{item.storeName ? (*/}
|
{/*{item.storeName ? (*/}
|
||||||
{/* <View className="mt-1 text-xs text-gray-500">*/}
|
{/* <View className="mt-1 text-xs text-gray-500">*/}
|
||||||
{/* <Text>门店:{item.storeName}</Text>*/}
|
{/* <Text>门店:{item.storeName}</Text>*/}
|
||||||
@@ -638,6 +818,38 @@ const UserTicketList = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
{item.id ? (
|
||||||
|
<View className="mt-3 flex justify-end gap-2">
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
disabled={
|
||||||
|
!isTicketOrderPendingDelivery(item) ||
|
||||||
|
!!orderCancelLoadingById[item.id as number]
|
||||||
|
}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
void handleOrderModify(item);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改订单
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
type="danger"
|
||||||
|
disabled={
|
||||||
|
!isTicketOrderPendingDelivery(item) ||
|
||||||
|
!!orderCancelLoadingById[item.id as number]
|
||||||
|
}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
void handleOrderCancel(item);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
取消订单
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
6
src/user/ticket/release/index.config.ts
Normal file
6
src/user/ticket/release/index.config.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export default definePageConfig({
|
||||||
|
navigationBarTitleText: '释放计划',
|
||||||
|
navigationBarTextStyle: 'black',
|
||||||
|
navigationBarBackgroundColor: '#ffffff'
|
||||||
|
})
|
||||||
|
|
||||||
245
src/user/ticket/release/index.tsx
Normal file
245
src/user/ticket/release/index.tsx
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import Taro, { useDidShow } from '@tarojs/taro'
|
||||||
|
import { View, Text } from '@tarojs/components'
|
||||||
|
import { ConfigProvider, Empty, InfiniteLoading, Loading, PullToRefresh, Tag } from '@nutui/nutui-react-taro'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
import { pageGltUserTicketRelease } from '@/api/glt/gltUserTicketRelease'
|
||||||
|
import type { GltUserTicketRelease } from '@/api/glt/gltUserTicketRelease/model'
|
||||||
|
import { ensureLoggedIn } from '@/utils/auth'
|
||||||
|
|
||||||
|
const PAGE_SIZE = 10
|
||||||
|
const MAX_FETCH_ROUNDS = 10
|
||||||
|
|
||||||
|
export default function TicketReleasePlanPage() {
|
||||||
|
const [list, setList] = useState<GltUserTicketRelease[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [hasMore, setHasMore] = useState(true)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [total, setTotal] = useState<number | undefined>(undefined)
|
||||||
|
|
||||||
|
const router = Taro.getCurrentInstance().router
|
||||||
|
const userTicketId = String(router?.params?.userTicketId || '').trim()
|
||||||
|
const templateName = (() => {
|
||||||
|
const raw = String(router?.params?.templateName || '')
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(raw)
|
||||||
|
} catch {
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
const frozenQtyText = router?.params?.frozenQty !== undefined ? String(router?.params?.frozenQty) : undefined
|
||||||
|
const releasedQtyText = router?.params?.releasedQty !== undefined ? String(router?.params?.releasedQty) : undefined
|
||||||
|
|
||||||
|
const getUserId = () => {
|
||||||
|
const raw = Taro.getStorageSync('UserId')
|
||||||
|
const id = Number(raw)
|
||||||
|
return Number.isFinite(id) && id > 0 ? id : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const getStatusMeta = (item: GltUserTicketRelease) => {
|
||||||
|
const status = Number(item.status)
|
||||||
|
if (status === 1) return { text: '已释放', type: 'success' as const }
|
||||||
|
if (status === 0) return { text: '待释放', type: 'warning' as const }
|
||||||
|
return { text: `状态${Number.isFinite(status) ? status : '-'}`, type: 'primary' as const }
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatDateTime = (v?: string) => {
|
||||||
|
if (!v) return '-'
|
||||||
|
const d = dayjs(v)
|
||||||
|
return d.isValid() ? d.format('YYYY年MM月DD日 HH:mm:ss') : v
|
||||||
|
}
|
||||||
|
|
||||||
|
const reload = async (isRefresh = true) => {
|
||||||
|
if (loading) return
|
||||||
|
|
||||||
|
const uid = getUserId()
|
||||||
|
if (!uid) {
|
||||||
|
setList([])
|
||||||
|
setHasMore(false)
|
||||||
|
setTotal(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!userTicketId) {
|
||||||
|
setList([])
|
||||||
|
setHasMore(false)
|
||||||
|
setTotal(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRefresh) {
|
||||||
|
setPage(1)
|
||||||
|
setList([])
|
||||||
|
setHasMore(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const baseList = isRefresh ? [] : list
|
||||||
|
const seen = new Set(baseList.map(r => String(r.id ?? `${r.userTicketId ?? ''}:${r.periodNo ?? ''}:${r.releaseTime ?? ''}`)))
|
||||||
|
|
||||||
|
let nextPage = isRefresh ? 1 : page
|
||||||
|
let serverHasMore = true
|
||||||
|
let added = 0
|
||||||
|
let nextList = baseList.slice()
|
||||||
|
|
||||||
|
for (let round = 0; round < MAX_FETCH_ROUNDS; round++) {
|
||||||
|
if (!serverHasMore) break
|
||||||
|
|
||||||
|
// Only query by current logged-in userId; userTicketId is filtered on the client.
|
||||||
|
const res = await pageGltUserTicketRelease({
|
||||||
|
page: nextPage,
|
||||||
|
limit: PAGE_SIZE,
|
||||||
|
userId: uid
|
||||||
|
} as any)
|
||||||
|
|
||||||
|
const incoming = Array.isArray(res?.list) ? res.list : []
|
||||||
|
const safe = incoming
|
||||||
|
.filter(r => Number((r as any)?.deleted) !== 1)
|
||||||
|
.filter(r => !userTicketId || String(r.userTicketId || '') === userTicketId)
|
||||||
|
.filter(r => {
|
||||||
|
const k = String(r.id ?? `${r.userTicketId ?? ''}:${r.periodNo ?? ''}:${r.releaseTime ?? ''}`)
|
||||||
|
if (seen.has(k)) return false
|
||||||
|
seen.add(k)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if (safe.length) {
|
||||||
|
nextList = nextList.concat(safe)
|
||||||
|
added += safe.length
|
||||||
|
}
|
||||||
|
|
||||||
|
serverHasMore = incoming.length >= PAGE_SIZE
|
||||||
|
if (!serverHasMore) break
|
||||||
|
nextPage += 1
|
||||||
|
|
||||||
|
// Stop early once we got something to render for this ticket.
|
||||||
|
if (added > 0) break
|
||||||
|
}
|
||||||
|
|
||||||
|
nextList.sort((a, b) => {
|
||||||
|
const at = dayjs(a.releaseTime || a.createTime || 0).valueOf()
|
||||||
|
const bt = dayjs(b.releaseTime || b.createTime || 0).valueOf()
|
||||||
|
return bt - at
|
||||||
|
})
|
||||||
|
|
||||||
|
setList(nextList)
|
||||||
|
setTotal(nextList.length)
|
||||||
|
setHasMore(serverHasMore)
|
||||||
|
setPage(nextPage)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('加载释放计划失败:', e)
|
||||||
|
Taro.showToast({ title: '加载失败', icon: 'none' })
|
||||||
|
setHasMore(false)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useDidShow(() => {
|
||||||
|
const redirect = userTicketId
|
||||||
|
? `/user/ticket/release/index?userTicketId=${encodeURIComponent(userTicketId)}`
|
||||||
|
: '/user/ticket/index'
|
||||||
|
if (!ensureLoggedIn(redirect)) return
|
||||||
|
void reload(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleRefresh = async () => {
|
||||||
|
await reload(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadMore = async () => {
|
||||||
|
if (!loading && hasMore) await reload(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConfigProvider>
|
||||||
|
<PullToRefresh onRefresh={handleRefresh} headHeight={60}>
|
||||||
|
<View style={{ height: 'calc(100vh)', overflowY: 'auto' }} id="ticket-release-scroll">
|
||||||
|
<View className="px-4 py-3">
|
||||||
|
<View className="bg-white rounded-xl p-4 mb-3">
|
||||||
|
<View className="flex items-center justify-between">
|
||||||
|
<Text className="text-base font-semibold text-gray-900">释放计划明细</Text>
|
||||||
|
{typeof total === 'number' ? (
|
||||||
|
<Text className="text-xs text-gray-400">共 {total} 条</Text>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
<View className="mt-2 text-xs text-gray-500">
|
||||||
|
<Text>票号:{userTicketId || '-'}</Text>
|
||||||
|
</View>
|
||||||
|
{templateName ? (
|
||||||
|
<View className="mt-1 text-xs text-gray-500">
|
||||||
|
<Text>套票名称:{templateName}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
{frozenQtyText !== undefined || releasedQtyText !== undefined ? (
|
||||||
|
<View className="mt-2 flex gap-4">
|
||||||
|
{frozenQtyText !== undefined ? (
|
||||||
|
<View>
|
||||||
|
<Text className="text-xs text-gray-500">剩余赠票:{frozenQtyText}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
{releasedQtyText !== undefined ? (
|
||||||
|
<View>
|
||||||
|
<Text className="text-xs text-gray-500">已释放:{releasedQtyText}</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{list.length === 0 && !loading && !hasMore ? (
|
||||||
|
<View className="flex flex-col justify-center items-center" style={{ height: 'calc(100vh - 220px)' }}>
|
||||||
|
<Empty description="暂无释放计划" style={{ backgroundColor: 'transparent' }} />
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<InfiniteLoading
|
||||||
|
target="ticket-release-scroll"
|
||||||
|
hasMore={hasMore}
|
||||||
|
onLoadMore={loadMore}
|
||||||
|
loadingText={
|
||||||
|
<View className="flex justify-center items-center py-4">
|
||||||
|
<Loading />
|
||||||
|
<View className="ml-2">加载中...</View>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
loadMoreText={
|
||||||
|
<View className="text-center py-4 text-gray-500">
|
||||||
|
{list.length === 0 ? '暂无数据' : '没有更多了'}
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<View>
|
||||||
|
{list.map((item, index) => {
|
||||||
|
const meta = getStatusMeta(item)
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
key={String(item.id ?? `${item.userTicketId ?? 't'}-${index}`)}
|
||||||
|
className="bg-white rounded-xl p-4 mb-3"
|
||||||
|
>
|
||||||
|
<View className="flex items-start justify-between">
|
||||||
|
<View className="flex-1 pr-3">
|
||||||
|
<Text className="text-sm font-semibold text-gray-900">
|
||||||
|
周期:{item.periodNo ?? '-'}
|
||||||
|
</Text>
|
||||||
|
<View className="mt-1 text-xs text-gray-500">
|
||||||
|
<Text>释放数量:{item.releaseQty ?? 0}</Text>
|
||||||
|
</View>
|
||||||
|
<View className="mt-1 text-xs text-gray-500">
|
||||||
|
<Text>释放时间:{formatDateTime(item.releaseTime)}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<Tag type={meta.type}>{meta.text}</Tag>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
</InfiniteLoading>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</PullToRefresh>
|
||||||
|
</ConfigProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -58,6 +58,179 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 配送方式选择
|
||||||
|
.delivery-method-group {
|
||||||
|
.delivery-method-section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delivery-method-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delivery-method-options {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delivery-method-item {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 16px 8px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 2px solid #f0f0f0;
|
||||||
|
background: #fafafa;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
border-color: #07c160;
|
||||||
|
background: rgba(7, 193, 96, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: scale(0.97);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.delivery-method-icon {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否送上楼
|
||||||
|
.carry-upstairs-section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 12px 0 0;
|
||||||
|
border-top: 1px dashed #eee;
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carry-upstairs-options {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carry-upstairs-item {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 2px solid #f0f0f0;
|
||||||
|
background: #fafafa;
|
||||||
|
font-size: 18px;
|
||||||
|
color: #666;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
border-color: #07c160;
|
||||||
|
background: rgba(7, 193, 96, 0.05);
|
||||||
|
color: #07c160;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: scale(0.97);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 楼层选择
|
||||||
|
.floor-select-section {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 12px 0 0;
|
||||||
|
border-top: 1px dashed #eee;
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floor-select-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 8px 14px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
font-size: 18px;
|
||||||
|
transition: background 0.2s;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: #e8e8e8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.floor-fee-tip {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 楼层选择弹窗
|
||||||
|
.floor-picker-popup {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 16px;
|
||||||
|
border-bottom: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__footer {
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-top: 1px solid #f0f0f0;
|
||||||
|
text-align: center;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.floor-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(5, 1fr);
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floor-grid-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 14px 0;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 2px solid #f0f0f0;
|
||||||
|
background: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #333;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
border-color: #07c160;
|
||||||
|
background: rgba(7, 193, 96, 0.08);
|
||||||
|
color: #07c160;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
transform: scale(0.95);
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 优惠券弹窗样式
|
// 优惠券弹窗样式
|
||||||
.coupon-popup {
|
.coupon-popup {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,8 @@ export enum PaymentType {
|
|||||||
* 支付结果回调
|
* 支付结果回调
|
||||||
*/
|
*/
|
||||||
export interface PaymentCallback {
|
export interface PaymentCallback {
|
||||||
onSuccess?: () => void;
|
// Return `false` to skip default "支付成功" toast + redirect.
|
||||||
|
onSuccess?: () => void | boolean | Promise<void | boolean>;
|
||||||
onError?: (error: string) => void;
|
onError?: (error: string) => void;
|
||||||
onComplete?: () => void;
|
onComplete?: () => void;
|
||||||
}
|
}
|
||||||
@@ -118,17 +119,27 @@ export class PaymentHandler {
|
|||||||
if (paymentSuccess) {
|
if (paymentSuccess) {
|
||||||
console.log('支付成功,订单号:', result.orderNo);
|
console.log('支付成功,订单号:', result.orderNo);
|
||||||
|
|
||||||
Taro.showToast({
|
// 先收起 loading,避免遮挡 modal/toast
|
||||||
title: '支付成功',
|
try {
|
||||||
icon: 'success'
|
Taro.hideLoading();
|
||||||
});
|
} catch (_e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
callback?.onSuccess?.();
|
const onSuccessResult = await callback?.onSuccess?.();
|
||||||
|
const skipDefaultSuccessBehavior = onSuccessResult === false;
|
||||||
|
|
||||||
// 跳转到订单页面
|
if (!skipDefaultSuccessBehavior) {
|
||||||
setTimeout(() => {
|
Taro.showToast({
|
||||||
Taro.navigateTo({ url: '/user/order/order' });
|
title: '支付成功',
|
||||||
}, 2000);
|
icon: 'success'
|
||||||
|
});
|
||||||
|
|
||||||
|
// 跳转到订单页面
|
||||||
|
setTimeout(() => {
|
||||||
|
Taro.navigateTo({ url: '/user/order/order' });
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('支付未完成');
|
throw new Error('支付未完成');
|
||||||
}
|
}
|
||||||
@@ -465,6 +476,8 @@ export function buildSingleGoodsOrder(
|
|||||||
specInfo?: string;
|
specInfo?: string;
|
||||||
buyerRemarks?: string;
|
buyerRemarks?: string;
|
||||||
sendStartTime?: string;
|
sendStartTime?: string;
|
||||||
|
deliveryMethod?: string;
|
||||||
|
deliveryFloor?: number;
|
||||||
}
|
}
|
||||||
): OrderCreateRequest {
|
): OrderCreateRequest {
|
||||||
return {
|
return {
|
||||||
@@ -482,7 +495,9 @@ export function buildSingleGoodsOrder(
|
|||||||
sendStartTime: options?.sendStartTime,
|
sendStartTime: options?.sendStartTime,
|
||||||
deliveryType: options?.deliveryType || 0,
|
deliveryType: options?.deliveryType || 0,
|
||||||
couponId: options?.couponId,
|
couponId: options?.couponId,
|
||||||
selfTakeMerchantId: options?.selfTakeMerchantId
|
selfTakeMerchantId: options?.selfTakeMerchantId,
|
||||||
|
deliveryMethod: options?.deliveryMethod,
|
||||||
|
deliveryFloor: options?.deliveryFloor
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ import {User} from "@/api/system/user/model";
|
|||||||
|
|
||||||
// 模版套餐ID - 请根据实际情况修改
|
// 模版套餐ID - 请根据实际情况修改
|
||||||
export const TEMPLATE_ID = '10584';
|
export const TEMPLATE_ID = '10584';
|
||||||
// 服务接口 - 请根据实际情况修改
|
// 服务接口 - 从环境配置读取
|
||||||
export const SERVER_API_URL = 'https://glt-server.websoft.top/api';
|
// @ts-ignore
|
||||||
// export const SERVER_API_URL = 'http://127.0.0.1:8000/api';
|
export const SERVER_API_URL = process.env.TARO_ENV === 'production'
|
||||||
|
? 'https://glt-server.websoft.top/api'
|
||||||
|
: 'https://glt-server.websoft.top/api';
|
||||||
/**
|
/**
|
||||||
* 保存用户信息到本地存储
|
* 保存用户信息到本地存储
|
||||||
* @param token
|
* @param token
|
||||||
|
|||||||
65
src/utils/shopOrderStatus.ts
Normal file
65
src/utils/shopOrderStatus.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import type { ShopOrder } from '@/api/shop/shopOrder/model';
|
||||||
|
|
||||||
|
const toNum = (value: unknown): number | undefined => {
|
||||||
|
if (value === null || value === undefined || value === '') return undefined;
|
||||||
|
const n = Number(value);
|
||||||
|
return Number.isFinite(n) ? n : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isShopOrderCompleted = (order: Pick<ShopOrder, 'orderStatus'>): boolean =>
|
||||||
|
toNum(order?.orderStatus) === 1;
|
||||||
|
|
||||||
|
export const getShopOrderStatusText = (order: ShopOrder): string => {
|
||||||
|
const orderStatus = toNum(order?.orderStatus);
|
||||||
|
const deliveryStatus = toNum(order?.deliveryStatus);
|
||||||
|
const riderId = toNum(order?.riderId);
|
||||||
|
|
||||||
|
if (orderStatus === 2) return '已取消';
|
||||||
|
if (orderStatus === 3) return '取消中';
|
||||||
|
if (orderStatus === 4) return '退款申请中';
|
||||||
|
if (orderStatus === 5) return '退款被拒绝';
|
||||||
|
if (orderStatus === 6) return '退款成功';
|
||||||
|
if (orderStatus === 7) return '客户端申请退款';
|
||||||
|
if (orderStatus === 1) return '已完成';
|
||||||
|
|
||||||
|
if (!order?.payStatus) return '等待买家付款';
|
||||||
|
|
||||||
|
if (deliveryStatus === 10) return '待发货';
|
||||||
|
if (deliveryStatus === 20) {
|
||||||
|
if (!riderId || riderId === 0) return '待收货';
|
||||||
|
if (order?.sendEndTime) return '待确认收货';
|
||||||
|
return '配送中';
|
||||||
|
}
|
||||||
|
if (deliveryStatus === 30) return '部分发货';
|
||||||
|
|
||||||
|
if (orderStatus === 0) return '未使用';
|
||||||
|
return '未知状态';
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getShopOrderStatusColor = (order: ShopOrder): string => {
|
||||||
|
const orderStatus = toNum(order?.orderStatus);
|
||||||
|
const deliveryStatus = toNum(order?.deliveryStatus);
|
||||||
|
const riderId = toNum(order?.riderId);
|
||||||
|
|
||||||
|
if (orderStatus === 2) return 'text-gray-500'; // 已取消
|
||||||
|
if (orderStatus === 3) return 'text-orange-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 (orderStatus === 1) return 'text-green-600'; // 已完成
|
||||||
|
|
||||||
|
if (!order?.payStatus) return 'text-orange-500'; // 等待买家付款
|
||||||
|
|
||||||
|
if (deliveryStatus === 10) return 'text-blue-500'; // 待发货
|
||||||
|
if (deliveryStatus === 20) {
|
||||||
|
if (!riderId || riderId === 0) return 'text-purple-500'; // 待收货
|
||||||
|
if (order?.sendEndTime) return 'text-purple-500'; // 待确认收货
|
||||||
|
return 'text-blue-500'; // 配送中
|
||||||
|
}
|
||||||
|
if (deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
||||||
|
|
||||||
|
if (orderStatus === 0) return 'text-gray-500'; // 未使用
|
||||||
|
return 'text-gray-600';
|
||||||
|
};
|
||||||
|
|
||||||
115
src/utils/userLevel.ts
Normal file
115
src/utils/userLevel.ts
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
* 用户等级配置
|
||||||
|
* 用于分销商角色的显示和样式管理
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** 用户等级枚举 */
|
||||||
|
export enum UserLevel {
|
||||||
|
/** 普通用户 */
|
||||||
|
NORMAL = 0,
|
||||||
|
/** 超级管理员 */
|
||||||
|
SUPER_ADMIN = 1,
|
||||||
|
/** 合伙人(总店) */
|
||||||
|
PARTNER_HEAD = 2,
|
||||||
|
/** 合伙人(分店) */
|
||||||
|
PARTNER_BRANCH = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 用户等级配置接口 */
|
||||||
|
export interface UserLevelConfig {
|
||||||
|
level: UserLevel;
|
||||||
|
name: string;
|
||||||
|
/** Tag 组件的 type 属性 */
|
||||||
|
tagType: 'default' | 'success' | 'warning' | 'danger';
|
||||||
|
/** 背景色 */
|
||||||
|
bgColor: string;
|
||||||
|
/** 文字颜色 */
|
||||||
|
textColor: string;
|
||||||
|
/** 边框颜色 */
|
||||||
|
borderColor: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 用户等级配置表 */
|
||||||
|
export const USER_LEVEL_CONFIG: Record<UserLevel, UserLevelConfig> = {
|
||||||
|
[UserLevel.NORMAL]: {
|
||||||
|
level: UserLevel.NORMAL,
|
||||||
|
name: '普通用户',
|
||||||
|
tagType: 'default',
|
||||||
|
bgColor: '#f5f5f5',
|
||||||
|
textColor: '#666666',
|
||||||
|
borderColor: '#e5e5e5',
|
||||||
|
},
|
||||||
|
[UserLevel.SUPER_ADMIN]: {
|
||||||
|
level: UserLevel.SUPER_ADMIN,
|
||||||
|
name: '超级管理员',
|
||||||
|
tagType: 'danger',
|
||||||
|
bgColor: '#fff2f0',
|
||||||
|
textColor: '#cf1322',
|
||||||
|
borderColor: '#ffccc7',
|
||||||
|
},
|
||||||
|
[UserLevel.PARTNER_HEAD]: {
|
||||||
|
level: UserLevel.PARTNER_HEAD,
|
||||||
|
name: '合伙人',
|
||||||
|
tagType: 'warning',
|
||||||
|
bgColor: '#fff7e6',
|
||||||
|
textColor: '#d46b08',
|
||||||
|
borderColor: '#ffd8bf',
|
||||||
|
},
|
||||||
|
[UserLevel.PARTNER_BRANCH]: {
|
||||||
|
level: UserLevel.PARTNER_BRANCH,
|
||||||
|
name: '合伙人',
|
||||||
|
tagType: 'success',
|
||||||
|
bgColor: '#f6ffed',
|
||||||
|
textColor: '#389e0d',
|
||||||
|
borderColor: '#b7eb8f',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 显示名称(带后缀区分总店和分店) */
|
||||||
|
export const USER_LEVEL_DISPLAY_NAMES: Record<UserLevel, string> = {
|
||||||
|
[UserLevel.NORMAL]: '普通用户',
|
||||||
|
[UserLevel.SUPER_ADMIN]: '超级管理员',
|
||||||
|
[UserLevel.PARTNER_HEAD]: '合伙人(总店)',
|
||||||
|
[UserLevel.PARTNER_BRANCH]: '合伙人(分店)',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据等级值获取配置
|
||||||
|
* @param level 等级值
|
||||||
|
* @returns 用户等级配置
|
||||||
|
*/
|
||||||
|
export function getUserLevelConfig(level?: number): UserLevelConfig {
|
||||||
|
const validLevel = level ?? 0;
|
||||||
|
return USER_LEVEL_CONFIG[validLevel as UserLevel] || USER_LEVEL_CONFIG[UserLevel.NORMAL];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据等级值获取显示名称
|
||||||
|
* @param level 等级值
|
||||||
|
* @returns 显示名称
|
||||||
|
*/
|
||||||
|
export function getUserLevelName(level?: number): string {
|
||||||
|
const validLevel = level ?? 0;
|
||||||
|
return USER_LEVEL_DISPLAY_NAMES[validLevel as UserLevel] || USER_LEVEL_DISPLAY_NAMES[UserLevel.NORMAL];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是合伙人(包括总店和分店)
|
||||||
|
* @param level 等级值
|
||||||
|
* @returns 是否是合伙人
|
||||||
|
*/
|
||||||
|
export function isPartner(level?: number): boolean {
|
||||||
|
return level === UserLevel.PARTNER_HEAD || level === UserLevel.PARTNER_BRANCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是管理员(包括超级管理员)
|
||||||
|
* @param level 等级值
|
||||||
|
* @returns 是否是管理员
|
||||||
|
*/
|
||||||
|
export function isAdmin(level?: number): boolean {
|
||||||
|
return level === UserLevel.SUPER_ADMIN || level === UserLevel.ADMIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出默认配置
|
||||||
|
export default USER_LEVEL_CONFIG;
|
||||||
Reference in New Issue
Block a user