From aff888794f3f7cb75501c08315e584a9dc498607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sun, 25 Jan 2026 13:32:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(dealer):=20=E6=B7=BB=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E9=94=80=E5=95=86=E6=94=B6=E7=9B=8A=E6=98=8E=E7=BB=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=B9=B6=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增收益明细页面,支持下拉刷新和上拉加载更多 - 在app.config.ts中注册收益明细页面路由 - 更新API基础URL配置,统一使用mp-api域名 - 优化提交表单逻辑,确保refereeId参数为数字类型 - 修改订单页面,添加resourceId参数以正确过滤分销订单 - 修复订单号显示逻辑,优先使用接口返回的订单号 - 优化订单列表项点击事件,跳转到收益明细页面 - 更新客户名称显示格式,包含昵称和用户ID - 调整订单详情展示布局和信息内容 --- config/env.ts | 6 +- src/api/shop/shopDealerCapital/model/index.ts | 6 + src/api/shop/shopDealerOrder/model/index.ts | 5 + src/app.config.ts | 1 + src/dealer/apply/add.tsx | 4 +- src/dealer/capital/index.config.ts | 4 + src/dealer/capital/index.scss | 2 + src/dealer/capital/index.tsx | 199 ++++++++++++++++++ src/dealer/orders/index.tsx | 41 ++-- 9 files changed, 247 insertions(+), 21 deletions(-) create mode 100644 src/dealer/capital/index.config.ts create mode 100644 src/dealer/capital/index.scss create mode 100644 src/dealer/capital/index.tsx diff --git a/config/env.ts b/config/env.ts index 16c21e5..da3a21b 100644 --- a/config/env.ts +++ b/config/env.ts @@ -3,19 +3,19 @@ export const ENV_CONFIG = { // 开发环境 development: { // API_BASE_URL: 'http://127.0.0.1:9200/api', - API_BASE_URL: 'https://cms-api.websoft.top/api', + API_BASE_URL: 'https://mp-api.websoft.top/api', APP_NAME: '开发环境', DEBUG: 'true', }, // 生产环境 production: { - API_BASE_URL: 'https://cms-api.websoft.top/api', + API_BASE_URL: 'https://mp-api.websoft.top/api', APP_NAME: '桂乐淘', DEBUG: 'false', }, // 测试环境 test: { - API_BASE_URL: 'https://cms-api.s209.websoft.top/api', + API_BASE_URL: 'https://mp-api.s209.websoft.top/api', APP_NAME: '测试环境', DEBUG: 'true', } diff --git a/src/api/shop/shopDealerCapital/model/index.ts b/src/api/shop/shopDealerCapital/model/index.ts index e6a6bc2..00d29a7 100644 --- a/src/api/shop/shopDealerCapital/model/index.ts +++ b/src/api/shop/shopDealerCapital/model/index.ts @@ -31,5 +31,11 @@ export interface ShopDealerCapital { */ export interface ShopDealerCapitalParam extends PageParam { id?: number; + // 仅查询当前分销商的收益/资金明细 + userId?: number; + // 可选:按订单过滤 + orderId?: number; + // 可选:资金流动类型过滤 + flowType?: number; keywords?: string; } diff --git a/src/api/shop/shopDealerOrder/model/index.ts b/src/api/shop/shopDealerOrder/model/index.ts index 68b4928..76d74a9 100644 --- a/src/api/shop/shopDealerOrder/model/index.ts +++ b/src/api/shop/shopDealerOrder/model/index.ts @@ -8,6 +8,9 @@ export interface ShopDealerOrder { id?: number; // 买家用户ID userId?: number; + nickname?: string; + // 订单编号(部分接口会直接返回订单号字符串) + orderNo?: string; // 订单ID orderId?: number; // 订单总金额(不含运费) @@ -47,5 +50,7 @@ export interface ShopDealerOrderParam extends PageParam { secondUserId?: number; thirdUserId?: number; userId?: number; + // 数据权限/资源ID(通常传当前登录用户ID) + resourceId?: number; keywords?: string; } diff --git a/src/app.config.ts b/src/app.config.ts index 651f4fe..1b2079d 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -73,6 +73,7 @@ export default { "apply/add", "withdraw/index", "orders/index", + "capital/index", "team/index", "qrcode/index", "invite-stats/index", diff --git a/src/dealer/apply/add.tsx b/src/dealer/apply/add.tsx index f49ff09..c041ebf 100644 --- a/src/dealer/apply/add.tsx +++ b/src/dealer/apply/add.tsx @@ -127,7 +127,7 @@ const AddUserAddress = () => { } // 提交表单 - const submitSucceed = async (values: any) => { + const submitSucceed = async (values: User) => { try { // 验证必填字段 if (!values.phone && !FormData?.phone) { @@ -192,7 +192,7 @@ const AddUserAddress = () => { userId: user?.userId, realName: values.realName || FormData?.nickname, mobile: values.phone || FormData?.phone, - refereeId: values.refereeId || FormData?.refereeId + refereeId: Number(values.refereeId) || Number(FormData?.refereeId) }) if (roles.length > 0) { diff --git a/src/dealer/capital/index.config.ts b/src/dealer/capital/index.config.ts new file mode 100644 index 0000000..8e2e153 --- /dev/null +++ b/src/dealer/capital/index.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '收益明细' +}) + diff --git a/src/dealer/capital/index.scss b/src/dealer/capital/index.scss new file mode 100644 index 0000000..5e9d65f --- /dev/null +++ b/src/dealer/capital/index.scss @@ -0,0 +1,2 @@ +/* Intentionally empty: styling is done via utility classes. */ + diff --git a/src/dealer/capital/index.tsx b/src/dealer/capital/index.tsx new file mode 100644 index 0000000..b599fb9 --- /dev/null +++ b/src/dealer/capital/index.tsx @@ -0,0 +1,199 @@ +import React, {useCallback, useEffect, useState} from 'react' +import {View, Text, ScrollView} from '@tarojs/components' +import {Empty, Tag, PullToRefresh, Loading} from '@nutui/nutui-react-taro' +import Taro from '@tarojs/taro' +import {pageShopDealerCapital} from '@/api/shop/shopDealerCapital' +import {useDealerUser} from '@/hooks/useDealerUser' +import type {ShopDealerCapital} from '@/api/shop/shopDealerCapital/model' + +const PAGE_SIZE = 10 + +const DealerCapital: React.FC = () => { + const {dealerUser} = useDealerUser() + + const [loading, setLoading] = useState(false) + const [refreshing, setRefreshing] = useState(false) + const [loadingMore, setLoadingMore] = useState(false) + const [currentPage, setCurrentPage] = useState(1) + const [hasMore, setHasMore] = useState(true) + const [records, setRecords] = useState([]) + + const getFlowTypeText = (flowType?: number) => { + switch (flowType) { + case 10: + return '佣金收入' + case 20: + return '提现支出' + case 30: + return '转账支出' + case 40: + return '转账收入' + default: + return '资金变动' + } + } + + const getFlowTypeTag = (flowType?: number) => { + // 收入:success;支出:danger;其它:default + if (flowType === 10 || flowType === 40) return 'success' + if (flowType === 20 || flowType === 30) return 'danger' + return 'default' + } + + const formatMoney = (flowType?: number, money?: string) => { + const isIncome = flowType === 10 || flowType === 40 + const isExpense = flowType === 20 || flowType === 30 + const sign = isIncome ? '+' : isExpense ? '-' : '' + return `${sign}${money || '0.00'}` + } + + const fetchRecords = useCallback(async (page: number = 1, isRefresh: boolean = false) => { + if (!dealerUser?.userId) return + + try { + if (isRefresh) { + setRefreshing(true) + } else if (page === 1) { + setLoading(true) + } else { + setLoadingMore(true) + } + + const result = await pageShopDealerCapital({ + page, + limit: PAGE_SIZE, + // 只显示与当前登录用户相关的收益明细 + userId: dealerUser.userId + }) + + const list = result?.list || [] + if (page === 1) { + setRecords(list) + } else { + setRecords(prev => [...prev, ...list]) + } + + setHasMore(list.length === PAGE_SIZE) + setCurrentPage(page) + } catch (error) { + console.error('获取收益明细失败:', error) + Taro.showToast({ + title: '获取收益明细失败', + icon: 'error' + }) + } finally { + setLoading(false) + setRefreshing(false) + setLoadingMore(false) + } + }, [dealerUser?.userId]) + + const handleRefresh = async () => { + await fetchRecords(1, true) + } + + const handleLoadMore = async () => { + if (!loadingMore && hasMore) { + await fetchRecords(currentPage + 1) + } + } + + useEffect(() => { + if (dealerUser?.userId) { + fetchRecords(1) + } + }, [fetchRecords, dealerUser?.userId]) + + if (!dealerUser) { + return ( + + + 加载中... + + ) + } + + return ( + + + + + {loading && records.length === 0 ? ( + + + 加载中... + + ) : records.length > 0 ? ( + <> + {records.map((item) => ( + + + + {item.describe || '收益明细'} + + + {getFlowTypeText(item.flowType)} + + + + + + 佣金收入 + + + {formatMoney(item.flowType, item.money)} + + + + + + {/*用户:{item.userId ?? '-'}*/} + + + {item.createTime || '-'} + + + + ))} + + {loadingMore && ( + + + 加载更多... + + )} + {!hasMore && records.length > 0 && ( + + 没有更多数据了 + + )} + + ) : ( + + )} + + + + + ) +} + +export default DealerCapital diff --git a/src/dealer/orders/index.tsx b/src/dealer/orders/index.tsx index f3b6bbf..7fbe6d8 100644 --- a/src/dealer/orders/index.tsx +++ b/src/dealer/orders/index.tsx @@ -24,7 +24,8 @@ const DealerOrders: React.FC = () => { // 获取订单数据 const fetchOrders = useCallback(async (page: number = 1, isRefresh: boolean = false) => { - if (!dealerUser?.userId) return + // 需要当前登录用户ID(用于 resourceId 参数) + if (!dealerUser || !dealerUser.userId) return try { if (isRefresh) { @@ -37,14 +38,17 @@ const DealerOrders: React.FC = () => { const result = await pageShopDealerOrder({ page, - limit: 10 + limit: 10, + // 后端需要 resourceId=当前登录用户ID 才能正确过滤分销订单 + resourceId: dealerUser.userId }) if (result?.list) { const newOrders = result.list.map(order => ({ ...order, - orderNo: `${order.orderId}`, - customerName: `用户${order.userId}`, + // 优先使用接口返回的订单号;没有则降级展示 orderId + orderNo: order.orderNo ?? (order.orderId != null ? String(order.orderId) : undefined), + customerName: `${order.nickname}${order.userId}`, userCommission: order.firstMoney || '0.00' })) @@ -102,32 +106,37 @@ const DealerOrders: React.FC = () => { return 'warning' } + const handleGoCapital = () => { + Taro.navigateTo({url: '/dealer/capital/index'}) + } + const renderOrderItem = (order: OrderWithDetails) => ( - + - 订单号:{order.orderNo} + 订单号:{order.orderNo || '-'} {getStatusText(order.isSettled, order.isInvalid)} - - - 订单金额:¥{order.orderPrice || '0.00'} - - - 我的佣金:¥{order.userCommission} - - + {/**/} + {/* */} + {/* 订单金额:¥{order.orderPrice || '0.00'}*/} + {/* */} + {/**/} - 客户:{order.customerName} + {order.createTime} - {order.createTime} + 订单金额:¥{order.orderPrice || '0.00'}