forked from gxwebsoft/mp-10550
Compare commits
70 Commits
00d3ffaeee
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 24d28d0aaa | |||
| 94e1e05fdf | |||
| 4d96ca4569 | |||
| daafca1d5d | |||
| 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 | |||
| 58d3e884ab | |||
| b9eb64894f | |||
| 81c63e0e65 | |||
| 86f7506422 | |||
| fae144549e | |||
| 718eddff63 | |||
| a4a0a922fc | |||
| ca2436a2e8 | |||
| 83ba49d860 | |||
| 7375a3b1ce | |||
| 756b548bf9 | |||
| 76e76c62ef | |||
| 546d90cc28 | |||
| d4fd61376c | |||
| b27421fd6e | |||
| b929b8d35e | |||
| 23af704c68 | |||
| ab61aa9ee0 | |||
| 64d30e1b62 | |||
| a8eb9e11be | |||
| 338dc421db | |||
| 6f1e0a6a2b | |||
| 8b5609255a | |||
| 31d47f0a0b | |||
| 68d5848d3d | |||
| e40120138b | |||
| ef26a207b0 | |||
| 78ac461ef9 | |||
| f9dcaa9ce9 | |||
| d86cdad470 | |||
| 3d94125c5e | |||
| 63d0d64a1f | |||
| 5840bea66b | |||
| 929f173b95 | |||
| 049b2396c3 | |||
| fb06816e37 | |||
| 939d7b3ec2 | |||
| d6eb6d5e05 | |||
| 694b5e1e7a |
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
|
||||||
16
.workbuddy/memory/2026-04-25.md
Normal file
16
.workbuddy/memory/2026-04-25.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# 2026-04-25 工作日志
|
||||||
|
|
||||||
|
## 微信支付"下单账号与支付账号不一致"问题修复
|
||||||
|
|
||||||
|
**问题**:用户支付时微信提示「下单账号与支付账号不一致,请核实后再支付」
|
||||||
|
|
||||||
|
**根因**:下单时后端使用的 openid 与当前实际支付的微信用户 openid 不匹配。前端在创建订单前没有刷新 openid,依赖登录/注册时的旧绑定。
|
||||||
|
|
||||||
|
**修改文件**:
|
||||||
|
1. `src/utils/payment.ts` — 新增 `ensureOpenIdBeforePay()` 方法,在 `pay()` 方法中、微信支付创建订单前强制调用 `Taro.login()` + `getWxOpenId()` 刷新绑定当前用户的 openid
|
||||||
|
2. `src/hooks/useUser.ts` — 在 `autoLoginByOpenId()` 登录成功后补充 openid 绑定逻辑(之前只调了 loginByOpenId 没有调 getWxOpenId)
|
||||||
|
|
||||||
|
**方案特点**:
|
||||||
|
- 非阻塞设计:openid 刷新失败不阻止支付(网络波动时兼容)
|
||||||
|
- 仅微信支付触发:余额支付/支付宝不受影响
|
||||||
|
- 兼容已有 openid 的场景:即使已有 openid 也会刷新(防止切号)
|
||||||
0
.workbuddy/memory/MEMORY.md
Normal file
0
.workbuddy/memory/MEMORY.md
Normal file
@@ -9,6 +9,7 @@ export const BaseUrl = API_BASE_URL;
|
|||||||
// 当前版本
|
// 当前版本
|
||||||
export const Version = 'v3.0.8';
|
export const Version = 'v3.0.8';
|
||||||
// 版权信息
|
// 版权信息
|
||||||
export const Copyright = 'WebSoft Inc.';
|
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 = 'development'
|
||||||
|
// ===========================================================
|
||||||
|
|
||||||
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-辅助函数
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#### 新增功能
|
#### 新增功能
|
||||||
- 用户头像和基本信息展示
|
- 用户头像和基本信息展示
|
||||||
- 佣金统计(可提现、冻结中、累计收益)
|
- 佣金统计(可提现、待使用、累计收益)
|
||||||
- 团队统计(一级、二级、三级成员)
|
- 团队统计(一级、二级、三级成员)
|
||||||
- 功能导航网格(分销订单、提现申请、我的团队、推广二维码)
|
- 功能导航网格(分销订单、提现申请、我的团队、推广二维码)
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ dealer: {
|
|||||||
// 金额相关
|
// 金额相关
|
||||||
money: {
|
money: {
|
||||||
available: 'linear-gradient(135deg, #10b981 0%, #059669 100%)', // 可提现 - 绿色
|
available: 'linear-gradient(135deg, #10b981 0%, #059669 100%)', // 可提现 - 绿色
|
||||||
frozen: 'linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)', // 冻结中 - 蓝色
|
frozen: 'linear-gradient(135deg, #3b82f6 0%, #2563eb 100%)', // 待使用 - 蓝色
|
||||||
total: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)' // 累计 - 橙色
|
total: 'linear-gradient(135deg, #f59e0b 0%, #d97706 100%)' // 累计 - 橙色
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询送水订单列表
|
* 查询送水订单列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ export interface GltTicketOrder {
|
|||||||
avatar?: string;
|
avatar?: string;
|
||||||
// 手机号码
|
// 手机号码
|
||||||
phone?: string;
|
phone?: string;
|
||||||
|
// 收货人姓名
|
||||||
|
receiverName?: string;
|
||||||
|
// 收货人手机号码
|
||||||
|
receiverPhone?: string;
|
||||||
// 排序(数字越小越靠前)
|
// 排序(数字越小越靠前)
|
||||||
sortNumber?: number;
|
sortNumber?: number;
|
||||||
// 备注
|
// 备注
|
||||||
@@ -76,6 +80,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;
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ export interface ShopDealerOrder {
|
|||||||
isInvalid?: number;
|
isInvalid?: number;
|
||||||
// 佣金结算(0未结算 1已结算)
|
// 佣金结算(0未结算 1已结算)
|
||||||
isSettled?: number;
|
isSettled?: number;
|
||||||
|
// 佣金解冻(0未解冻 1已解冻)
|
||||||
|
isUnfreeze?: number;
|
||||||
|
// 订单状态
|
||||||
|
orderStatus?: number;
|
||||||
// 结算时间
|
// 结算时间
|
||||||
settleTime?: number;
|
settleTime?: number;
|
||||||
// 商城ID
|
// 商城ID
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ export interface ShopStoreRider {
|
|||||||
otherGoodsCommissionValue?: string;
|
otherGoodsCommissionValue?: string;
|
||||||
// 用户ID
|
// 用户ID
|
||||||
userId?: number;
|
userId?: number;
|
||||||
|
// 经度(配送员当前位置)
|
||||||
|
longitude?: string;
|
||||||
|
// 纬度(配送员当前位置)
|
||||||
|
latitude?: string;
|
||||||
// 备注
|
// 备注
|
||||||
comments?: string;
|
comments?: string;
|
||||||
// 排序号
|
// 排序号
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ button[open-type="chooseAvatar"] {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
}
|
}
|
||||||
|
.cart-buy-only{
|
||||||
|
border-radius: 20px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image {
|
image {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export default definePageConfig({
|
export default definePageConfig({
|
||||||
navigationBarTitleText: '成为经销商',
|
navigationBarTitleText: '注册成为会员',
|
||||||
navigationBarTextStyle: 'black'
|
navigationBarTextStyle: 'black'
|
||||||
})
|
})
|
||||||
|
|||||||
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,3 +1,3 @@
|
|||||||
export default definePageConfig({
|
export default definePageConfig({
|
||||||
navigationBarTitleText: '桂乐淘分享中心'
|
navigationBarTitleText: '账户管理中心'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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">
|
||||||
@@ -134,19 +212,26 @@ const DealerIndex: React.FC = () => {
|
|||||||
<View className="grid grid-cols-3 gap-3">
|
<View className="grid grid-cols-3 gap-3">
|
||||||
<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.available
|
background: businessGradients.money.available
|
||||||
}}>
|
}} onClick={() => navigateToPage('/dealer/withdraw/index')}>
|
||||||
<Text className="text-lg font-bold mb-1 text-white">
|
<Text className="text-lg font-bold mb-1 text-white">
|
||||||
{formatMoney(dealerUser.money)}
|
{formatMoney(dealerUser.money)}
|
||||||
</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>
|
||||||
|
|||||||
@@ -94,15 +94,19 @@ const DealerOrders: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [fetchOrders])
|
}, [fetchOrders])
|
||||||
|
|
||||||
const getStatusText = (isSettled?: number, isInvalid?: number) => {
|
const getStatusText = (isSettled?: number, isInvalid?: number, isUnfreeze?: number, orderStatus?: number) => {
|
||||||
|
if (orderStatus === 2 || orderStatus === 5 || orderStatus === 6) return '已取消'
|
||||||
if (isInvalid === 1) return '已失效'
|
if (isInvalid === 1) return '已失效'
|
||||||
|
if (isUnfreeze === 1) return '已解冻'
|
||||||
if (isSettled === 1) return '已结算'
|
if (isSettled === 1) return '已结算'
|
||||||
return '待结算'
|
return '待结算'
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatusColor = (isSettled?: number, isInvalid?: number) => {
|
const getStatusColor = (isSettled?: number, isInvalid?: number, isUnfreeze?: number, orderStatus?: number) => {
|
||||||
|
if (orderStatus === 2 || orderStatus === 5 || orderStatus === 6) return 'default'
|
||||||
if (isInvalid === 1) return 'danger'
|
if (isInvalid === 1) return 'danger'
|
||||||
if (isSettled === 1) return 'success'
|
if (isUnfreeze === 1) return 'success'
|
||||||
|
if (isSettled === 1) return 'info'
|
||||||
return 'warning'
|
return 'warning'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,8 +124,8 @@ const DealerOrders: React.FC = () => {
|
|||||||
<Text className="font-semibold text-gray-800">
|
<Text className="font-semibold text-gray-800">
|
||||||
订单号:{order.orderNo || '-'}
|
订单号:{order.orderNo || '-'}
|
||||||
</Text>
|
</Text>
|
||||||
<Tag type={getStatusColor(order.isSettled, order.isInvalid)}>
|
<Tag type={getStatusColor(order.isSettled, order.isInvalid, order.isUnfreeze,order.orderStatus)}>
|
||||||
{getStatusText(order.isSettled, order.isInvalid)}
|
{getStatusText(order.isSettled, order.isInvalid, order.isUnfreeze,order.orderStatus)}
|
||||||
</Tag>
|
</Tag>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
export default definePageConfig({
|
export default definePageConfig({
|
||||||
navigationBarTitleText: '桂乐淘分享中心'
|
navigationBarTitleText: '账户管理中心',
|
||||||
|
// Enable "Share to friends" and "Share to Moments" (timeline) for this page.
|
||||||
|
enableShareAppMessage: true,
|
||||||
|
enableShareTimeline: true
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, {useState, useEffect} from 'react'
|
|||||||
import {View, Text, Image} from '@tarojs/components'
|
import {View, Text, Image} from '@tarojs/components'
|
||||||
import {Button, Loading} from '@nutui/nutui-react-taro'
|
import {Button, Loading} from '@nutui/nutui-react-taro'
|
||||||
import {Download, QrCode} from '@nutui/icons-react-taro'
|
import {Download, QrCode} from '@nutui/icons-react-taro'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro, {useShareAppMessage} from '@tarojs/taro'
|
||||||
import {useDealerUser} from '@/hooks/useDealerUser'
|
import {useDealerUser} from '@/hooks/useDealerUser'
|
||||||
import {generateInviteCode} from '@/api/invite'
|
import {generateInviteCode} from '@/api/invite'
|
||||||
// import type {InviteStats} from '@/api/invite'
|
// import type {InviteStats} from '@/api/invite'
|
||||||
@@ -16,6 +16,39 @@ const DealerQrcode: React.FC = () => {
|
|||||||
// const [statsLoading, setStatsLoading] = useState<boolean>(false)
|
// const [statsLoading, setStatsLoading] = useState<boolean>(false)
|
||||||
const {dealerUser, loading: dealerLoading, error, refresh} = useDealerUser()
|
const {dealerUser, loading: dealerLoading, error, refresh} = useDealerUser()
|
||||||
|
|
||||||
|
// Enable "转发给朋友" + "分享到朋友圈" items in the share panel/menu.
|
||||||
|
useEffect(() => {
|
||||||
|
// Some clients require explicit call to show both share entries.
|
||||||
|
Taro.showShareMenu({
|
||||||
|
withShareTicket: true,
|
||||||
|
showShareItems: ['shareAppMessage', 'shareTimeline']
|
||||||
|
}).catch(() => {})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 转发给朋友(分享小程序链接)
|
||||||
|
useShareAppMessage(() => {
|
||||||
|
const inviterRaw = dealerUser?.userId ?? Taro.getStorageSync('UserId')
|
||||||
|
const inviter = Number(inviterRaw)
|
||||||
|
const hasInviter = Number.isFinite(inviter) && inviter > 0
|
||||||
|
|
||||||
|
const user = Taro.getStorageSync('User') || {}
|
||||||
|
const nickname = (user && (user.nickname || user.realName || user.username)) || ''
|
||||||
|
const title = hasInviter ? `${nickname || '我'}邀请你加入桂乐淘伙伴计划` : '桂乐淘伙伴计划'
|
||||||
|
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
path: hasInviter
|
||||||
|
? `/pages/index/index?inviter=${inviter}&source=dealer_qrcode&t=${Date.now()}`
|
||||||
|
: `/pages/index/index`,
|
||||||
|
success: function () {
|
||||||
|
Taro.showToast({title: '分享成功', icon: 'success', duration: 2000})
|
||||||
|
},
|
||||||
|
fail: function () {
|
||||||
|
Taro.showToast({title: '分享失败', icon: 'none', duration: 2000})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 生成小程序码
|
// 生成小程序码
|
||||||
const generateMiniProgramCode = async () => {
|
const generateMiniProgramCode = async () => {
|
||||||
if (!dealerUser?.userId) {
|
if (!dealerUser?.userId) {
|
||||||
@@ -376,29 +409,7 @@ const DealerQrcode: React.FC = () => {
|
|||||||
保存小程序码到相册
|
保存小程序码到相册
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
{/*<View className={'my-2 bg-white'}>*/}
|
|
||||||
{/* <Button*/}
|
|
||||||
{/* size="large"*/}
|
|
||||||
{/* block*/}
|
|
||||||
{/* icon={<Copy/>}*/}
|
|
||||||
{/* onClick={copyInviteInfo}*/}
|
|
||||||
{/* disabled={!dealerUser?.userId || codeLoading}*/}
|
|
||||||
{/* >*/}
|
|
||||||
{/* 复制邀请信息*/}
|
|
||||||
{/* </Button>*/}
|
|
||||||
{/*</View>*/}
|
|
||||||
{/*<View className={'my-2 bg-white'}>*/}
|
|
||||||
{/* <Button*/}
|
|
||||||
{/* size="large"*/}
|
|
||||||
{/* block*/}
|
|
||||||
{/* fill="outline"*/}
|
|
||||||
{/* icon={<Share/>}*/}
|
|
||||||
{/* onClick={shareMiniProgramCode}*/}
|
|
||||||
{/* disabled={!dealerUser?.userId || codeLoading}*/}
|
|
||||||
{/* >*/}
|
|
||||||
{/* 分享给好友*/}
|
|
||||||
{/* </Button>*/}
|
|
||||||
{/*</View>*/}
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 推广说明 */}
|
{/* 推广说明 */}
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ const DealerTeam: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
{/* 显示手机号(仅本级可见) */}
|
{/* 显示手机号(仅本级可见) */}
|
||||||
{showPhone && member.phone && (
|
{showPhone && member.phone && (
|
||||||
<Text className="text-sm text-gray-500" onClick={(e) => {
|
<Text className="text-sm text-gray-500 hidden" onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
makePhoneCall(member.phone || '');
|
makePhoneCall(member.phone || '');
|
||||||
}}>
|
}}>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ const normalizeMoneyString = (money: unknown) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DealerWithdraw: React.FC = () => {
|
const DealerWithdraw: React.FC = () => {
|
||||||
const [activeTab, setActiveTab] = useState<string | number>('0')
|
const [activeTab, setActiveTab] = useState<string>('0')
|
||||||
const [loading, setLoading] = useState<boolean>(false)
|
const [loading, setLoading] = useState<boolean>(false)
|
||||||
const [refreshing, setRefreshing] = useState<boolean>(false)
|
const [refreshing, setRefreshing] = useState<boolean>(false)
|
||||||
const [submitting, setSubmitting] = useState<boolean>(false)
|
const [submitting, setSubmitting] = useState<boolean>(false)
|
||||||
@@ -114,10 +114,11 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
// Tab 切换处理函数
|
// Tab 切换处理函数
|
||||||
const handleTabChange = (value: string | number) => {
|
const handleTabChange = (value: string | number) => {
|
||||||
console.log('Tab切换到:', value)
|
console.log('Tab切换到:', value)
|
||||||
setActiveTab(value)
|
const next = String(value)
|
||||||
|
setActiveTab(next)
|
||||||
|
|
||||||
// 如果切换到提现记录页面,刷新数据
|
// 如果切换到提现记录页面,刷新数据
|
||||||
if (String(value) === '1') {
|
if (next === '1') {
|
||||||
fetchWithdrawRecords()
|
fetchWithdrawRecords()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,10 +308,17 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
// return
|
// return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (amount > 200) {
|
||||||
|
Taro.showToast({
|
||||||
|
title: '单笔最多提现200元',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
if (amount > available) {
|
if (amount > available) {
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '提现金额超过可用余额',
|
title: '提现金额超过可用余额',
|
||||||
icon: 'error'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -323,7 +331,6 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
money: values.amount,
|
money: values.amount,
|
||||||
// Only support WeChat wallet withdrawals.
|
// Only support WeChat wallet withdrawals.
|
||||||
payType: 10,
|
payType: 10,
|
||||||
applyStatus: 10, // 待审核
|
|
||||||
platform: 'MiniProgram'
|
platform: 'MiniProgram'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +420,7 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const quickAmounts = ['100', '300', '500', '1000']
|
const quickAmounts = ['50', '100', '200']
|
||||||
|
|
||||||
const setQuickAmount = (amount: string) => {
|
const setQuickAmount = (amount: string) => {
|
||||||
formRef.current?.setFieldsValue({amount})
|
formRef.current?.setFieldsValue({amount})
|
||||||
@@ -488,10 +495,10 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
labelPosition="top"
|
labelPosition="top"
|
||||||
>
|
>
|
||||||
<CellGroup>
|
<CellGroup>
|
||||||
<Form.Item name="amount" label="提现金额" required>
|
<Form.Item name="amount" label="提现金额">
|
||||||
<Input
|
<Input
|
||||||
placeholder="请输入提现金额"
|
placeholder="请输入提现金额"
|
||||||
type="number"
|
type="digit"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -523,8 +530,9 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
<Text className="text-sm text-red-500">
|
<Text className="text-sm text-red-500">
|
||||||
注意事项:
|
注意事项:
|
||||||
1. 提取佣金必须完成实名认证。
|
1. 提取佣金必须完成实名认证。
|
||||||
2. 佣金非自动到账,再您提取佣金申请通过后,请手动到我的申请记录点击领取。
|
2. 佣金非自动到账,在您提取佣金申请通过后,请手动到我的申请记录点击领取。
|
||||||
3. 桂乐淘温馨提示,请您依法依规申报所得,缴税相关税费。
|
3. 桂乐淘温馨提示,请您依法依规申报所得,缴税相关税费。
|
||||||
|
4. 单笔提现最高金额为200。
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
@@ -629,13 +637,12 @@ const DealerWithdraw: React.FC = () => {
|
|||||||
<View className="bg-gray-50 min-h-screen">
|
<View className="bg-gray-50 min-h-screen">
|
||||||
<Tabs value={activeTab} onChange={handleTabChange}>
|
<Tabs value={activeTab} onChange={handleTabChange}>
|
||||||
<Tabs.TabPane title="申请提现" value="0">
|
<Tabs.TabPane title="申请提现" value="0">
|
||||||
{renderWithdrawForm()}
|
|
||||||
</Tabs.TabPane>
|
</Tabs.TabPane>
|
||||||
|
|
||||||
<Tabs.TabPane title="提现记录" value="1">
|
<Tabs.TabPane title="提现记录" value="1">
|
||||||
{renderWithdrawRecords()}
|
|
||||||
</Tabs.TabPane>
|
</Tabs.TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
{activeTab === '0' ? renderWithdrawForm() : renderWithdrawRecords()}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import Taro from '@tarojs/taro';
|
import Taro from '@tarojs/taro';
|
||||||
import { User } from '@/api/system/user/model';
|
import { User } from '@/api/system/user/model';
|
||||||
import { getUserInfo, updateUserInfo, loginByOpenId } from '@/api/layout';
|
import { getUserInfo, updateUserInfo, loginByOpenId, getWxOpenId } from '@/api/layout';
|
||||||
import { TenantId } from '@/config/app';
|
import { TenantId } from '@/config/app';
|
||||||
import {getStoredInviteParams, handleInviteRelation} from '@/utils/invite';
|
import { handleInviteRelation } from '@/utils/invite';
|
||||||
|
|
||||||
// 用户Hook
|
// 用户Hook
|
||||||
export const useUser = () => {
|
export const useUser = () => {
|
||||||
@@ -27,6 +27,24 @@ export const useUser = () => {
|
|||||||
setUser(data.user);
|
setUser(data.user);
|
||||||
setIsLoggedIn(true);
|
setIsLoggedIn(true);
|
||||||
|
|
||||||
|
// 自动登录成功后,补齐 openid(JSAPI 微信支付必需)
|
||||||
|
// 防止后续支付时报"下单账号与支付账号不一致"
|
||||||
|
if (!data.user?.openid) {
|
||||||
|
try {
|
||||||
|
const freshCode = await new Promise<string | undefined>((resolve, reject) => {
|
||||||
|
Taro.login({
|
||||||
|
success: (r) => resolve(r.code as string),
|
||||||
|
fail: () => resolve(undefined),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (freshCode) {
|
||||||
|
await getWxOpenId({ code: freshCode });
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
console.warn('自动登录后绑定 openid 失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 处理邀请关系
|
// 处理邀请关系
|
||||||
if (data.user?.userId) {
|
if (data.user?.userId) {
|
||||||
try {
|
try {
|
||||||
@@ -44,15 +62,10 @@ export const useUser = () => {
|
|||||||
reject(new Error('自动登录失败'));
|
reject(new Error('自动登录失败'));
|
||||||
}
|
}
|
||||||
}).catch(_ => {
|
}).catch(_ => {
|
||||||
// 首次注册,跳转到邀请注册页面
|
// 登录失败(通常是新用户尚未注册/未绑定手机号等)。
|
||||||
const pages = Taro.getCurrentPages();
|
// 这里不做任何“自动跳转”,避免用户点击「我的」时被强制带到分销/申请页,体验割裂。
|
||||||
const currentPage = pages[pages.length - 1];
|
// 需要登录的页面请使用 utils/auth 的 ensureLoggedIn / goToRegister 做显式跳转。
|
||||||
const inviteParams = getStoredInviteParams()
|
reject(new Error('autoLoginByOpenId failed'));
|
||||||
if (currentPage?.route !== 'dealer/apply/add' && inviteParams?.inviter) {
|
|
||||||
return Taro.navigateTo({
|
|
||||||
url: '/dealer/apply/add'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: reject
|
fail: reject
|
||||||
@@ -60,7 +73,11 @@ export const useUser = () => {
|
|||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('自动登录失败:', error);
|
const msg = error instanceof Error ? error.message : String(error);
|
||||||
|
// 新用户首次进入、未绑定手机号等场景属于“预期失败”,避免刷屏报错。
|
||||||
|
if (msg !== 'autoLoginByOpenId failed') {
|
||||||
|
console.error('自动登录失败:', error);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Header from './Header'
|
// import Header from './Header'
|
||||||
import Banner from './Banner'
|
import Banner from './Banner'
|
||||||
import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro'
|
import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro'
|
||||||
import { View, Text, Image, ScrollView } from '@tarojs/components'
|
import { View, Text, Image, ScrollView } from '@tarojs/components'
|
||||||
import { useEffect, useMemo, useState, type ReactNode } from 'react'
|
import { useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||||
import { Cart, Gift, Ticket } from '@nutui/icons-react-taro'
|
import { Cart, Gift, Ticket, Agenda, ArrowRight } from '@nutui/icons-react-taro'
|
||||||
import { getShopInfo } from '@/api/layout'
|
import { getShopInfo } from '@/api/layout'
|
||||||
import { checkAndHandleInviteRelation, hasPendingInvite } from '@/utils/invite'
|
import { checkAndHandleInviteRelation, hasPendingInvite } from '@/utils/invite'
|
||||||
import { pageShopGoods } from '@/api/shop/shopGoods'
|
import { pageShopGoods } from '@/api/shop/shopGoods'
|
||||||
@@ -11,6 +11,7 @@ import type { ShopGoods, ShopGoodsParam } from '@/api/shop/shopGoods/model'
|
|||||||
import { getMyGltUserTicketTotal } from '@/api/glt/gltUserTicket'
|
import { getMyGltUserTicketTotal } from '@/api/glt/gltUserTicket'
|
||||||
import { ensureLoggedIn } from '@/utils/auth'
|
import { ensureLoggedIn } from '@/utils/auth'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
// import navTo from "@/utils/common";
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
const [activeTabKey, setActiveTabKey] = useState('recommend')
|
const [activeTabKey, setActiveTabKey] = useState('recommend')
|
||||||
@@ -20,9 +21,12 @@ function Home() {
|
|||||||
useShareAppMessage(() => {
|
useShareAppMessage(() => {
|
||||||
// 获取当前用户ID,用于生成邀请链接
|
// 获取当前用户ID,用于生成邀请链接
|
||||||
const userId = Taro.getStorageSync('UserId');
|
const userId = Taro.getStorageSync('UserId');
|
||||||
|
const user = Taro.getStorageSync('User') || {};
|
||||||
|
const nickname =
|
||||||
|
(user && (user.nickname || user.realName || user.username)) || '';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: userId + '超值推荐',
|
title: (nickname || '') + '超值推荐',
|
||||||
path: userId ? `/pages/index/index?inviter=${userId}&source=share&t=${Date.now()}` : `/pages/index/index`,
|
path: userId ? `/pages/index/index?inviter=${userId}&source=share&t=${Date.now()}` : `/pages/index/index`,
|
||||||
success: function () {
|
success: function () {
|
||||||
console.log('首页分享成功');
|
console.log('首页分享成功');
|
||||||
@@ -164,6 +168,7 @@ function Home() {
|
|||||||
Taro.getUserInfo({
|
Taro.getUserInfo({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
const avatar = res.userInfo.avatarUrl;
|
const avatar = res.userInfo.avatarUrl;
|
||||||
|
// Keep WeChat display name in storage so share title can use it.
|
||||||
console.log(avatar, 'avatarUrl')
|
console.log(avatar, 'avatarUrl')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -212,8 +217,18 @@ 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' })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'order',
|
||||||
|
title: '送水订单',
|
||||||
|
icon: <Agenda size={30} />,
|
||||||
|
onClick: () => {
|
||||||
|
const url = '/user/ticket/index?tab=order'
|
||||||
|
if (!ensureLoggedIn(url)) return
|
||||||
|
Taro.navigateTo({ url })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -245,7 +260,7 @@ function Home() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Header区域 */}
|
{/* Header区域 */}
|
||||||
<Header />
|
{/*<Header />*/}
|
||||||
|
|
||||||
<View className="home-page">
|
<View className="home-page">
|
||||||
{/* 顶部活动主视觉:使用 Banner 组件 */}
|
{/* 顶部活动主视觉:使用 Banner 组件 */}
|
||||||
@@ -276,7 +291,21 @@ function Home() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 分类Tabs */}
|
<View className="ticket-card" onClick={() => Taro.navigateTo({ url: `/shop/category/index?id=4560` })}>
|
||||||
|
<View className="ticket-card__head">
|
||||||
|
<Text className="ticket-card__title">政企采购专区</Text>
|
||||||
|
<ArrowRight className={'text-gray-50'} size={16} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View className="ticket-card" onClick={() => Taro.navigateTo({ url: `/shop/category/index?id=4556` })}>
|
||||||
|
<View className="ticket-card__head">
|
||||||
|
<Text className="ticket-card__title">桂乐淘·福利惊爆区</Text>
|
||||||
|
<ArrowRight className={'text-gray-50'} size={16} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/*分类Tabs*/}
|
||||||
<ScrollView className="home-tabs" scrollX enableFlex>
|
<ScrollView className="home-tabs" scrollX enableFlex>
|
||||||
<View className="home-tabs__inner">
|
<View className="home-tabs__inner">
|
||||||
{tabs.map((tab) => {
|
{tabs.map((tab) => {
|
||||||
@@ -293,7 +322,6 @@ function Home() {
|
|||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
{/* 商品列表 */}
|
{/* 商品列表 */}
|
||||||
<View className="goods-grid">
|
<View className="goods-grid">
|
||||||
{visibleGoods.map((item) => (
|
{visibleGoods.map((item) => (
|
||||||
@@ -316,20 +344,20 @@ function Home() {
|
|||||||
<Text className="goods-card__sold">已购:{item.sales || 0}人</Text>
|
<Text className="goods-card__sold">已购:{item.sales || 0}人</Text>
|
||||||
<View className="goods-card__price">
|
<View className="goods-card__price">
|
||||||
<Text className="goods-card__priceUnit">¥</Text>
|
<Text className="goods-card__priceUnit">¥</Text>
|
||||||
<Text className="goods-card__priceValue">{item.price}</Text>
|
<Text className="goods-card__priceValue">{item.buyingPrice}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View className="goods-card__actions">
|
<View className="goods-card__actions">
|
||||||
<View
|
{/*<View*/}
|
||||||
className="goods-card__btn goods-card__btn--ghost"
|
{/* className="goods-card__btn goods-card__btn--ghost"*/}
|
||||||
onClick={() => {
|
{/* onClick={() => {*/}
|
||||||
if (!ensureLoggedIn('/shop/orderConfirm/index?goodsId=10074')) return
|
{/* if (!ensureLoggedIn('/shop/orderConfirm/index?goodsId=10074')) return*/}
|
||||||
Taro.navigateTo({ url: '/shop/orderConfirm/index?goodsId=10074' })
|
{/* Taro.navigateTo({ url: '/shop/orderConfirm/index?goodsId=10074' })*/}
|
||||||
}}
|
{/* }}*/}
|
||||||
>
|
{/*>*/}
|
||||||
<Text className="goods-card__btnText">买水票更优惠</Text>
|
{/* <Text className="goods-card__btnText">买水票更优惠</Text>*/}
|
||||||
</View>
|
{/*</View>*/}
|
||||||
<View
|
<View
|
||||||
className="goods-card__btn goods-card__btn--primary"
|
className="goods-card__btn goods-card__btn--primary"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@@ -343,6 +371,7 @@ function Home() {
|
|||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const IsDealer = () => {
|
|||||||
<View style={{display: 'inline-flex', alignItems: 'center'}}>
|
<View style={{display: 'inline-flex', alignItems: 'center'}}>
|
||||||
<Reward className={'text-orange-100 '} size={16}/>
|
<Reward className={'text-orange-100 '} size={16}/>
|
||||||
<Text style={{fontSize: '16px'}}
|
<Text style={{fontSize: '16px'}}
|
||||||
className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '桂乐淘分享中心'}</Text>
|
className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '账户管理中心'}</Text>
|
||||||
{/*<Text className={'text-white opacity-80 pl-3'}>门店核销</Text>*/}
|
{/*<Text className={'text-white opacity-80 pl-3'}>门店核销</Text>*/}
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ const IsDealer = () => {
|
|||||||
title={
|
title={
|
||||||
<View style={{display: 'inline-flex', alignItems: 'center'}}>
|
<View style={{display: 'inline-flex', alignItems: 'center'}}>
|
||||||
<Reward className={'text-orange-100 '} size={16}/>
|
<Reward className={'text-orange-100 '} size={16}/>
|
||||||
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '桂乐淘分享中心'}</Text>
|
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '账户管理中心'}</Text>
|
||||||
<Text className={'text-white opacity-80 pl-3'}>{config?.vipComments || ''}</Text>
|
<Text className={'text-white opacity-80 pl-3'}>{config?.vipComments || ''}</Text>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ 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()
|
||||||
const {getDisplayName, isAdmin} = useUser();
|
const {loadUserFromStorage} = useUser();
|
||||||
const [IsLogin, setIsLogin] = useState<boolean>(false)
|
const [IsLogin, setIsLogin] = useState<boolean>(false)
|
||||||
const [userInfo, setUserInfo] = useState<User>()
|
const [userInfo, setUserInfo] = useState<User>()
|
||||||
const [ticketTotal, setTicketTotal] = useState<number>(0)
|
const [ticketTotal, setTicketTotal] = useState<number>(0)
|
||||||
@@ -25,14 +26,34 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
const themeStyles = useThemeStyles();
|
const themeStyles = useThemeStyles();
|
||||||
const canShowScanButton = (() => {
|
const canShowScanButton = (() => {
|
||||||
const v: any = (userInfo as any)?.isAdmin
|
const v: any = (userInfo as any)?.isAdmin
|
||||||
return isAdmin() || v === true || v === 1 || v === '1'
|
return v === true || v === 1 || v === '1'
|
||||||
})()
|
})()
|
||||||
|
|
||||||
// 角色名称:优先取用户 roles 数组的第一个角色名称
|
const getDisplayName = () => {
|
||||||
|
if (!userInfo) return IsLogin ? '用户' : '点击登录'
|
||||||
|
return userInfo.nickname || (userInfo as any).realName || (userInfo as any).username || (IsLogin ? '用户' : '点击登录')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 角色名称:优先使用 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()
|
||||||
@@ -45,10 +66,46 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const syncUserToStorage = (u: User) => {
|
||||||
|
// Keep storage up-to-date for other places that read user info synchronously.
|
||||||
|
Taro.setStorageSync('User', u)
|
||||||
|
if (u?.userId) Taro.setStorageSync('UserId', u.userId)
|
||||||
|
if (u?.nickname) Taro.setStorageSync('WxNickName', u.nickname)
|
||||||
|
}
|
||||||
|
|
||||||
|
const reloadUserInfo = async () => {
|
||||||
|
try {
|
||||||
|
const u = await getUserInfo()
|
||||||
|
if (u) {
|
||||||
|
setUserInfo(u)
|
||||||
|
setIsLogin(true)
|
||||||
|
syncUserToStorage(u)
|
||||||
|
// Refresh this hook instance's state from storage (defensive).
|
||||||
|
await loadUserFromStorage()
|
||||||
|
|
||||||
|
// 获取openId(不阻塞 UI 刷新)
|
||||||
|
if (!u.openid) {
|
||||||
|
Taro.login({
|
||||||
|
success: (res) => {
|
||||||
|
getWxOpenId({code: res.code}).catch(() => {})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Not logged in / token expired: keep UI in "not login" state.
|
||||||
|
// Other error handling is done in request interceptor / callers.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 暴露方法给父组件
|
// 暴露方法给父组件
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
handleRefresh: () => reloadStats(true),
|
handleRefresh: async () => {
|
||||||
reloadStats
|
await reloadUserInfo()
|
||||||
|
await reloadStats(true)
|
||||||
|
},
|
||||||
|
reloadStats,
|
||||||
|
reloadUserInfo
|
||||||
}))
|
}))
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -97,30 +154,15 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
nickname: res.userInfo.nickName,
|
nickname: res.userInfo.nickName,
|
||||||
sexName: res.userInfo.gender == 1 ? '男' : '女'
|
sexName: res.userInfo.gender == 1 ? '男' : '女'
|
||||||
})
|
})
|
||||||
getUserInfo().then((data) => {
|
reloadUserInfo()
|
||||||
if (data) {
|
.then(() => {
|
||||||
setUserInfo(data)
|
|
||||||
setIsLogin(true);
|
|
||||||
// Keep local storage user info in sync so other hooks (e.g. unified scan) can read admin flags.
|
|
||||||
Taro.setStorageSync('User', data)
|
|
||||||
Taro.setStorageSync('UserId', data.userId)
|
|
||||||
// 登录态已就绪后刷新卡片统计(余额/积分/券/水票)
|
// 登录态已就绪后刷新卡片统计(余额/积分/券/水票)
|
||||||
refresh().then()
|
refresh().then()
|
||||||
reloadTicketTotal()
|
reloadTicketTotal()
|
||||||
|
})
|
||||||
// 获取openId
|
.catch(() => {
|
||||||
if (!data.openid) {
|
console.log('未登录')
|
||||||
Taro.login({
|
})
|
||||||
success: (res) => {
|
|
||||||
getWxOpenId({code: res.code}).then(() => {
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).catch(() => {
|
|
||||||
console.log('未登录')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -241,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>
|
||||||
@@ -309,13 +366,9 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
<View className={'py-2'}>
|
<View className={'py-2'}>
|
||||||
<View className={'flex justify-around mt-1'}>
|
<View className={'flex justify-around mt-1'}>
|
||||||
<View className={'item flex justify-center flex-col items-center'}
|
<View className={'item flex justify-center flex-col items-center'}
|
||||||
onClick={() => navTo('/user/wallet/wallet', true)}>
|
onClick={() => navTo('/user/ticket/index', true)}>
|
||||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>余额</Text>
|
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>水票</Text>
|
||||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.balance || '0.00'}</Text>
|
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{ticketTotal}</Text>
|
||||||
</View>
|
|
||||||
<View className={'item flex justify-center flex-col items-center'}>
|
|
||||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>积分</Text>
|
|
||||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.points || 0}</Text>
|
|
||||||
</View>
|
</View>
|
||||||
<View className={'item flex justify-center flex-col items-center'}
|
<View className={'item flex justify-center flex-col items-center'}
|
||||||
onClick={() => navTo('/user/coupon/index', true)}>
|
onClick={() => navTo('/user/coupon/index', true)}>
|
||||||
@@ -323,9 +376,13 @@ const UserCard = forwardRef<any, any>((_, ref) => {
|
|||||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.coupons || 0}</Text>
|
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.coupons || 0}</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className={'item flex justify-center flex-col items-center'}
|
<View className={'item flex justify-center flex-col items-center'}
|
||||||
onClick={() => navTo('/user/ticket/index', true)}>
|
onClick={() => navTo('/user/wallet/wallet', true)}>
|
||||||
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>水票</Text>
|
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>余额</Text>
|
||||||
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{ticketTotal}</Text>
|
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.balance || '0.00'}</Text>
|
||||||
|
</View>
|
||||||
|
<View className={'item flex justify-center flex-col items-center'}>
|
||||||
|
<Text className={'text-xs text-gray-200'} style={themeStyles.textColor}>积分</Text>
|
||||||
|
<Text className={'text-xl text-white'} style={themeStyles.textColor}>{data?.points || 0}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</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,10 +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>
|
<View className={'text-xs text-gray-400 py-1 flex justify-center items-center gap-2'}>
|
||||||
|
<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'}}
|
||||||
@@ -65,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',
|
||||||
@@ -75,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
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const UserCell = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View className="bg-white mx-4 mt-4 rounded-xl">
|
<View className="bg-white mx-4 mt-4 rounded-xl">
|
||||||
<View className="font-semibold text-gray-800 pt-4 pl-4">我的服务</View>
|
<View className="font-semibold text-gray-800 pt-4 pl-4">桂乐淘服务中心</View>
|
||||||
<ConfigProvider>
|
<ConfigProvider>
|
||||||
<Grid
|
<Grid
|
||||||
columns={4}
|
columns={4}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {useEffect, useRef} from 'react'
|
import {useEffect, useRef, useState} from 'react'
|
||||||
import {PullToRefresh} from '@nutui/nutui-react-taro'
|
import {PullToRefresh} from '@nutui/nutui-react-taro'
|
||||||
import UserCard from "./components/UserCard";
|
import UserCard from "./components/UserCard";
|
||||||
import UserOrder from "./components/UserOrder";
|
import UserOrder from "./components/UserOrder";
|
||||||
@@ -14,12 +14,15 @@ function User() {
|
|||||||
|
|
||||||
const userCardRef = useRef<any>()
|
const userCardRef = useRef<any>()
|
||||||
const themeStyles = useThemeStyles();
|
const themeStyles = useThemeStyles();
|
||||||
|
// TabBar 页在小程序里通常不会销毁;从“注册/申请”页返回时需要触发子组件重新初始化/拉取最新状态。
|
||||||
|
const [dealerViewKey, setDealerViewKey] = useState(0)
|
||||||
|
|
||||||
// 下拉刷新处理
|
// 下拉刷新处理
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
if (userCardRef.current?.handleRefresh) {
|
if (userCardRef.current?.handleRefresh) {
|
||||||
await userCardRef.current.handleRefresh()
|
await userCardRef.current.handleRefresh()
|
||||||
}
|
}
|
||||||
|
setDealerViewKey(v => v + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -28,6 +31,9 @@ function User() {
|
|||||||
// 每次进入/切回个人中心都刷新一次统计(包含水票数量)
|
// 每次进入/切回个人中心都刷新一次统计(包含水票数量)
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
userCardRef.current?.reloadStats?.()
|
userCardRef.current?.reloadStats?.()
|
||||||
|
// 个人资料(头像/昵称)可能在其它页面被修改,这里确保返回时立刻刷新
|
||||||
|
userCardRef.current?.reloadUserInfo?.()
|
||||||
|
setDealerViewKey(v => v + 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -56,7 +62,7 @@ function User() {
|
|||||||
</View>
|
</View>
|
||||||
<UserCard ref={userCardRef}/>
|
<UserCard ref={userCardRef}/>
|
||||||
<UserOrder/>
|
<UserOrder/>
|
||||||
<IsDealer/>
|
<IsDealer key={dealerViewKey}/>
|
||||||
<UserGrid/>
|
<UserGrid/>
|
||||||
<UserFooter/>
|
<UserFooter/>
|
||||||
</PullToRefresh>
|
</PullToRefresh>
|
||||||
|
|||||||
@@ -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)',
|
||||||
@@ -130,7 +256,7 @@ const DealerIndex: React.FC = () => {
|
|||||||
{dealerUser && (
|
{dealerUser && (
|
||||||
<View className="mx-4 -mt-6 rounded-xl p-4 relative z-10" style={cardGradients.elevated}>
|
<View className="mx-4 -mt-6 rounded-xl p-4 relative z-10" style={cardGradients.elevated}>
|
||||||
<View className="mb-4">
|
<View className="mb-4">
|
||||||
<Text className="font-semibold text-gray-800">工资统计</Text>
|
<Text className="font-semibold text-gray-800">配送提成</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className="grid grid-cols-3 gap-3">
|
<View className="grid grid-cols-3 gap-3">
|
||||||
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
<View className="text-center p-3 rounded-lg flex flex-col" style={{
|
||||||
@@ -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">
|
||||||
@@ -398,7 +410,7 @@ export default function RiderOrders() {
|
|||||||
<View className="mt-3 bg-white rounded-lg">
|
<View className="mt-3 bg-white rounded-lg">
|
||||||
<View className="text-sm text-gray-700">
|
<View className="text-sm text-gray-700">
|
||||||
<Text className="text-gray-500">客户:</Text>
|
<Text className="text-gray-500">客户:</Text>
|
||||||
<Text>{o.nickname || '-'} {o.phone ? `(${o.phone})` : ''}</Text>
|
<Text>{o.receiverName || o.nickname} {o.receiverPhone ? `(${o.receiverPhone})` : o.phone}</Text>
|
||||||
</View>
|
</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>
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
|
||||||
|
.goods-grid {
|
||||||
|
margin-top: 18rpx;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card {
|
||||||
|
border-radius: 22rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 18rpx 36rpx rgba(0, 0, 0, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__imgWrap {
|
||||||
|
padding: 18rpx 18rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__img {
|
||||||
|
width: 100%;
|
||||||
|
height: 280rpx;
|
||||||
|
border-radius: 18rpx;
|
||||||
|
background: #f4f4f4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__body {
|
||||||
|
padding: 18rpx 18rpx 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__title {
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 26rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #1c1c1c;
|
||||||
|
min-height: 72rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__meta {
|
||||||
|
margin-top: 10rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__sold {
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #9a9a9a;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__price {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 4rpx;
|
||||||
|
color: #27c86b;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__priceUnit {
|
||||||
|
font-size: 22rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__priceValue {
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__actions {
|
||||||
|
margin-top: 16rpx;
|
||||||
|
display: flex;
|
||||||
|
gap: 14rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__btn {
|
||||||
|
flex: 1;
|
||||||
|
height: 64rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__btn--ghost {
|
||||||
|
border: 2rpx solid rgba(32, 194, 106, 0.7);
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__btn--primary {
|
||||||
|
background: linear-gradient(90deg, #24d34c 0%, #6df09a 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__btnText {
|
||||||
|
font-size: 24rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #18b85a;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goods-card__btnText--primary {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-btn{
|
||||||
|
height: 70px;
|
||||||
|
background: linear-gradient(to bottom, #1cd98a, #24ca94);
|
||||||
|
border-radius: 100px;
|
||||||
|
color: #ffffff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-around;
|
||||||
|
.cart-icon{
|
||||||
|
background: linear-gradient(to bottom, #bbe094, #4ee265);
|
||||||
|
border-radius: 100px 0 0 100px;
|
||||||
|
height: 70px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,51 +1,57 @@
|
|||||||
import {Image} from '@nutui/nutui-react-taro'
|
import {Image} from '@nutui/nutui-react-taro'
|
||||||
import {Share} from '@nutui/icons-react-taro'
|
|
||||||
import {View, Text} from '@tarojs/components'
|
import {View, Text} from '@tarojs/components'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import './GoodsList.scss'
|
import './GoodsList.scss'
|
||||||
|
import {ShopGoods} from "@/api/shop/shopGoods/model";
|
||||||
|
|
||||||
|
|
||||||
const GoodsList = (props: any) => {
|
const GoodsList = (props: any) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View className={'py-3'}>
|
<View className={'p-3'}>
|
||||||
<View className={'flex flex-col justify-between items-center rounded-lg px-2'}>
|
|
||||||
{props.data?.map((item: any, index: number) => {
|
<View className="goods-grid">
|
||||||
return (
|
{props.data?.map((item: ShopGoods) => (
|
||||||
<View key={index} className={'flex flex-col rounded-lg bg-white shadow-sm w-full mb-5'}>
|
<View key={item.goodsId} className="goods-card">
|
||||||
<Image src={item.image} mode={'aspectFit'} lazyLoad={false}
|
<View className="goods-card__imgWrap">
|
||||||
radius="10px 10px 0 0" height="180"
|
<Image
|
||||||
onClick={() => Taro.navigateTo({url: '/shop/goodsDetail/index?id=' + item.goodsId})}/>
|
className="goods-card__img"
|
||||||
<View className={'flex flex-col p-2 rounded-lg'}>
|
src={item.image || ''}
|
||||||
<View>
|
mode="aspectFill"
|
||||||
<View className={'car-no text-sm'}>{item.name}</View>
|
width="100%"
|
||||||
<View className={'flex justify-between text-xs py-1'}>
|
height="280rpx"
|
||||||
<Text className={'text-orange-500'}>{item.comments}</Text>
|
radius="18rpx"
|
||||||
<Text className={'text-gray-400'}>已售 {item.sales}</Text>
|
lazyLoad={false}
|
||||||
</View>
|
onClick={() =>
|
||||||
<View className={'flex justify-between items-center py-2'}>
|
Taro.navigateTo({ url: `/shop/goodsDetail/index?id=${item.goodsId}` })
|
||||||
<View className={'flex text-red-500 text-xl items-baseline'}>
|
}
|
||||||
<Text className={'text-xs'}>¥</Text>
|
/>
|
||||||
<Text className={'font-bold text-2xl'}>{item.price}</Text>
|
</View>
|
||||||
<Text className={'text-xs px-1'}>会员价</Text>
|
|
||||||
<Text className={'text-xs text-gray-400 line-through'}>¥{item.salePrice}</Text>
|
<View className="goods-card__body">
|
||||||
</View>
|
<Text className="goods-card__title">{item.name}</Text>
|
||||||
<View className={'buy-btn'}>
|
<View className="goods-card__meta">
|
||||||
<View className={'cart-icon'}>
|
<Text className="goods-card__sold">已购:{item.sales || 0}人</Text>
|
||||||
<Share size={20} className={'mx-4 mt-2'}
|
<View className="goods-card__price">
|
||||||
onClick={() => Taro.navigateTo({url: '/shop/goodsDetail/index?id=' + item.goodsId})}/>
|
<Text className="goods-card__priceUnit">¥</Text>
|
||||||
</View>
|
<Text className="goods-card__priceValue">{item.buyingPrice}</Text>
|
||||||
<View className={'text-white pl-4 pr-5'}
|
</View>
|
||||||
onClick={() => Taro.navigateTo({url: '/shop/goodsDetail/index?id=' + item.goodsId})}>购买
|
</View>
|
||||||
</View>
|
|
||||||
</View>
|
<View className="goods-card__actions">
|
||||||
</View>
|
<View
|
||||||
|
className="goods-card__btn goods-card__btn--primary"
|
||||||
|
onClick={() =>
|
||||||
|
Taro.navigateTo({ url: `/shop/goodsDetail/index?id=${item.goodsId}` })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Text className="goods-card__btnText goods-card__btnText--primary">立即购买</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
</View>
|
||||||
})}
|
))}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import GoodsList from './components/GoodsList'
|
import GoodsList from './components/GoodsList'
|
||||||
import {useShareAppMessage} from "@tarojs/taro"
|
import {useShareAppMessage} from "@tarojs/taro"
|
||||||
import {Loading} from '@nutui/nutui-react-taro'
|
import {Loading,Empty} from '@nutui/nutui-react-taro'
|
||||||
import {useEffect, useState} from "react"
|
import {useEffect, useState} from "react"
|
||||||
import {useRouter} from '@tarojs/taro'
|
import {useRouter} from '@tarojs/taro'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
@@ -21,7 +21,7 @@ function Category() {
|
|||||||
// 1.加载远程数据
|
// 1.加载远程数据
|
||||||
const id = Number(params.id)
|
const id = Number(params.id)
|
||||||
const nav = await getCmsNavigation(id)
|
const nav = await getCmsNavigation(id)
|
||||||
const shopGoods = await pageShopGoods({categoryId: id})
|
const shopGoods = await pageShopGoods({categoryId: id, status: 0})
|
||||||
|
|
||||||
// 2.处理业务逻辑
|
// 2.处理业务逻辑
|
||||||
setCategoryId(id)
|
setCategoryId(id)
|
||||||
@@ -59,6 +59,12 @@ function Category() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(list.length == 0){
|
||||||
|
return (
|
||||||
|
<Empty description="暂无数据"/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={'flex flex-col'}>
|
<div className={'flex flex-col'}>
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import {useCart} from "@/hooks/useCart";
|
|||||||
import {useConfig} from "@/hooks/useConfig";
|
import {useConfig} from "@/hooks/useConfig";
|
||||||
import {parseInviteParams, saveInviteParams, trackInviteSource} from "@/utils/invite";
|
import {parseInviteParams, saveInviteParams, trackInviteSource} from "@/utils/invite";
|
||||||
import { ensureLoggedIn } from '@/utils/auth'
|
import { ensureLoggedIn } from '@/utils/auth'
|
||||||
|
import {getGltTicketTemplateByGoodsId} from "@/api/glt/gltTicketTemplate";
|
||||||
|
import type {GltTicketTemplate} from "@/api/glt/gltTicketTemplate/model";
|
||||||
|
|
||||||
const GoodsDetail = () => {
|
const GoodsDetail = () => {
|
||||||
const [statusBarHeight, setStatusBarHeight] = useState<number>(44);
|
const [statusBarHeight, setStatusBarHeight] = useState<number>(44);
|
||||||
@@ -32,6 +34,9 @@ const GoodsDetail = () => {
|
|||||||
title: '',
|
title: '',
|
||||||
content: ''
|
content: ''
|
||||||
})
|
})
|
||||||
|
// 水票套票模板:存在时该商品不允许加入购物车(购物车无法支付此类商品)
|
||||||
|
const [ticketTemplate, setTicketTemplate] = useState<GltTicketTemplate | null>(null)
|
||||||
|
const [ticketTemplateChecked, setTicketTemplateChecked] = useState(false)
|
||||||
// const [selectedSku, setSelectedSku] = useState<ShopGoodsSku | null>(null);
|
// const [selectedSku, setSelectedSku] = useState<ShopGoodsSku | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const router = Taro.getCurrentInstance().router;
|
const router = Taro.getCurrentInstance().router;
|
||||||
@@ -60,9 +65,29 @@ const GoodsDetail = () => {
|
|||||||
}, [goodsId])
|
}, [goodsId])
|
||||||
|
|
||||||
// 处理加入购物车
|
// 处理加入购物车
|
||||||
const handleAddToCart = () => {
|
const handleAddToCart = async () => {
|
||||||
if (!goods) return;
|
if (!goods) return;
|
||||||
|
|
||||||
|
// 水票套票商品:不允许加入购物车(购物车无法支付)
|
||||||
|
// 优先使用已加载的 ticketTemplate;若尚未加载则补一次查询
|
||||||
|
let tpl = ticketTemplate
|
||||||
|
let checked = ticketTemplateChecked
|
||||||
|
if (!tpl && goods?.goodsId) {
|
||||||
|
try {
|
||||||
|
tpl = await getGltTicketTemplateByGoodsId(Number(goods.goodsId))
|
||||||
|
setTicketTemplate(tpl)
|
||||||
|
setTicketTemplateChecked(true)
|
||||||
|
checked = true
|
||||||
|
} catch (_e) {
|
||||||
|
tpl = null
|
||||||
|
setTicketTemplateChecked(true)
|
||||||
|
checked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!checked || tpl) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!ensureLoggedIn(`/shop/goodsDetail/index?id=${goods.goodsId}`)) return
|
if (!ensureLoggedIn(`/shop/goodsDetail/index?id=${goods.goodsId}`)) return
|
||||||
|
|
||||||
// 如果有规格,显示规格选择器
|
// 如果有规格,显示规格选择器
|
||||||
@@ -99,11 +124,30 @@ const GoodsDetail = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 规格选择确认回调
|
// 规格选择确认回调
|
||||||
const handleSpecConfirm = (sku: ShopGoodsSku, quantity: number, action?: 'cart' | 'buy') => {
|
const handleSpecConfirm = async (sku: ShopGoodsSku, quantity: number, action?: 'cart' | 'buy') => {
|
||||||
// setSelectedSku(sku);
|
// setSelectedSku(sku);
|
||||||
setShowSpecSelector(false);
|
setShowSpecSelector(false);
|
||||||
|
|
||||||
if (action === 'cart') {
|
if (action === 'cart') {
|
||||||
|
// 水票套票商品:不允许加入购物车(购物车无法支付)
|
||||||
|
let tpl = ticketTemplate
|
||||||
|
let checked = ticketTemplateChecked
|
||||||
|
if (!tpl && goods?.goodsId) {
|
||||||
|
try {
|
||||||
|
tpl = await getGltTicketTemplateByGoodsId(Number(goods.goodsId))
|
||||||
|
setTicketTemplate(tpl)
|
||||||
|
setTicketTemplateChecked(true)
|
||||||
|
checked = true
|
||||||
|
} catch (_e) {
|
||||||
|
tpl = null
|
||||||
|
setTicketTemplateChecked(true)
|
||||||
|
checked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!checked || tpl) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 加入购物车
|
// 加入购物车
|
||||||
addToCart({
|
addToCart({
|
||||||
goodsId: goods!.goodsId!,
|
goodsId: goods!.goodsId!,
|
||||||
@@ -143,14 +187,19 @@ const GoodsDetail = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let alive = true
|
||||||
Taro.getSystemInfo({
|
Taro.getSystemInfo({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
if (!alive) return
|
||||||
setWindowWidth(res.windowWidth)
|
setWindowWidth(res.windowWidth)
|
||||||
setStatusBarHeight(Number(res.statusBarHeight) + 5)
|
setStatusBarHeight(Number(res.statusBarHeight) + 5)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (goodsId) {
|
if (goodsId) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
// 切换商品时先重置套票模板,避免复用上一个商品状态
|
||||||
|
setTicketTemplate(null)
|
||||||
|
setTicketTemplateChecked(false)
|
||||||
|
|
||||||
// 加载商品详情
|
// 加载商品详情
|
||||||
getShopGoods(Number(goodsId))
|
getShopGoods(Number(goodsId))
|
||||||
@@ -159,6 +208,7 @@ const GoodsDetail = () => {
|
|||||||
if (res.content) {
|
if (res.content) {
|
||||||
res.content = wxParse(res.content);
|
res.content = wxParse(res.content);
|
||||||
}
|
}
|
||||||
|
if (!alive) return
|
||||||
setGoods(res);
|
setGoods(res);
|
||||||
if (res.files) {
|
if (res.files) {
|
||||||
const arr = JSON.parse(res.files);
|
const arr = JSON.parse(res.files);
|
||||||
@@ -169,12 +219,27 @@ const GoodsDetail = () => {
|
|||||||
console.error("Failed to fetch goods detail:", error);
|
console.error("Failed to fetch goods detail:", error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
if (!alive) return
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 查询商品是否绑定水票模板(失败/无数据时不影响正常浏览)
|
||||||
|
getGltTicketTemplateByGoodsId(Number(goodsId))
|
||||||
|
.then((tpl) => {
|
||||||
|
if (!alive) return
|
||||||
|
setTicketTemplate(tpl)
|
||||||
|
setTicketTemplateChecked(true)
|
||||||
|
})
|
||||||
|
.catch((_e) => {
|
||||||
|
if (!alive) return
|
||||||
|
setTicketTemplate(null)
|
||||||
|
setTicketTemplateChecked(true)
|
||||||
|
})
|
||||||
|
|
||||||
// 加载商品规格
|
// 加载商品规格
|
||||||
listShopGoodsSpec({goodsId: Number(goodsId)} as any)
|
listShopGoodsSpec({goodsId: Number(goodsId)} as any)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
if (!alive) return
|
||||||
setSpecs(data || []);
|
setSpecs(data || []);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -184,12 +249,16 @@ const GoodsDetail = () => {
|
|||||||
// 加载商品SKU
|
// 加载商品SKU
|
||||||
listShopGoodsSku({goodsId: Number(goodsId)} as any)
|
listShopGoodsSku({goodsId: Number(goodsId)} as any)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
if (!alive) return
|
||||||
setSkus(data || []);
|
setSkus(data || []);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Failed to fetch goods skus:", error);
|
console.error("Failed to fetch goods skus:", error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
|
alive = false
|
||||||
|
}
|
||||||
}, [goodsId]);
|
}, [goodsId]);
|
||||||
|
|
||||||
// 分享给好友
|
// 分享给好友
|
||||||
@@ -227,6 +296,8 @@ const GoodsDetail = () => {
|
|||||||
return <View>加载中...</View>;
|
return <View>加载中...</View>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showAddToCart = ticketTemplateChecked && !ticketTemplate
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={"py-0"}>
|
<View className={"py-0"}>
|
||||||
<View
|
<View
|
||||||
@@ -295,9 +366,9 @@ const GoodsDetail = () => {
|
|||||||
<View className={'flex justify-between'}>
|
<View className={'flex justify-between'}>
|
||||||
<View className={'flex text-red-500 text-xl items-baseline'}>
|
<View className={'flex text-red-500 text-xl items-baseline'}>
|
||||||
<Text className={'text-xs'}>¥</Text>
|
<Text className={'text-xs'}>¥</Text>
|
||||||
<Text className={'font-bold text-2xl'}>{goods.price}</Text>
|
<Text className={'font-bold text-2xl'}>{goods.buyingPrice}</Text>
|
||||||
<Text className={'text-xs px-1'}>会员价</Text>
|
<Text className={'text-xs px-1'}>会员价</Text>
|
||||||
<Text className={'text-xs text-gray-400 line-through'}>¥{goods.salePrice}</Text>
|
<Text className={'text-xs text-gray-400 line-through'}>¥{goods.salePrice}/{goods.unitName}</Text>
|
||||||
</View>
|
</View>
|
||||||
<span className={"text-gray-400 text-xs"}>已售 {goods.sales}</span>
|
<span className={"text-gray-400 text-xs"}>已售 {goods.sales}</span>
|
||||||
</View>
|
</View>
|
||||||
@@ -306,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}
|
||||||
@@ -385,10 +467,12 @@ const GoodsDetail = () => {
|
|||||||
</button>
|
</button>
|
||||||
</View>
|
</View>
|
||||||
<View className={'buy-btn mx-4'}>
|
<View className={'buy-btn mx-4'}>
|
||||||
<View className={'cart-add px-4 text-sm'}
|
{showAddToCart && (
|
||||||
onClick={() => handleAddToCart()}>加入购物车
|
<View className={'cart-add px-4 text-sm'}
|
||||||
</View>
|
onClick={() => handleAddToCart()}>加入购物车
|
||||||
<View className={'cart-buy pl-4 pr-5 text-sm'}
|
</View>
|
||||||
|
)}
|
||||||
|
<View className={`cart-buy text-sm ${showAddToCart ? 'pl-4 pr-5' : 'cart-buy-only px-4'}`}
|
||||||
onClick={() => handleBuyNow()}>立即购买
|
onClick={() => handleBuyNow()}>立即购买
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -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,9 +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)
|
||||||
// 配送时间(仅水票套票商品需要)
|
|
||||||
const [sendTime, setSendTime] = useState<Date>(() => dayjs().startOf('day').toDate())
|
|
||||||
const [sendTimePickerVisible, setSendTimePickerVisible] = useState(false)
|
|
||||||
|
|
||||||
// 水票套票活动(若存在则按规则限制最小购买量等)
|
// 水票套票活动(若存在则按规则限制最小购买量等)
|
||||||
const [ticketTemplate, setTicketTemplate] = useState<GltTicketTemplate | null>(null)
|
const [ticketTemplate, setTicketTemplate] = useState<GltTicketTemplate | null>(null)
|
||||||
@@ -80,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 &&
|
||||||
@@ -113,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)
|
||||||
@@ -151,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
|
||||||
|
|
||||||
// 🔍 详细日志,用于排查数值精度问题
|
// 🔍 详细日志,用于排查数值精度问题
|
||||||
@@ -192,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)
|
||||||
@@ -421,6 +468,7 @@ const OrderConfirm = () => {
|
|||||||
* 统一支付入口
|
* 统一支付入口
|
||||||
*/
|
*/
|
||||||
const onPay = async (goods: ShopGoods) => {
|
const onPay = async (goods: ShopGoods) => {
|
||||||
|
let skipFinallyResetPayLoading = false
|
||||||
try {
|
try {
|
||||||
setPayLoading(true)
|
setPayLoading(true)
|
||||||
|
|
||||||
@@ -441,11 +489,7 @@ const OrderConfirm = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 水票套票商品:保存配送时间到 ShopOrder.sendStartTime
|
// 购买水票(囤券预付费)与水票核销(下单履约)为两个独立动作:下单页不再选择配送时间。
|
||||||
if (hasTicketTemplate && !sendTime) {
|
|
||||||
Taro.showToast({ title: '请选择配送时间', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 水票套票活动:最小购买量校验
|
// 水票套票活动:最小购买量校验
|
||||||
if (isTicketTemplateActive && quantity < minBuyQty) {
|
if (isTicketTemplateActive && quantity < minBuyQty) {
|
||||||
@@ -507,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 {
|
||||||
// 用户选择不使用优惠券,继续支付
|
// 用户选择不使用优惠券,继续支付
|
||||||
@@ -535,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
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -574,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({
|
||||||
@@ -583,13 +675,36 @@ const OrderConfirm = () => {
|
|||||||
// })
|
// })
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
const message = String(error?.message || '')
|
const message = String(error?.message || '')
|
||||||
|
const isUserCancelPay =
|
||||||
|
message.includes('用户取消支付') ||
|
||||||
|
message.includes('取消支付') ||
|
||||||
|
message.toLowerCase().includes('requestpayment:fail cancel') ||
|
||||||
|
message.toLowerCase().includes('cancel')
|
||||||
|
|
||||||
|
// 用户取消支付:跳转到待付款列表,方便继续支付
|
||||||
|
if (isUserCancelPay) {
|
||||||
|
skipFinallyResetPayLoading = true
|
||||||
|
setPayLoading(false)
|
||||||
|
const url = '/user/order/order?statusFilter=0'
|
||||||
|
try {
|
||||||
|
await Taro.redirectTo({ url })
|
||||||
|
} catch (_e) {
|
||||||
|
try {
|
||||||
|
await Taro.navigateTo({ url })
|
||||||
|
} catch (_e2) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const isOutOfDeliveryRange =
|
const isOutOfDeliveryRange =
|
||||||
message.includes('不在配送范围') ||
|
message.includes('不在配送范围') ||
|
||||||
message.includes('配送范围') ||
|
message.includes('配送范围') ||
|
||||||
message.includes('电子围栏') ||
|
message.includes('电子围栏') ||
|
||||||
message.includes('围栏')
|
message.includes('围栏')
|
||||||
|
|
||||||
// “配送范围”类错误给出更友好的解释,并提供快捷入口去更换收货地址
|
// "配送范围"类错误给出更友好的解释,并提供快捷入口去更换收货地址
|
||||||
if (isOutOfDeliveryRange) {
|
if (isOutOfDeliveryRange) {
|
||||||
try {
|
try {
|
||||||
const res = await Taro.showModal({
|
const res = await Taro.showModal({
|
||||||
@@ -612,7 +727,9 @@ const OrderConfirm = () => {
|
|||||||
Taro.showToast({ title: message || '支付失败,请重试', icon: 'none' })
|
Taro.showToast({ title: message || '支付失败,请重试', icon: 'none' })
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setPayLoading(false)
|
if (!skipFinallyResetPayLoading) {
|
||||||
|
setPayLoading(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -627,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([
|
||||||
@@ -639,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
|
||||||
}
|
}
|
||||||
@@ -657,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)
|
||||||
@@ -687,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) {
|
||||||
@@ -714,12 +865,9 @@ const OrderConfirm = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 切换商品时重置配送时间,避免沿用上一次选择
|
|
||||||
if (!isLoggedIn()) return
|
if (!isLoggedIn()) return
|
||||||
setSendTime(dayjs().startOf('day').toDate())
|
|
||||||
setSendTimePickerVisible(false)
|
|
||||||
loadAllData()
|
loadAllData()
|
||||||
}, [goodsId]);
|
}, [resolvedGoodsId, orderDataRaw]);
|
||||||
|
|
||||||
// 重新加载数据
|
// 重新加载数据
|
||||||
const handleRetry = () => {
|
const handleRetry = () => {
|
||||||
@@ -745,49 +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={() => setSendTimePickerVisible(true)}
|
<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>
|
||||||
|
<Location/>
|
||||||
|
添加收货地址
|
||||||
|
</Space>
|
||||||
|
</Cell>
|
||||||
|
)}
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -822,19 +971,21 @@ const OrderConfirm = () => {
|
|||||||
</View>
|
</View>
|
||||||
<View className={'flex flex-col w-full ml-2'} style={{width: '100%'}}>
|
<View className={'flex flex-col w-full ml-2'} style={{width: '100%'}}>
|
||||||
<Text className={'font-medium w-full'}>{goods.name}</Text>
|
<Text className={'font-medium w-full'}>{goods.name}</Text>
|
||||||
<Text className={'number text-gray-400 text-sm py-2'}>80g/袋</Text>
|
{/*<Text className={'number text-gray-400 text-sm py-2'}>80g/袋</Text>*/}
|
||||||
<View className={'flex justify-between items-center'}>
|
<View className={'flex justify-between items-center'}>
|
||||||
<Text className={'text-red-500'}>¥{goods.price}</Text>
|
<Text className={'text-red-500'}>¥{goods.price}</Text>
|
||||||
<View className={'flex flex-col items-end gap-1'}>
|
<View className={'flex flex-col items-end gap-1'}>
|
||||||
<ConfigProvider theme={customTheme}>
|
<ConfigProvider theme={customTheme}>
|
||||||
<InputNumber
|
<InputNumber
|
||||||
value={quantity}
|
value={quantity}
|
||||||
min={isTicketTemplateActive ? minBuyQty : 1}
|
min={isTicketTemplateActive ? minBuyQty : 1}
|
||||||
max={goods.stock || 999}
|
max={goods.stock || 999}
|
||||||
disabled={((goods.canBuyNumber ?? 0) !== 0) && !isTicketTemplateActive}
|
step={goods.step || 1}
|
||||||
onChange={handleQuantityChange}
|
readOnly
|
||||||
/>
|
disabled={((goods.canBuyNumber ?? 0) !== 0) && !isTicketTemplateActive}
|
||||||
</ConfigProvider>
|
onChange={handleQuantityChange}
|
||||||
|
/>
|
||||||
|
</ConfigProvider>
|
||||||
{goods.stock !== undefined && (
|
{goods.stock !== undefined && (
|
||||||
<Text className={'text-xs text-gray-400'}>
|
<Text className={'text-xs text-gray-400'}>
|
||||||
库存 {goods.stock} 件
|
库存 {goods.stock} 件
|
||||||
@@ -1083,23 +1234,6 @@ const OrderConfirm = () => {
|
|||||||
|
|
||||||
<Gap height={50}/>
|
<Gap height={50}/>
|
||||||
|
|
||||||
<DatePicker
|
|
||||||
visible={sendTimePickerVisible}
|
|
||||||
title="选择配送时间"
|
|
||||||
type="date"
|
|
||||||
startDate={dayjs().startOf('day').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'}>
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ const OrderConfirm = () => {
|
|||||||
}} lazyLoad={false}/>
|
}} lazyLoad={false}/>
|
||||||
<View className={'flex flex-col'}>
|
<View className={'flex flex-col'}>
|
||||||
<View className={'font-medium w-full'}>{item.name}</View>
|
<View className={'font-medium w-full'}>{item.name}</View>
|
||||||
<View className={'number text-gray-400 text-sm py-2'}>80g/袋</View>
|
{/*<View className={'number text-gray-400 text-sm py-2'}>80g/袋</View>*/}
|
||||||
<Space className={'flex justify-start items-center'}>
|
<Space className={'flex justify-start items-center'}>
|
||||||
<View className={'text-red-500'}>¥{item.price}</View>
|
<View className={'text-red-500'}>¥{item.price}</View>
|
||||||
<View className={'text-gray-500 text-sm'}>x {item.quantity}</View>
|
<View className={'text-gray-500 text-sm'}>x {item.quantity}</View>
|
||||||
|
|||||||
@@ -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'
|
||||||
|
|
||||||
// 申请退款:支付成功后仅允许在指定时间窗内发起(前端展示层限制,后端仍应校验)
|
// 申请退款:支付成功后仅允许在指定时间窗内发起(前端展示层限制,后端仍应校验)
|
||||||
@@ -58,25 +59,39 @@ const OrderDetail = () => {
|
|||||||
const handleApplyRefund = async () => {
|
const handleApplyRefund = async () => {
|
||||||
if (order) {
|
if (order) {
|
||||||
try {
|
try {
|
||||||
// 更新订单状态为"退款申请中"
|
const confirm = await Taro.showModal({
|
||||||
|
title: '申请退款',
|
||||||
|
content: '确认要申请退款吗?',
|
||||||
|
confirmText: '确认',
|
||||||
|
cancelText: '取消'
|
||||||
|
})
|
||||||
|
if (!confirm?.confirm) return
|
||||||
|
|
||||||
|
Taro.showLoading({ title: '提交中...' })
|
||||||
|
|
||||||
|
// 退款相关操作使用退款接口:PUT /api/shop/shop-order/refund
|
||||||
await updateShopOrder({
|
await updateShopOrder({
|
||||||
orderId: order.orderId,
|
orderId: order.orderId,
|
||||||
orderStatus: 4 // 退款申请中
|
refundMoney: order.payPrice || order.totalPrice,
|
||||||
});
|
orderStatus: 7
|
||||||
|
})
|
||||||
|
|
||||||
// 更新本地状态
|
// 乐观更新本地状态
|
||||||
setOrder(prev => prev ? {...prev, orderStatus: 4} : null);
|
setOrder(prev => prev ? { ...prev, orderStatus: 7 } : null)
|
||||||
|
|
||||||
// 跳转到退款申请页面
|
Taro.showToast({ title: '退款申请已提交', icon: 'success' })
|
||||||
Taro.navigateTo({
|
|
||||||
url: `/user/order/refund/index?orderId=${order.orderId}&orderNo=${order.orderNo}`
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('更新订单状态失败:', error);
|
console.error('申请退款失败:', error);
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '操作失败,请重试',
|
title: '操作失败,请重试',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
Taro.hideLoading()
|
||||||
|
} catch (_e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -100,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:
|
||||||
@@ -180,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'}>
|
||||||
@@ -218,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>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {ShopUserAddress} from "@/api/shop/shopUserAddress/model";
|
|||||||
import {getShopUserAddress, listShopUserAddress, updateShopUserAddress, addShopUserAddress} from "@/api/shop/shopUserAddress";
|
import {getShopUserAddress, listShopUserAddress, updateShopUserAddress, addShopUserAddress} from "@/api/shop/shopUserAddress";
|
||||||
import RegionData from '@/api/json/regions-data.json';
|
import RegionData from '@/api/json/regions-data.json';
|
||||||
import FixedButton from "@/components/FixedButton";
|
import FixedButton from "@/components/FixedButton";
|
||||||
|
import { parseLngLatFromText } from "@/utils/geofence";
|
||||||
|
|
||||||
type SelectedLocation = { lng: string; lat: string; name?: string; address?: string }
|
type SelectedLocation = { lng: string; lat: string; name?: string; address?: string }
|
||||||
|
|
||||||
@@ -28,6 +29,15 @@ const isUserCancel = (e: any) => {
|
|||||||
return msg.includes('cancel')
|
return msg.includes('cancel')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasValidLngLat = (addr?: Partial<ShopUserAddress> | null) => {
|
||||||
|
if (!addr) return false
|
||||||
|
const p = parseLngLatFromText(`${(addr as any)?.lng ?? ''},${(addr as any)?.lat ?? ''}`)
|
||||||
|
if (!p) return false
|
||||||
|
// Treat "0,0" as missing in this app (typically used as placeholder by backends).
|
||||||
|
if (p.lng === 0 && p.lat === 0) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const AddUserAddress = () => {
|
const AddUserAddress = () => {
|
||||||
const {params} = useRouter();
|
const {params} = useRouter();
|
||||||
const [loading, setLoading] = useState<boolean>(true)
|
const [loading, setLoading] = useState<boolean>(true)
|
||||||
@@ -37,16 +47,72 @@ const AddUserAddress = () => {
|
|||||||
const [FormData, setFormData] = useState<ShopUserAddress>({})
|
const [FormData, setFormData] = useState<ShopUserAddress>({})
|
||||||
const [inputText, setInputText] = useState<string>('')
|
const [inputText, setInputText] = useState<string>('')
|
||||||
const [selectedLocation, setSelectedLocation] = useState<SelectedLocation | null>(null)
|
const [selectedLocation, setSelectedLocation] = useState<SelectedLocation | null>(null)
|
||||||
|
const [regionLocked, setRegionLocked] = useState(false)
|
||||||
const formRef = useRef<any>(null)
|
const formRef = useRef<any>(null)
|
||||||
|
const wxDraftRef = useRef<Partial<ShopUserAddress> | null>(null)
|
||||||
|
const wxDraftPatchedRef = useRef(false)
|
||||||
|
|
||||||
// 判断是编辑还是新增模式
|
// 判断是编辑还是新增模式
|
||||||
const isEditMode = !!params.id
|
const isEditMode = !!params.id
|
||||||
const addressId = params.id ? Number(params.id) : undefined
|
const addressId = params.id ? Number(params.id) : undefined
|
||||||
|
const fromWx = params.fromWx === '1' || params.fromWx === 'true'
|
||||||
|
const skipDefaultCheck =
|
||||||
|
fromWx || params.skipDefaultCheck === '1' || params.skipDefaultCheck === 'true'
|
||||||
|
|
||||||
const reload = async () => {
|
const reload = async () => {
|
||||||
// 整理地区数据
|
// 整理地区数据
|
||||||
setRegionData()
|
setRegionData()
|
||||||
|
|
||||||
|
// 新增模式:若存在“默认地址”但缺少经纬度,则强制引导到编辑页完善定位
|
||||||
|
// 目的:确保业务依赖默认地址坐标(选店/配送范围)时不会因为缺失坐标而失败
|
||||||
|
if (!isEditMode && !skipDefaultCheck) {
|
||||||
|
try {
|
||||||
|
const defaultList = await listShopUserAddress({ isDefault: true })
|
||||||
|
const defaultAddr = defaultList?.[0]
|
||||||
|
if (defaultAddr && !hasValidLngLat(defaultAddr)) {
|
||||||
|
await Taro.showModal({
|
||||||
|
title: '需要完善定位',
|
||||||
|
content: '默认收货地址缺少定位信息,请先进入编辑页面选择定位并保存后再继续。',
|
||||||
|
confirmText: '去完善',
|
||||||
|
showCancel: false
|
||||||
|
})
|
||||||
|
if (defaultAddr.id) {
|
||||||
|
Taro.navigateTo({ url: `/user/address/add?id=${defaultAddr.id}` })
|
||||||
|
} else {
|
||||||
|
Taro.navigateTo({ url: '/user/address/index' })
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// ignore: 新增页不阻塞渲染
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信地址导入:先用微信返回的字段预填表单,让用户手动选择定位后再保存
|
||||||
|
if (!isEditMode && fromWx && !wxDraftPatchedRef.current) {
|
||||||
|
try {
|
||||||
|
const draft = Taro.getStorageSync('WxAddressDraft')
|
||||||
|
if (draft) {
|
||||||
|
wxDraftPatchedRef.current = true
|
||||||
|
wxDraftRef.current = draft as any
|
||||||
|
Taro.removeStorageSync('WxAddressDraft')
|
||||||
|
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
...(draft as any)
|
||||||
|
}))
|
||||||
|
|
||||||
|
const p = String((draft as any)?.province || '').trim()
|
||||||
|
const c = String((draft as any)?.city || '').trim()
|
||||||
|
const r = String((draft as any)?.region || '').trim()
|
||||||
|
const regionText = [p, c, r].filter(Boolean).join(' ')
|
||||||
|
if (regionText) setText(regionText)
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是编辑模式,加载地址数据
|
// 如果是编辑模式,加载地址数据
|
||||||
if (isEditMode && addressId) {
|
if (isEditMode && addressId) {
|
||||||
try {
|
try {
|
||||||
@@ -55,8 +121,11 @@ const AddUserAddress = () => {
|
|||||||
// 设置所在地区
|
// 设置所在地区
|
||||||
setText(`${address.province} ${address.city} ${address.region}`)
|
setText(`${address.province} ${address.city} ${address.region}`)
|
||||||
// 回显已保存的经纬度(编辑模式)
|
// 回显已保存的经纬度(编辑模式)
|
||||||
if (address?.lng && address?.lat) {
|
if (hasValidLngLat(address)) {
|
||||||
setSelectedLocation({ lng: String(address.lng), lat: String(address.lat) })
|
setSelectedLocation({ lng: String(address.lng), lat: String(address.lat) })
|
||||||
|
setRegionLocked(true)
|
||||||
|
} else {
|
||||||
|
setRegionLocked(false)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载地址失败:', error)
|
console.error('加载地址失败:', error)
|
||||||
@@ -109,30 +178,39 @@ const AddUserAddress = () => {
|
|||||||
const result = parseAddressText(inputText);
|
const result = parseAddressText(inputText);
|
||||||
|
|
||||||
// 更新表单数据
|
// 更新表单数据
|
||||||
const newFormData = {
|
const newFormData: any = {
|
||||||
...FormData,
|
...FormData,
|
||||||
name: result.name || FormData.name,
|
name: result.name || FormData.name,
|
||||||
phone: result.phone || FormData.phone,
|
phone: result.phone || FormData.phone,
|
||||||
address: result.address || FormData.address,
|
address: result.address || FormData.address
|
||||||
province: result.province || FormData.province,
|
|
||||||
city: result.city || FormData.city,
|
|
||||||
region: result.region || FormData.region
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!regionLocked) {
|
||||||
|
newFormData.province = result.province || FormData.province
|
||||||
|
newFormData.city = result.city || FormData.city
|
||||||
|
newFormData.region = result.region || FormData.region
|
||||||
|
}
|
||||||
|
|
||||||
setFormData(newFormData);
|
setFormData(newFormData);
|
||||||
|
|
||||||
// 更新地区显示文本
|
// 更新地区显示文本
|
||||||
if (result.province && result.city && result.region) {
|
if (!regionLocked && result.province && result.city && result.region) {
|
||||||
setText(`${result.province} ${result.city} ${result.region}`);
|
setText(`${result.province} ${result.city} ${result.region}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新表单字段值
|
// 更新表单字段值
|
||||||
if (formRef.current) {
|
if (formRef.current) {
|
||||||
formRef.current.setFieldsValue(newFormData);
|
const patch: any = {
|
||||||
|
name: newFormData.name,
|
||||||
|
phone: newFormData.phone,
|
||||||
|
address: newFormData.address
|
||||||
|
}
|
||||||
|
if (!regionLocked && newFormData.region) patch.region = newFormData.region
|
||||||
|
formRef.current.setFieldsValue(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '识别成功',
|
title: regionLocked ? '识别成功(所在地区以定位为准)' : '识别成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -248,7 +326,6 @@ const AddUserAddress = () => {
|
|||||||
name: res.name,
|
name: res.name,
|
||||||
address: res.address
|
address: res.address
|
||||||
}
|
}
|
||||||
setSelectedLocation(next)
|
|
||||||
|
|
||||||
// 尝试从地图返回的 address 文本解析省市区(best-effort)
|
// 尝试从地图返回的 address 文本解析省市区(best-effort)
|
||||||
const regionResult = res?.provinceName || res?.cityName || res?.adName
|
const regionResult = res?.provinceName || res?.cityName || res?.adName
|
||||||
@@ -259,15 +336,22 @@ const AddUserAddress = () => {
|
|||||||
}
|
}
|
||||||
: parseRegion(String(res.address || ''))
|
: parseRegion(String(res.address || ''))
|
||||||
|
|
||||||
|
const province = String(regionResult?.province || '').trim()
|
||||||
|
const city = String(regionResult?.city || '').trim()
|
||||||
|
const region = String(regionResult?.region || '').trim()
|
||||||
|
if (!province || !city || !region) {
|
||||||
|
Taro.showToast({ title: '定位未识别到所在地区,请重新选择定位', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedLocation(next)
|
||||||
|
setRegionLocked(true)
|
||||||
|
|
||||||
// 将地图选点的地址同步到“收货地址”(不额外拼接省市区字段,省市区由独立字段保存)
|
// 将地图选点的地址同步到“收货地址”(不额外拼接省市区字段,省市区由独立字段保存)
|
||||||
const nextDetailAddress = (() => {
|
const nextDetailAddress = (() => {
|
||||||
const rawAddr = String(res.address || '').trim()
|
const rawAddr = String(res.address || '').trim()
|
||||||
const name = String(res.name || '').trim()
|
const name = String(res.name || '').trim()
|
||||||
|
|
||||||
const province = String(regionResult?.province || '').trim()
|
|
||||||
const city = String(regionResult?.city || '').trim()
|
|
||||||
const region = String(regionResult?.region || '').trim()
|
|
||||||
|
|
||||||
// 选择定位返回的 address 往往包含省市区,这里尽量剥离掉,避免和表单的省市区字段重复
|
// 选择定位返回的 address 往往包含省市区,这里尽量剥离掉,避免和表单的省市区字段重复
|
||||||
let detail = rawAddr
|
let detail = rawAddr
|
||||||
for (const part of [province, city, region]) {
|
for (const part of [province, city, region]) {
|
||||||
@@ -287,20 +371,18 @@ const AddUserAddress = () => {
|
|||||||
lng: next.lng,
|
lng: next.lng,
|
||||||
lat: next.lat,
|
lat: next.lat,
|
||||||
address: nextDetailAddress || prev.address,
|
address: nextDetailAddress || prev.address,
|
||||||
province: regionResult?.province || prev.province,
|
province,
|
||||||
city: regionResult?.city || prev.city,
|
city,
|
||||||
region: regionResult?.region || prev.region
|
region
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (regionResult?.province && regionResult?.city && regionResult?.region) {
|
setText(`${province} ${city} ${region}`)
|
||||||
setText(`${regionResult.province} ${regionResult.city} ${regionResult.region}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新表单展示值(Form initialValues 不会跟随 FormData 变化)
|
// 更新表单展示值(Form initialValues 不会跟随 FormData 变化)
|
||||||
if (formRef.current) {
|
if (formRef.current) {
|
||||||
const patch: any = {}
|
const patch: any = {}
|
||||||
if (nextDetailAddress) patch.address = nextDetailAddress
|
if (nextDetailAddress) patch.address = nextDetailAddress
|
||||||
if (regionResult?.region) patch.region = regionResult.region
|
patch.region = region
|
||||||
formRef.current.setFieldsValue(patch)
|
formRef.current.setFieldsValue(patch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,20 +426,33 @@ const AddUserAddress = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openRegionPicker = () => {
|
||||||
|
if (regionLocked) {
|
||||||
|
Taro.showToast({ title: '所在地区已由定位确定,修改请重新选择定位', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setVisible(true)
|
||||||
|
}
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const submitSucceed = async (values: any) => {
|
const submitSucceed = async (values: any) => {
|
||||||
const loc =
|
const loc =
|
||||||
selectedLocation ||
|
selectedLocation ||
|
||||||
(FormData?.lng && FormData?.lat ? { lng: String(FormData.lng), lat: String(FormData.lat) } : null)
|
(hasValidLngLat(FormData) ? { lng: String(FormData.lng), lat: String(FormData.lat) } : null)
|
||||||
if (!loc) {
|
if (!loc) {
|
||||||
Taro.showToast({ title: '请选择定位', icon: 'none' })
|
Taro.showToast({ title: '请选择定位', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!FormData.province || !FormData.city || !FormData.region) {
|
||||||
|
Taro.showToast({ title: '请先选择定位以自动填写所在地区', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 准备提交的数据
|
// 准备提交的数据
|
||||||
const submitData = {
|
const submitData = {
|
||||||
...values,
|
...values,
|
||||||
|
country: FormData.country,
|
||||||
province: FormData.province,
|
province: FormData.province,
|
||||||
city: FormData.city,
|
city: FormData.city,
|
||||||
region: FormData.region,
|
region: FormData.region,
|
||||||
@@ -415,13 +510,40 @@ const AddUserAddress = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 动态设置页面标题
|
// 动态设置页面标题
|
||||||
Taro.setNavigationBarTitle({
|
Taro.setNavigationBarTitle({
|
||||||
title: isEditMode ? '编辑收货地址' : '新增收货地址'
|
title: isEditMode ? '编辑收货地址' : (fromWx ? '完善收货地址' : '新增收货地址')
|
||||||
});
|
});
|
||||||
|
|
||||||
reload().then(() => {
|
reload().then(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
}, [isEditMode]);
|
}, [fromWx, isEditMode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!regionLocked) return
|
||||||
|
if (!visible) return
|
||||||
|
setVisible(false)
|
||||||
|
}, [regionLocked, visible])
|
||||||
|
|
||||||
|
// NutUI Form 的 initialValues 在首次渲染后不再响应更新;微信导入时做一次 setFieldsValue 兜底回填。
|
||||||
|
useEffect(() => {
|
||||||
|
if (loading) return
|
||||||
|
if (isEditMode) return
|
||||||
|
const draft = wxDraftRef.current
|
||||||
|
if (!draft) return
|
||||||
|
if (!formRef.current?.setFieldsValue) return
|
||||||
|
try {
|
||||||
|
formRef.current.setFieldsValue({
|
||||||
|
name: (draft as any)?.name,
|
||||||
|
phone: (draft as any)?.phone,
|
||||||
|
address: (draft as any)?.address,
|
||||||
|
region: (draft as any)?.region
|
||||||
|
})
|
||||||
|
} catch (_e) {
|
||||||
|
// ignore
|
||||||
|
} finally {
|
||||||
|
wxDraftRef.current = null
|
||||||
|
}
|
||||||
|
}, [fromWx, isEditMode, loading])
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Loading className={'px-2'}>加载中</Loading>
|
return <Loading className={'px-2'}>加载中</Loading>
|
||||||
@@ -438,7 +560,7 @@ const AddUserAddress = () => {
|
|||||||
onFinishFailed={(errors) => submitFailed(errors)}
|
onFinishFailed={(errors) => submitFailed(errors)}
|
||||||
>
|
>
|
||||||
<CellGroup className={'px-3'}>
|
<CellGroup className={'px-3'}>
|
||||||
<div
|
<View
|
||||||
style={{
|
style={{
|
||||||
border: '1px dashed #22c55e',
|
border: '1px dashed #22c55e',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -464,7 +586,7 @@ const AddUserAddress = () => {
|
|||||||
>
|
>
|
||||||
识别
|
识别
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</View>
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
<View className={'bg-gray-100 h-3'}></View>
|
<View className={'bg-gray-100 h-3'}></View>
|
||||||
<CellGroup style={{padding: '4px 0'}}>
|
<CellGroup style={{padding: '4px 0'}}>
|
||||||
@@ -496,30 +618,32 @@ const AddUserAddress = () => {
|
|||||||
rules={[{message: '请输入您的所在地区'}]}
|
rules={[{message: '请输入您的所在地区'}]}
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<div className={'flex justify-between items-center'} onClick={() => setVisible(true)}>
|
<View className={'flex justify-between items-center'} onClick={openRegionPicker}>
|
||||||
<Input placeholder="选择所在地区" value={text} disabled/>
|
<Input placeholder="选择所在地区" value={text} disabled/>
|
||||||
<ArrowRight className={'text-gray-400'}/>
|
<ArrowRight className={'text-gray-400'}/>
|
||||||
</div>
|
</View>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="address" label="收货地址" initialValue={FormData.address} required>
|
<Form.Item name="address" label="收货地址" initialValue={FormData.address} required>
|
||||||
<TextArea maxLength={50} placeholder="请输入详细收货地址"/>
|
<TextArea maxLength={50} placeholder="请输入详细收货地址"/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
</CellGroup>
|
||||||
|
<CellGroup>
|
||||||
<Cell
|
<Cell
|
||||||
title="选择定位"
|
title="选择定位"
|
||||||
description={
|
description={
|
||||||
selectedLocation?.address ||
|
selectedLocation?.address ||
|
||||||
(selectedLocation ? `经纬度:${selectedLocation.lng}, ${selectedLocation.lat}` : '')
|
(selectedLocation ? `经纬度:${selectedLocation.lng}, ${selectedLocation.lat}` : '用于计算是否超出配送范围')
|
||||||
}
|
}
|
||||||
extra={(
|
extra={(
|
||||||
<div className={'flex items-center gap-2'}>
|
<View className={'flex items-center gap-2'}>
|
||||||
<div
|
<View
|
||||||
className={'text-gray-900 text-sm'}
|
className={'text-gray-900 text-sm'}
|
||||||
style={{maxWidth: '200px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap'}}
|
style={{maxWidth: '200px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap'}}
|
||||||
>
|
>
|
||||||
{selectedLocation?.name || (selectedLocation ? '已选择' : '请选择')}
|
{selectedLocation?.name || (selectedLocation ? '已选择' : '请选择')}
|
||||||
</div>
|
</View>
|
||||||
<ArrowRight className={'text-gray-400'}/>
|
<ArrowRight className={'text-gray-400'}/>
|
||||||
</div>
|
</View>
|
||||||
)}
|
)}
|
||||||
onClick={chooseGeoLocation}
|
onClick={chooseGeoLocation}
|
||||||
/>
|
/>
|
||||||
@@ -531,6 +655,10 @@ const AddUserAddress = () => {
|
|||||||
options={optionsDemo1}
|
options={optionsDemo1}
|
||||||
title="选择地址"
|
title="选择地址"
|
||||||
onChange={(value, _) => {
|
onChange={(value, _) => {
|
||||||
|
if (regionLocked) {
|
||||||
|
Taro.showToast({ title: '所在地区已由定位确定,修改请重新选择定位', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
setFormData({
|
setFormData({
|
||||||
...FormData,
|
...FormData,
|
||||||
province: `${value[0]}`,
|
province: `${value[0]}`,
|
||||||
|
|||||||
@@ -1,18 +1,30 @@
|
|||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
import Taro, {useDidShow} from '@tarojs/taro'
|
import Taro, {useDidShow} from '@tarojs/taro'
|
||||||
import {Button, Cell, CellGroup, Space, Empty, ConfigProvider, Divider} from '@nutui/nutui-react-taro'
|
import {Button, Cell, Space, Empty, ConfigProvider, Divider} from '@nutui/nutui-react-taro'
|
||||||
import {Dongdong, ArrowRight, CheckNormal, Checked} from '@nutui/icons-react-taro'
|
import {CheckNormal, Checked} from '@nutui/icons-react-taro'
|
||||||
import {View} from '@tarojs/components'
|
import {View} from '@tarojs/components'
|
||||||
import {ShopUserAddress} from "@/api/shop/shopUserAddress/model";
|
import {ShopUserAddress} from "@/api/shop/shopUserAddress/model";
|
||||||
import {listShopUserAddress, removeShopUserAddress, updateShopUserAddress} from "@/api/shop/shopUserAddress";
|
import {listShopUserAddress, removeShopUserAddress, updateShopUserAddress} from "@/api/shop/shopUserAddress";
|
||||||
import FixedButton from "@/components/FixedButton";
|
import FixedButton from "@/components/FixedButton";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { getCurrentLngLat } from "@/utils/location";
|
|
||||||
|
|
||||||
const Address = () => {
|
const Address = () => {
|
||||||
const [list, setList] = useState<ShopUserAddress[]>([])
|
const [list, setList] = useState<ShopUserAddress[]>([])
|
||||||
const [address, setAddress] = useState<ShopUserAddress>()
|
const [address, setAddress] = useState<ShopUserAddress>()
|
||||||
|
|
||||||
|
const safeNavigateBack = async () => {
|
||||||
|
try {
|
||||||
|
const pages = (Taro as any).getCurrentPages?.() || []
|
||||||
|
if (Array.isArray(pages) && pages.length > 1) {
|
||||||
|
await Taro.navigateBack()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
const parseTime = (raw?: unknown) => {
|
const parseTime = (raw?: unknown) => {
|
||||||
if (raw === undefined || raw === null || raw === '') return null;
|
if (raw === undefined || raw === null || raw === '') return null;
|
||||||
// 兼容秒/毫秒时间戳
|
// 兼容秒/毫秒时间戳
|
||||||
@@ -59,8 +71,7 @@ const Address = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onDefault = async (item: ShopUserAddress) => {
|
const onDefault = async (item: ShopUserAddress) => {
|
||||||
const loc = await getCurrentLngLat()
|
if (item.isDefault) return
|
||||||
if (!loc) return
|
|
||||||
|
|
||||||
if (address) {
|
if (address) {
|
||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
@@ -71,14 +82,16 @@ const Address = () => {
|
|||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
...item,
|
...item,
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
lng: loc.lng,
|
|
||||||
lat: loc.lat,
|
|
||||||
})
|
})
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '设置成功',
|
title: '设置成功',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
});
|
});
|
||||||
reload();
|
// 设置默认地址通常是“选择地址”的动作:成功后返回上一页,体验更顺滑
|
||||||
|
setTimeout(async () => {
|
||||||
|
const backed = await safeNavigateBack()
|
||||||
|
if (!backed) reload()
|
||||||
|
}, 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDel = async (id?: number) => {
|
const onDel = async (id?: number) => {
|
||||||
@@ -91,8 +104,11 @@ const Address = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selectAddress = async (item: ShopUserAddress) => {
|
const selectAddress = async (item: ShopUserAddress) => {
|
||||||
const loc = await getCurrentLngLat()
|
if (item.isDefault) {
|
||||||
if (!loc) return
|
const backed = await safeNavigateBack()
|
||||||
|
if (!backed) reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (address) {
|
if (address) {
|
||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
@@ -103,11 +119,10 @@ const Address = () => {
|
|||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
...item,
|
...item,
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
lng: loc.lng,
|
|
||||||
lat: loc.lat,
|
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
Taro.navigateBack()
|
const backed = await safeNavigateBack()
|
||||||
|
if (!backed) reload()
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,8 +144,8 @@ const Address = () => {
|
|||||||
/>
|
/>
|
||||||
<Space>
|
<Space>
|
||||||
<Button onClick={() => Taro.navigateTo({url: '/user/address/add'})}>新增地址</Button>
|
<Button onClick={() => Taro.navigateTo({url: '/user/address/add'})}>新增地址</Button>
|
||||||
<Button type="success" fill="dashed"
|
{/*<Button type="success" fill="dashed"*/}
|
||||||
onClick={() => Taro.navigateTo({url: '/user/address/wxAddress'})}>获取微信地址</Button>
|
{/* onClick={() => Taro.navigateTo({url: '/user/address/wxAddress'})}>获取微信地址</Button>*/}
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
@@ -139,19 +154,19 @@ const Address = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CellGroup>
|
{/*<CellGroup>*/}
|
||||||
<Cell
|
{/* <Cell*/}
|
||||||
onClick={() => Taro.navigateTo({url: '/user/address/wxAddress'})}
|
{/* onClick={() => Taro.navigateTo({url: '/user/address/wxAddress'})}*/}
|
||||||
>
|
{/* >*/}
|
||||||
<div className={'flex justify-between items-center w-full'}>
|
{/* <div className={'flex justify-between items-center w-full'}>*/}
|
||||||
<div className={'flex items-center gap-3'}>
|
{/* <div className={'flex items-center gap-3'}>*/}
|
||||||
<Dongdong className={'text-green-600'}/>
|
{/* <Dongdong className={'text-green-600'}/>*/}
|
||||||
<div>获取微信地址</div>
|
{/* <div>获取微信地址</div>*/}
|
||||||
</div>
|
{/* </div>*/}
|
||||||
<ArrowRight className={'text-gray-400'}/>
|
{/* <ArrowRight className={'text-gray-400'}/>*/}
|
||||||
</div>
|
{/* </div>*/}
|
||||||
</Cell>
|
{/* </Cell>*/}
|
||||||
</CellGroup>
|
{/*</CellGroup>*/}
|
||||||
{list.map((item, _) => (
|
{list.map((item, _) => (
|
||||||
<Cell.Group>
|
<Cell.Group>
|
||||||
<Cell className={'flex flex-col gap-1'} onClick={() => selectAddress(item)}>
|
<Cell className={'flex flex-col gap-1'} onClick={() => selectAddress(item)}>
|
||||||
|
|||||||
@@ -1,25 +1,17 @@
|
|||||||
import {useEffect} from "react";
|
import {useEffect} from "react";
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import {addShopUserAddress} from "@/api/shop/shopUserAddress";
|
|
||||||
import { getCurrentLngLat } from "@/utils/location";
|
|
||||||
|
|
||||||
const WxAddress = () => {
|
const WxAddress = () => {
|
||||||
/**
|
/**
|
||||||
* 从微信API获取用户收货地址
|
* 从微信API获取用户收货地址
|
||||||
* 调用微信原生地址选择界面,获取成功后保存到服务器并刷新列表
|
* 调用微信原生地址选择界面,获取成功后跳转到“新增收货地址”页面,让用户选择定位后再保存
|
||||||
*/
|
*/
|
||||||
const getWeChatAddress = () => {
|
const getWeChatAddress = () => {
|
||||||
Taro.chooseAddress()
|
Taro.chooseAddress()
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
const loc = await getCurrentLngLat()
|
// 仅填充微信地址信息,不要用“当前定位”覆盖经纬度(会造成经纬度与地址不匹配)。
|
||||||
if (!loc) {
|
// 选择后跳转到“新增/编辑收货地址”页面,让用户手动选择地图定位后再保存。
|
||||||
// Avoid leaving the user on an empty page.
|
const addressDraft = {
|
||||||
setTimeout(() => Taro.navigateBack(), 300)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化微信返回的地址数据为后端所需格式
|
|
||||||
const addressData = {
|
|
||||||
name: res.userName,
|
name: res.userName,
|
||||||
phone: res.telNumber,
|
phone: res.telNumber,
|
||||||
country: res.nationalCode || '中国',
|
country: res.nationalCode || '中国',
|
||||||
@@ -27,40 +19,32 @@ const WxAddress = () => {
|
|||||||
city: res.cityName,
|
city: res.cityName,
|
||||||
region: res.countyName,
|
region: res.countyName,
|
||||||
address: res.detailInfo,
|
address: res.detailInfo,
|
||||||
postalCode: res.postalCode,
|
isDefault: false,
|
||||||
lng: loc.lng,
|
|
||||||
lat: loc.lat,
|
|
||||||
isDefault: false
|
|
||||||
}
|
}
|
||||||
console.log(res, 'addrs..')
|
Taro.setStorageSync('WxAddressDraft', addressDraft)
|
||||||
// 调用保存地址的API(假设存在该接口)
|
// 用 redirectTo 替换当前页面,避免保存后 navigateBack 回到空白的 wxAddress 页面。
|
||||||
addShopUserAddress(addressData)
|
await Taro.redirectTo({ url: '/user/address/add?fromWx=1&skipDefaultCheck=1' })
|
||||||
.then((msg) => {
|
|
||||||
console.log(msg)
|
|
||||||
Taro.showToast({
|
|
||||||
title: `${msg}`,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
|
||||||
// 保存成功后返回
|
|
||||||
Taro.navigateBack()
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('保存地址失败:', error)
|
|
||||||
Taro.showToast({title: '保存地址失败', icon: 'error'})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('获取微信地址失败:', err)
|
console.error('获取微信地址失败:', err)
|
||||||
|
// 用户取消选择地址:直接返回上一页
|
||||||
|
if (String(err?.errMsg || '').includes('cancel')) {
|
||||||
|
setTimeout(() => Taro.navigateBack(), 200)
|
||||||
|
return
|
||||||
|
}
|
||||||
// 处理用户拒绝授权的情况
|
// 处理用户拒绝授权的情况
|
||||||
if (err.errMsg.includes('auth deny')) {
|
if (String(err?.errMsg || '').includes('auth deny')) {
|
||||||
Taro.showModal({
|
Taro.showModal({
|
||||||
title: '授权失败',
|
title: '授权失败',
|
||||||
content: '请在设置中允许获取地址权限',
|
content: '请在设置中允许获取地址权限',
|
||||||
showCancel: false
|
showCancel: false
|
||||||
})
|
})
|
||||||
|
setTimeout(() => Taro.navigateBack(), 300)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Taro.showToast({ title: '获取微信地址失败', icon: 'none' })
|
||||||
|
setTimeout(() => Taro.navigateBack(), 300)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 => {
|
||||||
@@ -104,6 +105,10 @@ interface OrderListProps {
|
|||||||
baseParams?: ShopOrderParam;
|
baseParams?: ShopOrderParam;
|
||||||
// 只读模式:隐藏“支付/取消/确认收货/退款”等用户操作按钮
|
// 只读模式:隐藏“支付/取消/确认收货/退款”等用户操作按钮
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
|
// 是否自动取消“支付已过期”的待支付订单(仅 user 模式生效)
|
||||||
|
autoCancelExpired?: boolean;
|
||||||
|
// 支付超时时间(小时),默认 24 小时
|
||||||
|
paymentTimeoutHours?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function OrderList(props: OrderListProps) {
|
function OrderList(props: OrderListProps) {
|
||||||
@@ -111,6 +116,8 @@ function OrderList(props: OrderListProps) {
|
|||||||
const pageRef = useRef(1)
|
const pageRef = useRef(1)
|
||||||
const [hasMore, setHasMore] = useState(true)
|
const [hasMore, setHasMore] = useState(true)
|
||||||
const [payingOrderId, setPayingOrderId] = useState<number | null>(null)
|
const [payingOrderId, setPayingOrderId] = useState<number | null>(null)
|
||||||
|
const autoCanceledOrderIdsRef = useRef<Set<number>>(new Set())
|
||||||
|
const autoCancelRunningRef = useRef(false)
|
||||||
// 根据传入的statusFilter设置初始tab索引
|
// 根据传入的statusFilter设置初始tab索引
|
||||||
const getInitialTabIndex = () => {
|
const getInitialTabIndex = () => {
|
||||||
if (props.searchParams?.statusFilter !== undefined) {
|
if (props.searchParams?.statusFilter !== undefined) {
|
||||||
@@ -132,68 +139,39 @@ function OrderList(props: OrderListProps) {
|
|||||||
const [orderToConfirmReceive, setOrderToConfirmReceive] = useState<ShopOrder | null>(null)
|
const [orderToConfirmReceive, setOrderToConfirmReceive] = useState<ShopOrder | null>(null)
|
||||||
const isReadOnly = props.readOnly || props.mode === 'store' || props.mode === 'rider'
|
const isReadOnly = props.readOnly || props.mode === 'store' || props.mode === 'rider'
|
||||||
|
|
||||||
// 获取订单状态文本
|
const toNum = (v: any): number | undefined => {
|
||||||
const getOrderStatusText = (order: ShopOrder) => {
|
if (v === null || v === undefined || v === '') return undefined;
|
||||||
|
const n = Number(v);
|
||||||
// 优先检查订单状态
|
return Number.isFinite(n) ? n : undefined;
|
||||||
if (order.orderStatus === 2) return '已取消';
|
|
||||||
if (order.orderStatus === 4) return '退款申请中';
|
|
||||||
if (order.orderStatus === 5) return '退款被拒绝';
|
|
||||||
if (order.orderStatus === 6) return '退款成功';
|
|
||||||
if (order.orderStatus === 7) return '客户端申请退款';
|
|
||||||
|
|
||||||
// 检查支付状态 (payStatus为boolean类型,false/0表示未付款,true/1表示已付款)
|
|
||||||
if (!order.payStatus) return '等待买家付款';
|
|
||||||
|
|
||||||
// 已付款后检查发货状态
|
|
||||||
if (order.deliveryStatus === 10) return '待发货';
|
|
||||||
if (order.formId === 10074) return '已完成';
|
|
||||||
if (order.deliveryStatus === 20) {
|
|
||||||
// 若订单没有配送员,沿用原“待收货”语义
|
|
||||||
if (!order.riderId) return '待收货';
|
|
||||||
// 配送员确认送达后(sendEndTime有值),才进入“待确认收货”
|
|
||||||
if (order.sendEndTime && order.orderStatus !== 1) return '待确认收货';
|
|
||||||
return '配送中';
|
|
||||||
}
|
|
||||||
if (order.deliveryStatus === 30) return '部分发货';
|
|
||||||
|
|
||||||
// 最后检查订单完成状态
|
|
||||||
if (order.orderStatus === 1) return '已完成';
|
|
||||||
if (order.orderStatus === 0) return '未使用';
|
|
||||||
|
|
||||||
return '未知状态';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const isOrderCompleted = (order: ShopOrder) => order.orderStatus === 1 || order.formId === 10074;
|
const parseTime = (raw: any): dayjs.Dayjs | null => {
|
||||||
|
const text = String(raw ?? '').trim();
|
||||||
// 获取订单状态颜色
|
if (!text) return null;
|
||||||
const getOrderStatusColor = (order: ShopOrder) => {
|
const t = /^\d+$/.test(text)
|
||||||
// 优先检查订单状态
|
? dayjs(Number(text) < 1e12 ? Number(text) * 1000 : Number(text))
|
||||||
if (order.orderStatus === 2) return 'text-gray-500'; // 已取消
|
: dayjs(text);
|
||||||
if (order.orderStatus === 4) return 'text-orange-500'; // 退款申请中
|
return t.isValid() ? t : null;
|
||||||
if (order.orderStatus === 5) return 'text-red-500'; // 退款被拒绝
|
|
||||||
if (order.orderStatus === 6) return 'text-green-500'; // 退款成功
|
|
||||||
if (order.orderStatus === 7) return 'text-orange-500'; // 客户端申请退款
|
|
||||||
|
|
||||||
// 检查支付状态
|
|
||||||
if (!order.payStatus) return 'text-orange-500'; // 等待买家付款
|
|
||||||
|
|
||||||
// 已付款后检查发货状态
|
|
||||||
if (order.deliveryStatus === 10) return 'text-blue-500'; // 待发货
|
|
||||||
if (order.deliveryStatus === 20) {
|
|
||||||
if (!order.riderId) return 'text-purple-500'; // 待收货
|
|
||||||
if (order.sendEndTime && order.orderStatus !== 1) return 'text-purple-500'; // 待确认收货
|
|
||||||
return 'text-blue-500'; // 配送中
|
|
||||||
}
|
|
||||||
if (order.deliveryStatus === 30) return 'text-blue-500'; // 部分发货
|
|
||||||
|
|
||||||
// 最后检查订单完成状态
|
|
||||||
if (order.orderStatus === 1) return 'text-green-600'; // 已完成
|
|
||||||
if (order.orderStatus === 0) return 'text-gray-500'; // 未使用
|
|
||||||
|
|
||||||
return 'text-gray-600'; // 默认颜色
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isOrderPaymentExpiredSafe = (order: ShopOrder, timeoutHours: number) => {
|
||||||
|
if (order.payStatus) return false;
|
||||||
|
if (toNum(order.orderStatus) === 2) return false;
|
||||||
|
|
||||||
|
const expiration = parseTime(order.expirationTime);
|
||||||
|
if (expiration) return dayjs().isAfter(expiration);
|
||||||
|
|
||||||
|
if (order.createTime) return isPaymentExpired(order.createTime, timeoutHours);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// “已完成”应以订单状态为准;不要用商品ID等字段推断完成态,否则会造成 Tab(待发货/待收货) 与状态文案不同步
|
||||||
|
const isOrderCompleted = (order: ShopOrder) => isShopOrderCompleted(order);
|
||||||
|
|
||||||
|
const getOrderStatusText = (order: ShopOrder) => getShopOrderStatusText(order);
|
||||||
|
|
||||||
|
const getOrderStatusColor = (order: ShopOrder) => getShopOrderStatusColor(order);
|
||||||
|
|
||||||
// 使用后端统一的 statusFilter 进行筛选
|
// 使用后端统一的 statusFilter 进行筛选
|
||||||
const getOrderStatusParams = (index: string | number) => {
|
const getOrderStatusParams = (index: string | number) => {
|
||||||
let params: ShopOrderParam = {
|
let params: ShopOrderParam = {
|
||||||
@@ -240,24 +218,82 @@ function OrderList(props: OrderListProps) {
|
|||||||
finalStatusFilter: searchConditions.statusFilter
|
finalStatusFilter: searchConditions.statusFilter
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await pageShopOrder(searchConditions);
|
const timeoutHours = typeof props.paymentTimeoutHours === 'number' ? props.paymentTimeoutHours : 24;
|
||||||
|
const canAutoCancelExpired =
|
||||||
|
!!props.autoCancelExpired &&
|
||||||
|
(!props.mode || props.mode === 'user') &&
|
||||||
|
!props.readOnly;
|
||||||
|
const isPendingPayList = statusParams.statusFilter === 0;
|
||||||
|
|
||||||
if (res?.list && res?.list.length > 0) {
|
const fetchOrders = async () => pageShopOrder(searchConditions);
|
||||||
|
|
||||||
|
let res = await fetchOrders();
|
||||||
|
let incoming = (res?.list || []) as ShopOrder[];
|
||||||
|
let rawIncomingLength = incoming.length;
|
||||||
|
|
||||||
|
// 自动取消“支付已过期”的待支付订单(避免用户看到一堆不可支付的过期单)
|
||||||
|
if (canAutoCancelExpired && incoming.length && !autoCancelRunningRef.current) {
|
||||||
|
const expiredToCancel = incoming
|
||||||
|
.filter(o => !!o?.orderId)
|
||||||
|
.filter(o => !autoCanceledOrderIdsRef.current.has(o.orderId as number))
|
||||||
|
.filter(o => isOrderPaymentExpiredSafe(o, timeoutHours));
|
||||||
|
|
||||||
|
if (expiredToCancel.length) {
|
||||||
|
autoCancelRunningRef.current = true;
|
||||||
|
const justCanceled = new Set<number>();
|
||||||
|
try {
|
||||||
|
// 单次最多处理 20 笔,避免接口风暴
|
||||||
|
for (const order of expiredToCancel.slice(0, 20)) {
|
||||||
|
try {
|
||||||
|
await updateShopOrder({ orderId: order.orderId, orderStatus: 2 });
|
||||||
|
autoCanceledOrderIdsRef.current.add(order.orderId as number);
|
||||||
|
justCanceled.add(order.orderId as number);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('自动取消过期订单失败:', order?.orderId, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
autoCancelRunningRef.current = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (justCanceled.size > 0) {
|
||||||
|
if (resetPage) {
|
||||||
|
// resetPage 时重新拉取一次,确保列表状态与服务端一致
|
||||||
|
res = await fetchOrders();
|
||||||
|
incoming = (res?.list || []) as ShopOrder[];
|
||||||
|
rawIncomingLength = incoming.length;
|
||||||
|
Taro.showToast({ title: '已自动取消过期订单', icon: 'none' });
|
||||||
|
} else {
|
||||||
|
// loadMore 时不重新拉取,避免破坏滚动;仅在本地列表中做最小同步
|
||||||
|
if (isPendingPayList) {
|
||||||
|
incoming = incoming.filter(o => !justCanceled.has(o.orderId as number));
|
||||||
|
} else {
|
||||||
|
incoming = incoming.map(o => (
|
||||||
|
justCanceled.has(o.orderId as number) ? { ...o, orderStatus: 2 } : o
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rawIncomingLength > 0) {
|
||||||
// 订单分页接口已返回 orderGoods:列表直接使用该字段
|
// 订单分页接口已返回 orderGoods:列表直接使用该字段
|
||||||
const incoming = res.list as ShopOrder[];
|
|
||||||
|
|
||||||
// 使用函数式更新避免依赖 list
|
// 使用函数式更新避免依赖 list
|
||||||
setList(prevList => {
|
if (incoming.length > 0) {
|
||||||
const newList = resetPage ? incoming : (prevList || []).concat(incoming);
|
setList(prevList => (resetPage ? incoming : (prevList || []).concat(incoming)));
|
||||||
return newList;
|
} else {
|
||||||
});
|
// 本页数据全部被自动取消过滤掉:不清空历史列表,仅保持现状
|
||||||
|
setList(prevList => (resetPage ? [] : prevList));
|
||||||
|
}
|
||||||
|
|
||||||
// 正确判断是否还有更多数据
|
// 正确判断是否还有更多数据(以服务端返回条数为准)
|
||||||
const hasMoreData = incoming.length >= 10; // 假设每页10条数据
|
const hasMoreData = rawIncomingLength >= 10; // 假设每页10条数据
|
||||||
setHasMore(hasMoreData);
|
setHasMore(hasMoreData);
|
||||||
} else {
|
} else {
|
||||||
setList(prevList => resetPage ? [] : prevList);
|
// 服务端已无更多数据
|
||||||
|
setList(prevList => (resetPage ? [] : prevList));
|
||||||
setHasMore(false);
|
setHasMore(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +309,7 @@ function OrderList(props: OrderListProps) {
|
|||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [tapIndex, props.searchParams]); // 移除 list/page 依赖,避免useEffect触发循环
|
}, [tapIndex, props.searchParams, props.baseParams, props.mode, props.readOnly, props.autoCancelExpired, props.paymentTimeoutHours]); // 移除 list/page 依赖,避免useEffect触发循环
|
||||||
|
|
||||||
const reloadMore = useCallback(async () => {
|
const reloadMore = useCallback(async () => {
|
||||||
if (loading || !hasMore) return; // 防止重复加载
|
if (loading || !hasMore) return; // 防止重复加载
|
||||||
@@ -329,30 +365,11 @@ function OrderList(props: OrderListProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 申请退款 (待发货状态)
|
// 申请退款 (待发货状态)
|
||||||
const applyRefund = async (order: ShopOrder) => {
|
const applyRefund = (order: ShopOrder) => {
|
||||||
try {
|
// 跳转到退款申请页面(订单状态在选择退款原因后再更新)
|
||||||
// 更新订单状态为"退款申请中"
|
Taro.navigateTo({
|
||||||
await updateShopOrder({
|
url: `/user/order/refund/index?orderId=${order.orderId}&orderNo=${order.orderNo}`
|
||||||
orderId: order.orderId,
|
});
|
||||||
orderStatus: 4 // 退款申请中
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新本地状态
|
|
||||||
setList(prev => prev.map(item =>
|
|
||||||
item.orderId === order.orderId ? {...item, orderStatus: 4} : item
|
|
||||||
));
|
|
||||||
|
|
||||||
// 跳转到退款申请页面
|
|
||||||
Taro.navigateTo({
|
|
||||||
url: `/user/order/refund/index?orderId=${order.orderId}&orderNo=${order.orderNo}`
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('更新订单状态失败:', error);
|
|
||||||
Taro.showToast({
|
|
||||||
title: '操作失败,请重试',
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 查看物流 (待收货状态)
|
// 查看物流 (待收货状态)
|
||||||
@@ -734,17 +751,20 @@ function OrderList(props: OrderListProps) {
|
|||||||
{/* 订单列表 */}
|
{/* 订单列表 */}
|
||||||
{list.length > 0 && list
|
{list.length > 0 && list
|
||||||
?.filter((item) => {
|
?.filter((item) => {
|
||||||
|
const orderStatus = toNum(item.orderStatus);
|
||||||
// “待收货”不展示退款中的/已退款订单,这些订单统一放到“退货/售后”
|
// “待收货”不展示退款中的/已退款订单,这些订单统一放到“退货/售后”
|
||||||
if (tapIndex === 3 && (item.orderStatus === 4 || item.orderStatus === 6)) {
|
if (tapIndex === 3 && (orderStatus === 4 || orderStatus === 6)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// “退货/售后”只展示售后相关状态
|
// “退货/售后”只展示售后相关状态
|
||||||
if (tapIndex === 5) {
|
if (tapIndex === 5) {
|
||||||
return item.orderStatus === 4 || item.orderStatus === 5 || item.orderStatus === 6 || item.orderStatus === 7;
|
return orderStatus === 4 || orderStatus === 5 || orderStatus === 6 || orderStatus === 7;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
?.map((item, index) => {
|
?.map((item, index) => {
|
||||||
|
const orderStatus = toNum(item.orderStatus);
|
||||||
|
const deliveryStatus = toNum(item.deliveryStatus);
|
||||||
return (
|
return (
|
||||||
<Cell key={item.orderId ?? item.orderNo ?? index} style={{padding: '16px'}}
|
<Cell key={item.orderId ?? item.orderNo ?? index} style={{padding: '16px'}}
|
||||||
onClick={() => Taro.navigateTo({url: `/shop/orderDetail/index?orderId=${item.orderId}`})}>
|
onClick={() => Taro.navigateTo({url: `/shop/orderDetail/index?orderId=${item.orderId}`})}>
|
||||||
@@ -759,7 +779,7 @@ function OrderList(props: OrderListProps) {
|
|||||||
</View>
|
</View>
|
||||||
{/* 右侧显示合并的状态和倒计时 */}
|
{/* 右侧显示合并的状态和倒计时 */}
|
||||||
<View className={`${getOrderStatusColor(item)} font-medium`}>
|
<View className={`${getOrderStatusColor(item)} font-medium`}>
|
||||||
{!item.payStatus && item.orderStatus !== 2 ? (
|
{!item.payStatus && orderStatus !== 2 ? (
|
||||||
<PaymentCountdown
|
<PaymentCountdown
|
||||||
expirationTime={item.expirationTime}
|
expirationTime={item.expirationTime}
|
||||||
createTime={item.createTime}
|
createTime={item.createTime}
|
||||||
@@ -823,23 +843,23 @@ function OrderList(props: OrderListProps) {
|
|||||||
{!isReadOnly && (
|
{!isReadOnly && (
|
||||||
<Space className={'btn flex justify-end'}>
|
<Space className={'btn flex justify-end'}>
|
||||||
{/* 待付款状态:显示取消订单和立即支付 */}
|
{/* 待付款状态:显示取消订单和立即支付 */}
|
||||||
{(!item.payStatus) && item.orderStatus !== 2 && (
|
{(!item.payStatus) && orderStatus !== 2 && (
|
||||||
<Space>
|
<Space>
|
||||||
<Button size={'small'} onClick={(e) => {
|
<Button size={'small'} onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
void cancelOrder(item);
|
void cancelOrder(item);
|
||||||
}}>取消订单</Button>
|
}}>取消</Button>
|
||||||
{(!item.createTime || !isPaymentExpired(item.createTime, 24)) && (
|
{(!item.createTime || !isPaymentExpired(item.createTime, 24)) && (
|
||||||
<Button size={'small'} type="primary" onClick={(e) => {
|
<Button size={'small'} type="primary" onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
void payOrder(item);
|
void payOrder(item);
|
||||||
}}>立即支付</Button>
|
}}>继续支付</Button>
|
||||||
)}
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 待发货状态:显示申请退款 */}
|
{/* 待发货状态:显示申请退款 */}
|
||||||
{item.payStatus && isWithinRefundWindow(item.payTime, 60) && item.deliveryStatus === 10 && item.orderStatus !== 2 && item.orderStatus !== 4 && !isOrderCompleted(item) && (
|
{item.payStatus && isWithinRefundWindow(item.payTime, 60) && deliveryStatus === 10 && orderStatus !== 2 && orderStatus !== 4 && orderStatus !== 6 && orderStatus !== 7 && !isOrderCompleted(item) && (
|
||||||
<Button size={'small'} onClick={(e) => {
|
<Button size={'small'} onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
applyRefund(item);
|
applyRefund(item);
|
||||||
@@ -847,7 +867,7 @@ function OrderList(props: OrderListProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 待收货状态:显示查看物流和确认收货 */}
|
{/* 待收货状态:显示查看物流和确认收货 */}
|
||||||
{item.deliveryStatus === 20 && (!item.riderId || !!item.sendEndTime) && item.orderStatus !== 2 && item.orderStatus !== 6 && !isOrderCompleted(item) && (
|
{deliveryStatus === 20 && (!item.riderId || Number(item.riderId) === 0 || !!item.sendEndTime) && orderStatus !== 2 && orderStatus !== 6 && !isOrderCompleted(item) && (
|
||||||
<Space>
|
<Space>
|
||||||
{/*<Button size={'small'} onClick={(e) => {*/}
|
{/*<Button size={'small'} onClick={(e) => {*/}
|
||||||
{/* e.stopPropagation();*/}
|
{/* e.stopPropagation();*/}
|
||||||
@@ -861,7 +881,7 @@ function OrderList(props: OrderListProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 退款/售后状态:显示查看进度和撤销申请 */}
|
{/* 退款/售后状态:显示查看进度和撤销申请 */}
|
||||||
{(item.orderStatus === 4 || item.orderStatus === 7) && (
|
{(orderStatus === 4 || orderStatus === 7) && (
|
||||||
<Space>
|
<Space>
|
||||||
{/*<Button size={'small'} onClick={(e) => {*/}
|
{/*<Button size={'small'} onClick={(e) => {*/}
|
||||||
{/* e.stopPropagation();*/}
|
{/* e.stopPropagation();*/}
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ function Order() {
|
|||||||
onReload={() => reload(searchParams)}
|
onReload={() => reload(searchParams)}
|
||||||
searchParams={searchParams}
|
searchParams={searchParams}
|
||||||
showSearch={showSearch}
|
showSearch={showSearch}
|
||||||
|
autoCancelExpired
|
||||||
onSearchParamsChange={(newParams) => {
|
onSearchParamsChange={(newParams) => {
|
||||||
console.log('父组件接收到searchParams变化:', newParams);
|
console.log('父组件接收到searchParams变化:', newParams);
|
||||||
setSearchParams(newParams);
|
setSearchParams(newParams);
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import {
|
|||||||
RadioGroup,
|
RadioGroup,
|
||||||
TextArea,
|
TextArea,
|
||||||
Button,
|
Button,
|
||||||
Uploader,
|
|
||||||
Loading,
|
Loading,
|
||||||
Empty,
|
|
||||||
InputNumber
|
InputNumber
|
||||||
} from '@nutui/nutui-react-taro'
|
} from '@nutui/nutui-react-taro'
|
||||||
import { applyAfterSale } from '@/api/afterSale'
|
import { applyAfterSale } from '@/api/afterSale'
|
||||||
import { updateShopOrder } from '@/api/shop/shopOrder'
|
import { getShopOrder, updateShopOrder } from '@/api/shop/shopOrder'
|
||||||
|
import { listShopOrderGoods } from '@/api/shop/shopOrderGoods'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
||||||
// 订单商品信息
|
// 订单商品信息
|
||||||
@@ -60,6 +59,7 @@ const RefundPage: React.FC = () => {
|
|||||||
|
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [submitting, setSubmitting] = useState(false)
|
const [submitting, setSubmitting] = useState(false)
|
||||||
|
const [markedClientRefund, setMarkedClientRefund] = useState(false)
|
||||||
const [orderGoods, setOrderGoods] = useState<OrderGoods[]>([])
|
const [orderGoods, setOrderGoods] = useState<OrderGoods[]>([])
|
||||||
const [orderAmount, setOrderAmount] = useState(0)
|
const [orderAmount, setOrderAmount] = useState(0)
|
||||||
const [refundApp, setRefundApp] = useState<RefundApplication>({
|
const [refundApp, setRefundApp] = useState<RefundApplication>({
|
||||||
@@ -73,6 +73,40 @@ const RefundPage: React.FC = () => {
|
|||||||
isUrgent: false
|
isUrgent: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const toMoneyNumber = (value: unknown, defaultValue: number = 0): number => {
|
||||||
|
if (typeof value === 'number') return Number.isFinite(value) ? value : defaultValue
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
// Be tolerant of API strings like "¥12.34" or "1,234.56".
|
||||||
|
const cleaned = value.trim().replace(/,/g, '').replace(/[^\d.-]/g, '')
|
||||||
|
const n = Number.parseFloat(cleaned)
|
||||||
|
return Number.isFinite(n) ? n : defaultValue
|
||||||
|
}
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatMoney = (value: unknown): string => {
|
||||||
|
const n = toMoneyNumber(value, 0)
|
||||||
|
return n.toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
const markOrderClientRefund = async () => {
|
||||||
|
if (markedClientRefund) return
|
||||||
|
if (!orderId) return
|
||||||
|
const orderIdNum = Number.parseInt(String(orderId), 10)
|
||||||
|
if (!Number.isFinite(orderIdNum)) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateShopOrder({
|
||||||
|
orderId: orderIdNum,
|
||||||
|
orderStatus: 7 // 客户端申请退款
|
||||||
|
})
|
||||||
|
setMarkedClientRefund(true)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('更新订单状态为客户端申请退款失败:', e)
|
||||||
|
// 不阻塞用户填写表单;提交时仍会再次尝试更新一次
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (orderId) {
|
if (orderId) {
|
||||||
loadOrderInfo()
|
loadOrderInfo()
|
||||||
@@ -84,45 +118,52 @@ const RefundPage: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
// 模拟API调用
|
if (!orderId) {
|
||||||
const mockOrderGoods: OrderGoods[] = [
|
throw new Error('缺少订单ID')
|
||||||
{
|
}
|
||||||
goodsId: '1',
|
|
||||||
goodsName: 'iPhone 15 Pro Max 256GB 深空黑色',
|
|
||||||
goodsImage: 'https://via.placeholder.com/100x100',
|
|
||||||
goodsPrice: 9999,
|
|
||||||
goodsNum: 1,
|
|
||||||
canRefundNum: 1,
|
|
||||||
skuInfo: '颜色:深空黑色,容量:256GB'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
goodsId: '2',
|
|
||||||
goodsName: 'AirPods Pro 第三代',
|
|
||||||
goodsImage: 'https://via.placeholder.com/100x100',
|
|
||||||
goodsPrice: 1999,
|
|
||||||
goodsNum: 2,
|
|
||||||
canRefundNum: 2,
|
|
||||||
skuInfo: '颜色:白色'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const totalAmount = mockOrderGoods.reduce((sum, goods) =>
|
const orderIdNum = Number.parseInt(String(orderId), 10)
|
||||||
sum + goods.goodsPrice * goods.goodsNum, 0
|
if (!Number.isFinite(orderIdNum)) {
|
||||||
)
|
throw new Error('订单ID不合法')
|
||||||
|
}
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
// 以订单实付金额为准(避免商品单价合计与优惠/运费等不一致)
|
||||||
|
const order = await getShopOrder(orderIdNum)
|
||||||
|
const payAmount = toMoneyNumber(order?.payPrice ?? order?.totalPrice, 0)
|
||||||
|
|
||||||
setOrderGoods(mockOrderGoods)
|
// 商品信息加载失败时,不阻塞退款申请(全额退款不依赖商品明细)
|
||||||
setOrderAmount(totalAmount)
|
let mappedGoods: OrderGoods[] = []
|
||||||
|
try {
|
||||||
|
const goods = (await listShopOrderGoods({ orderId: orderIdNum })) || []
|
||||||
|
mappedGoods = goods.map((g, idx) => {
|
||||||
|
const goodsNum = Number(g.totalNum ?? 0) || 0
|
||||||
|
return {
|
||||||
|
goodsId: String(g.goodsId ?? idx),
|
||||||
|
goodsName: g.goodsName || '订单商品',
|
||||||
|
goodsImage: g.image || '/default-goods.png',
|
||||||
|
goodsPrice: toMoneyNumber(g.price, 0),
|
||||||
|
goodsNum,
|
||||||
|
canRefundNum: goodsNum,
|
||||||
|
skuInfo: g.spec
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('加载订单商品失败(不阻塞退款申请):', e)
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化退款申请信息
|
setOrderGoods(mappedGoods)
|
||||||
|
setOrderAmount(payAmount)
|
||||||
|
|
||||||
|
// 初始化退款申请信息:默认全额退款
|
||||||
setRefundApp(prev => ({
|
setRefundApp(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
refundAmount: totalAmount,
|
refundType: 'full',
|
||||||
refundGoods: mockOrderGoods.map(goods => ({
|
refundAmount: payAmount,
|
||||||
goodsId: goods.goodsId,
|
refundGoods: mappedGoods.map(g => ({
|
||||||
refundNum: goods.goodsNum
|
goodsId: g.goodsId,
|
||||||
}))
|
refundNum: g.goodsNum
|
||||||
|
})),
|
||||||
|
evidenceImages: []
|
||||||
}))
|
}))
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -180,27 +221,6 @@ const RefundPage: React.FC = () => {
|
|||||||
updateRefundApp('refundAmount', newRefundAmount)
|
updateRefundApp('refundAmount', newRefundAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理图片上传
|
|
||||||
const handleImageUpload = async (files: any) => {
|
|
||||||
try {
|
|
||||||
const uploadedImages: string[] = []
|
|
||||||
|
|
||||||
for (const file of files) {
|
|
||||||
if (file.url) {
|
|
||||||
uploadedImages.push(file.url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateRefundApp('evidenceImages', uploadedImages)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('图片上传失败:', error)
|
|
||||||
Taro.showToast({
|
|
||||||
title: '图片上传失败',
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 提交退款申请
|
// 提交退款申请
|
||||||
const submitRefund = async () => {
|
const submitRefund = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -243,23 +263,30 @@ const RefundPage: React.FC = () => {
|
|||||||
amount: refundApp.refundAmount,
|
amount: refundApp.refundAmount,
|
||||||
contactPhone: refundApp.contactPhone,
|
contactPhone: refundApp.contactPhone,
|
||||||
evidenceImages: refundApp.evidenceImages,
|
evidenceImages: refundApp.evidenceImages,
|
||||||
goodsItems: refundApp.refundGoods.filter(item => item.refundNum > 0).map(item => ({
|
...(refundApp.refundGoods.some(item => item.refundNum > 0)
|
||||||
goodsId: item.goodsId,
|
? {
|
||||||
quantity: item.refundNum
|
goodsItems: refundApp.refundGoods
|
||||||
}))
|
.filter(item => item.refundNum > 0)
|
||||||
|
.map(item => ({
|
||||||
|
goodsId: item.goodsId,
|
||||||
|
quantity: item.refundNum
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
: {})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用API提交退款申请
|
// 调用API提交退款申请
|
||||||
const result = await applyAfterSale(params)
|
const result = await applyAfterSale(params)
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// 更新订单状态为"退款申请中"
|
// 更新订单状态为"客户端申请退款"
|
||||||
if (orderId) {
|
if (orderId) {
|
||||||
try {
|
try {
|
||||||
await updateShopOrder({
|
await updateShopOrder({
|
||||||
orderId: parseInt(orderId),
|
orderId: parseInt(orderId),
|
||||||
orderStatus: 4 // 退款申请中
|
orderStatus: 7 // 客户端申请退款
|
||||||
})
|
})
|
||||||
|
setMarkedClientRefund(true)
|
||||||
} catch (updateError) {
|
} catch (updateError) {
|
||||||
console.error('更新订单状态失败:', updateError)
|
console.error('更新订单状态失败:', updateError)
|
||||||
// 即使更新订单状态失败,也继续执行后续操作
|
// 即使更新订单状态失败,也继续执行后续操作
|
||||||
@@ -301,27 +328,12 @@ const RefundPage: React.FC = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orderGoods.length === 0) {
|
|
||||||
return (
|
|
||||||
<View className="refund-page">
|
|
||||||
<Empty
|
|
||||||
description="暂无订单信息"
|
|
||||||
imageSize={80}
|
|
||||||
>
|
|
||||||
<Button type="primary" size="small" onClick={() => Taro.navigateBack()}>
|
|
||||||
返回
|
|
||||||
</Button>
|
|
||||||
</Empty>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className="refund-page">
|
<View className="refund-page">
|
||||||
{/* 订单信息 */}
|
{/* 订单信息 */}
|
||||||
<View className="order-info">
|
<View className="order-info">
|
||||||
<Text className="order-no">订单号:{orderNo}</Text>
|
<Text className="order-no">订单号:{orderNo}</Text>
|
||||||
<Text className="order-amount">订单金额:¥{orderAmount}</Text>
|
<Text className="order-amount">订单金额:¥{formatMoney(orderAmount)}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 退款类型选择 */}
|
{/* 退款类型选择 */}
|
||||||
@@ -369,7 +381,7 @@ const RefundPage: React.FC = () => {
|
|||||||
value={refundNum}
|
value={refundNum}
|
||||||
min={0}
|
min={0}
|
||||||
max={goods.canRefundNum}
|
max={goods.canRefundNum}
|
||||||
onChange={(value) => updateGoodsRefundNum(goods.goodsId, value)}
|
onChange={(value) => updateGoodsRefundNum(goods.goodsId, Number(value) || 0)}
|
||||||
/>
|
/>
|
||||||
<Text className="max-num">最多{goods.canRefundNum}件</Text>
|
<Text className="max-num">最多{goods.canRefundNum}件</Text>
|
||||||
</View>
|
</View>
|
||||||
@@ -382,7 +394,7 @@ const RefundPage: React.FC = () => {
|
|||||||
{/* 退款金额 */}
|
{/* 退款金额 */}
|
||||||
<CellGroup title="退款金额">
|
<CellGroup title="退款金额">
|
||||||
<Cell>
|
<Cell>
|
||||||
<Text className="refund-amount">¥{refundApp.refundAmount}</Text>
|
<Text className="refund-amount">¥{formatMoney(refundApp.refundAmount)}</Text>
|
||||||
</Cell>
|
</Cell>
|
||||||
</CellGroup>
|
</CellGroup>
|
||||||
|
|
||||||
@@ -390,7 +402,10 @@ const RefundPage: React.FC = () => {
|
|||||||
<CellGroup title="退款原因">
|
<CellGroup title="退款原因">
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
value={refundApp.refundReason}
|
value={refundApp.refundReason}
|
||||||
onChange={(value) => updateRefundApp('refundReason', value)}
|
onChange={(value) => {
|
||||||
|
updateRefundApp('refundReason', value)
|
||||||
|
void markOrderClientRefund()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{REFUND_REASONS.map(reason => (
|
{REFUND_REASONS.map(reason => (
|
||||||
<Cell key={reason} className="reason-cell">
|
<Cell key={reason} className="reason-cell">
|
||||||
@@ -414,18 +429,18 @@ const RefundPage: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* 凭证图片 */}
|
{/* 凭证图片:当前上传链路不可用,先隐藏(保留数据结构,后续可恢复) */}
|
||||||
<View className="evidence-section">
|
{/*<View className="evidence-section">*/}
|
||||||
<View className="section-title">上传凭证(可选)</View>
|
{/* <View className="section-title">上传凭证(可选)</View>*/}
|
||||||
<Uploader
|
{/* <Uploader*/}
|
||||||
value={refundApp.evidenceImages.map(url => ({ url }))}
|
{/* value={refundApp.evidenceImages.map(url => ({ url }))}*/}
|
||||||
onChange={handleImageUpload}
|
{/* onChange={handleImageUpload}*/}
|
||||||
multiple
|
{/* multiple*/}
|
||||||
maxCount={6}
|
{/* maxCount={6}*/}
|
||||||
previewType="picture"
|
{/* previewType="picture"*/}
|
||||||
deletable
|
{/* deletable*/}
|
||||||
/>
|
{/* />*/}
|
||||||
</View>
|
{/*</View>*/}
|
||||||
|
|
||||||
{/* 其他选项 */}
|
{/* 其他选项 */}
|
||||||
{/*<CellGroup>*/}
|
{/*<CellGroup>*/}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import Taro, { useDidShow } from '@tarojs/taro';
|
import Taro, { useDidShow } from '@tarojs/taro';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -14,14 +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 { 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[]>([]);
|
||||||
@@ -36,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
|
||||||
@@ -45,6 +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 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');
|
||||||
@@ -94,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}`);
|
||||||
@@ -185,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' });
|
||||||
@@ -262,6 +318,187 @@ const UserTicketList = () => {
|
|||||||
return d.isValid() ? d.format('YYYY年MM月DD日') : v;
|
return d.isValid() ? d.format('YYYY年MM月DD日') : v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getTicketAvailableQty = (t?: Partial<GltUserTicket> | null) => {
|
||||||
|
if (!t) return 0;
|
||||||
|
const anyT: any = t;
|
||||||
|
const raw =
|
||||||
|
anyT.availableQty ??
|
||||||
|
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 getTicketUsedQty = (t?: Partial<GltUserTicket> | null) => {
|
||||||
|
if (!t) return 0;
|
||||||
|
const anyT: any = t;
|
||||||
|
const raw = anyT.usedQty ?? anyT.usedNum ?? anyT.usedCount;
|
||||||
|
const n = Number(raw);
|
||||||
|
return Number.isFinite(n) ? n : 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const rollbackUserTicketAfterOrderCancel = async (order: GltTicketOrder, before?: GltUserTicket | null) => {
|
||||||
|
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;
|
||||||
|
|
||||||
|
const rollbackKey = `glt_ticket_order_rollback:${orderId}`;
|
||||||
|
if (Taro.getStorageSync(rollbackKey)) return;
|
||||||
|
|
||||||
|
const after = await getGltUserTicket(ticketId);
|
||||||
|
if (!after?.id) return;
|
||||||
|
|
||||||
|
const beforeAvail = before ? getTicketAvailableQty(before) : undefined;
|
||||||
|
const afterAvail = getTicketAvailableQty(after);
|
||||||
|
const beforeUsed = before ? getTicketUsedQty(before) : undefined;
|
||||||
|
const afterUsed = getTicketUsedQty(after);
|
||||||
|
|
||||||
|
let needAvail = qty;
|
||||||
|
if (typeof beforeAvail === 'number') {
|
||||||
|
const delta = afterAvail - beforeAvail;
|
||||||
|
if (delta >= qty) {
|
||||||
|
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 (needAvail <= 0 && needUsed <= 0) {
|
||||||
|
Taro.setStorageSync(rollbackKey, Date.now());
|
||||||
|
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 {
|
||||||
|
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) {
|
||||||
|
console.error('取消送水订单失败:', e);
|
||||||
|
Taro.showToast({ title: '取消失败,请重试', icon: 'none' });
|
||||||
|
} finally {
|
||||||
|
Taro.hideLoading();
|
||||||
|
setOrderCancelLoadingById((prev) => ({ ...prev, [order.id as number]: false }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getTicketOrderStatusMeta = (order: GltTicketOrder) => {
|
const getTicketOrderStatusMeta = (order: GltTicketOrder) => {
|
||||||
if (order.status === 1) return { text: '已冻结', type: 'warning' as const };
|
if (order.status === 1) return { text: '已冻结', type: 'warning' as const };
|
||||||
|
|
||||||
@@ -313,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>
|
||||||
@@ -401,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>
|
||||||
@@ -413,12 +678,24 @@ const UserTicketList = () => {
|
|||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
<View className="flex flex-col items-end gap-2">
|
<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.
|
||||||
@@ -440,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>
|
||||||
@@ -534,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>
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import dayjs from 'dayjs'
|
|||||||
import { pageGltTicketOrder, updateGltTicketOrder } from '@/api/glt/gltTicketOrder'
|
import { pageGltTicketOrder, updateGltTicketOrder } from '@/api/glt/gltTicketOrder'
|
||||||
import type { GltTicketOrder, GltTicketOrderParam } from '@/api/glt/gltTicketOrder/model'
|
import type { GltTicketOrder, GltTicketOrderParam } from '@/api/glt/gltTicketOrder/model'
|
||||||
import { uploadFile } from '@/api/system/file'
|
import { uploadFile } from '@/api/system/file'
|
||||||
|
import { listShopStoreRider, updateShopStoreRider } from '@/api/shop/shopStoreRider'
|
||||||
|
import { getCurrentLngLat } from '@/utils/location'
|
||||||
|
|
||||||
const PAGE_SIZE = 10
|
const PAGE_SIZE = 10
|
||||||
|
|
||||||
@@ -236,6 +238,37 @@ export default function TicketOrdersPage() {
|
|||||||
}
|
}
|
||||||
setDeliverSubmitting(true)
|
setDeliverSubmitting(true)
|
||||||
try {
|
try {
|
||||||
|
// 送达时同步记录配送员当前位置(用于门店/后台跟踪骑手位置)
|
||||||
|
const loc = await getCurrentLngLat('确认送达需要记录您的当前位置,请在设置中开启定位权限后重试。')
|
||||||
|
if (!loc) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 优先按 userId 精确查找;后端若未支持该字段,会自动忽略,我们再做兜底。
|
||||||
|
let riderRow =
|
||||||
|
(await listShopStoreRider({ userId: riderId, storeId: deliverOrder.storeId, status: 1 } as any))
|
||||||
|
?.find(r => String(r?.userId || '') === String(riderId || '')) ||
|
||||||
|
null
|
||||||
|
|
||||||
|
// 兜底:按门店筛选后再匹配 userId
|
||||||
|
if (!riderRow && deliverOrder.storeId) {
|
||||||
|
const list = await listShopStoreRider({ storeId: deliverOrder.storeId, status: 1 } as any)
|
||||||
|
riderRow = list?.find(r => String(r?.userId || '') === String(riderId || '')) || null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (riderRow?.id) {
|
||||||
|
await updateShopStoreRider({
|
||||||
|
id: riderRow.id,
|
||||||
|
longitude: loc.lng,
|
||||||
|
latitude: loc.lat
|
||||||
|
} as any)
|
||||||
|
} else {
|
||||||
|
console.warn('未找到 ShopStoreRider 记录,无法更新骑手经纬度:', { riderId, storeId: deliverOrder.storeId })
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// 不阻塞送达流程,但记录日志便于排查。
|
||||||
|
console.warn('更新 ShopStoreRider 经纬度失败:', e)
|
||||||
|
}
|
||||||
|
|
||||||
const now = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
const now = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||||
// 送达时间:首次“确认送达”写入;补传照片时不要覆盖原送达时间
|
// 送达时间:首次“确认送达”写入;补传照片时不要覆盖原送达时间
|
||||||
const deliveredAt = deliverOrder.sendEndTime || now
|
const deliveredAt = deliverOrder.sendEndTime || now
|
||||||
|
|||||||
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
@@ -5,6 +5,7 @@ import { getSelectedStoreFromStorage, getSelectedStoreIdFromStorage } from '@/ut
|
|||||||
import type { ShopStoreRider } from '@/api/shop/shopStoreRider/model';
|
import type { ShopStoreRider } from '@/api/shop/shopStoreRider/model';
|
||||||
import type { ShopStoreWarehouse } from '@/api/shop/shopStoreWarehouse/model';
|
import type { ShopStoreWarehouse } from '@/api/shop/shopStoreWarehouse/model';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
import { getWxOpenId, getUserInfo } from '@/api/layout';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付类型枚举
|
* 支付类型枚举
|
||||||
@@ -19,7 +20,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;
|
||||||
}
|
}
|
||||||
@@ -32,6 +34,74 @@ export class PaymentHandler {
|
|||||||
private static storeRidersCache = new Map<number, ShopStoreRider[]>();
|
private static storeRidersCache = new Map<number, ShopStoreRider[]>();
|
||||||
private static warehousesCache: ShopStoreWarehouse[] | null = null;
|
private static warehousesCache: ShopStoreWarehouse[] | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【关键修复】支付前确保当前微信用户的 openid 已正确绑定到后端
|
||||||
|
*
|
||||||
|
* 问题场景:
|
||||||
|
* 1. 用户通过手机号注册 → openid 未绑定 → 后端用空 openid 创建预支付单 → 支付时报"账号不一致"
|
||||||
|
* 2. 用户切换了微信账号 → 本地缓存的用户信息是旧账号的 → openid 与当前支付人不匹配
|
||||||
|
* 3. 自动登录(loginByOpenId)未触发 getWxOpenId 绑定流程
|
||||||
|
*
|
||||||
|
* 解决方案:每次微信支付前,重新获取 wx.login code 并调用 getWxOpenId 绑定,
|
||||||
|
* 确保后端记录的 openid = 当前实际支付人的 openid
|
||||||
|
*/
|
||||||
|
private static async ensureOpenIdBeforePay(): Promise<void> {
|
||||||
|
try {
|
||||||
|
// 非微信环境跳过(如 H5 开发调试)
|
||||||
|
let isWeapp = false;
|
||||||
|
try {
|
||||||
|
isWeapp = Taro.getEnv() === Taro.ENV_TYPE.WEAPP;
|
||||||
|
} catch (_e) {
|
||||||
|
isWeapp = process.env.TARO_ENV === 'weapp';
|
||||||
|
}
|
||||||
|
if (!isWeapp) return;
|
||||||
|
|
||||||
|
// 获取当前登录用户的最新信息(检查是否已有 openid)
|
||||||
|
let currentUser = null;
|
||||||
|
try {
|
||||||
|
currentUser = await getUserInfo();
|
||||||
|
} catch (_e) {
|
||||||
|
// getUserInfo 失败时不阻塞支付(可能是 token 过期等),让后续接口自行报错
|
||||||
|
console.warn('[ensureOpenId] 获取用户信息失败,跳过 openid 校验');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果用户已有 openid,仍然需要刷新:因为用户可能切换了微信账号
|
||||||
|
// 每次都重新获取 code + 绑定,确保 openid 是当前微信会话的
|
||||||
|
|
||||||
|
const code = await new Promise<string | undefined>((resolve, reject) => {
|
||||||
|
Taro.login({
|
||||||
|
success: (res) => resolve(res.code as string),
|
||||||
|
fail: (e) => reject(e),
|
||||||
|
timeout: 5000, // 5秒超时
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!code) {
|
||||||
|
console.warn('[ensureOpenId] wx.login 未返回 code');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用后端绑定/更新 openid
|
||||||
|
await getWxOpenId({ code });
|
||||||
|
console.log('[ensureOpenId] openid 刷新/绑定成功');
|
||||||
|
|
||||||
|
// 同步本地 User 缓存,确保后续逻辑能读到最新 openid
|
||||||
|
try {
|
||||||
|
const freshUser = await getUserInfo();
|
||||||
|
if (freshUser) {
|
||||||
|
Taro.setStorageSync('User', freshUser);
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// ignore: 服务端已更新 openid,本地缓存不同步也不影响本次支付
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// openid 刷新失败不阻塞支付流程(可能网络波动),
|
||||||
|
// 但记录日志方便排查;若确实不一致,微信支付侧会报错
|
||||||
|
console.warn('[ensureOpenId] openid 刷新失败(非阻塞):', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行支付
|
* 执行支付
|
||||||
* @param orderData 订单数据
|
* @param orderData 订单数据
|
||||||
@@ -79,6 +149,12 @@ export class PaymentHandler {
|
|||||||
// 设置支付类型
|
// 设置支付类型
|
||||||
orderData.payType = paymentType;
|
orderData.payType = paymentType;
|
||||||
|
|
||||||
|
// 【关键修复】微信支付前,强制刷新/绑定当前微信用户的 openid
|
||||||
|
// 防止"下单账号与支付账号不一致"错误
|
||||||
|
if (paymentType === PaymentType.WECHAT) {
|
||||||
|
await this.ensureOpenIdBeforePay();
|
||||||
|
}
|
||||||
|
|
||||||
console.log('创建订单请求:', orderData);
|
console.log('创建订单请求:', orderData);
|
||||||
|
|
||||||
// 创建订单
|
// 创建订单
|
||||||
@@ -118,17 +194,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 +551,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 +570,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
|
||||||
@@ -16,5 +18,7 @@ export function saveStorageByLoginUser(token: string, user: User) {
|
|||||||
Taro.setStorageSync('access_token', token)
|
Taro.setStorageSync('access_token', token)
|
||||||
Taro.setStorageSync('UserId', user.userId)
|
Taro.setStorageSync('UserId', user.userId)
|
||||||
Taro.setStorageSync('Phone', user.phone)
|
Taro.setStorageSync('Phone', user.phone)
|
||||||
|
Taro.setStorageSync('WxNickName', user.nickname);
|
||||||
Taro.setStorageSync('User', user)
|
Taro.setStorageSync('User', user)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
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