Compare commits

...

6 Commits

Author SHA1 Message Date
chashaobao
fd5b3dab97 feat: fix conflict 2025-06-15 01:10:47 +08:00
chashaobao
1b782ee82c Merge branch 'trunk' into feat/update-login 2025-06-15 01:09:35 +08:00
chashaobao
80c0d71921 feat: login whatever 2025-06-15 01:09:30 +08:00
chashaobao
c76027b4d9 feat: support click to open material page 2025-06-15 00:19:18 +08:00
chashaobao
c08b0bef95 feat: support click avatar jump to resume page 2025-06-15 00:14:48 +08:00
chashaobao
96eb46821e feat: withdraw 2025-06-14 23:45:47 +08:00
21 changed files with 338 additions and 47 deletions

View File

@ -109,5 +109,6 @@
"ignoredBuiltDependencies": [ "ignoredBuiltDependencies": [
"@tarojs/binding" "@tarojs/binding"
] ]
} },
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
} }

View File

@ -8,7 +8,6 @@ import PhoneButton from '@/components/phone-button';
import { ProtocolPrivacy } from '@/components/protocol-privacy'; import { ProtocolPrivacy } from '@/components/protocol-privacy';
import SafeBottomPadding from '@/components/safe-bottom-padding'; import SafeBottomPadding from '@/components/safe-bottom-padding';
import './index.less'; import './index.less';
interface IProps { interface IProps {

View File

@ -5,7 +5,7 @@ import { useCallback, useState } from 'react';
import LoginDialog from '@/components/login-dialog'; import LoginDialog from '@/components/login-dialog';
import useUserInfo from '@/hooks/use-user-info'; import useUserInfo from '@/hooks/use-user-info';
import { isNeedLogin } from '@/utils/user'; import { getAgreementSigned, isNeedLogin } from '@/utils/user';
import './index.less'; import './index.less';
@ -26,6 +26,7 @@ function LoginButton(props: ILoginButtonProps) {
const userInfo = useUserInfo(); const userInfo = useUserInfo();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const needLogin = isNeedLogin(userInfo); const needLogin = isNeedLogin(userInfo);
const needSign = !getAgreementSigned();
const onSuccess = useCallback( const onSuccess = useCallback(
e => { e => {
@ -40,11 +41,13 @@ function LoginButton(props: ILoginButtonProps) {
<Button <Button
{...otherProps} {...otherProps}
className={classNames(PREFIX, className)} className={classNames(PREFIX, className)}
onClick={needLogin ? () => setVisible(true) : onClick} onClick={needLogin || needSign ? () => setVisible(true) : onClick}
> >
{children} {children}
</Button> </Button>
{visible && <LoginDialog onCancel={() => setVisible(false)} onSuccess={onSuccess} needPhone={needPhone} />} {visible && (
<LoginDialog disableCheck onCancel={() => setVisible(false)} onSuccess={onSuccess} needPhone={needPhone} />
)}
</> </>
); );
} }

View File

@ -12,6 +12,7 @@ import './index.less';
interface IProps { interface IProps {
title?: string; title?: string;
onCancel: () => void; onCancel: () => void;
disableCheck?: boolean;
needPhone?: IPhoneButtonProps['needPhone']; needPhone?: IPhoneButtonProps['needPhone'];
onSuccess?: IPhoneButtonProps['onSuccess']; onSuccess?: IPhoneButtonProps['onSuccess'];
onBindPhone?: IPhoneButtonProps['onBindPhone']; onBindPhone?: IPhoneButtonProps['onBindPhone'];
@ -20,8 +21,15 @@ interface IProps {
const PREFIX = 'login-dialog'; const PREFIX = 'login-dialog';
export default function LoginDialog(props: IProps) { export default function LoginDialog(props: IProps) {
const { title = '使用播络服务前,请先登录', needPhone, onSuccess, onCancel, onBindPhone } = props; const {
const [checked, setChecked] = useState(false); title = '使用播络服务前,请先登录',
disableCheck = false,
needPhone,
onSuccess,
onCancel,
onBindPhone,
} = props;
const [checked, setChecked] = useState(disableCheck);
const handleTipCheck = useCallback(() => { const handleTipCheck = useCallback(() => {
Toast.info('请先阅读并同意协议'); Toast.info('请先阅读并同意协议');
@ -50,7 +58,9 @@ export default function LoginDialog(props: IProps) {
<Button className={`${PREFIX}__cancel-button`} onClick={onCancel}> <Button className={`${PREFIX}__cancel-button`} onClick={onCancel}>
</Button> </Button>
{!disableCheck && (
<ProtocolPrivacyCheckbox checked={checked} onChange={setChecked} className={`${PREFIX}__checkbox`} /> <ProtocolPrivacyCheckbox checked={checked} onChange={setChecked} className={`${PREFIX}__checkbox`} />
)}
</div> </div>
</Dialog.Content> </Dialog.Content>
</Dialog> </Dialog>

View File

@ -2,13 +2,13 @@ import { Image } from '@tarojs/components';
import classNames from 'classnames'; import classNames from 'classnames';
import { PropsWithChildren, useEffect, useState, useCallback } from 'react'; import { PropsWithChildren, useEffect, useState, useCallback } from 'react';
import { MaterialViewSource } from '@/constants/material';
import { PageUrl } from '@/constants/app';
import { MaterialViewSource } from '@/constants/material';
import useUserInfo from '@/hooks/use-user-info'; import useUserInfo from '@/hooks/use-user-info';
import { IChatMessage } from '@/types/message'; import { IChatMessage } from '@/types/message';
import { getScrollItemId } from '@/utils/common'; import { getScrollItemId } from '@/utils/common';
import { navigateTo } from '@/utils/route'; import { navigateTo } from '@/utils/route';
import { PageUrl } from '@/constants/app';
import './index.less'; import './index.less';
@ -19,12 +19,13 @@ export interface IBaseMessageProps {
export interface IUserMessageProps extends PropsWithChildren, IBaseMessageProps { export interface IUserMessageProps extends PropsWithChildren, IBaseMessageProps {
isRead?: boolean; isRead?: boolean;
resumeId?: string;
} }
const PREFIX = 'base-message'; const PREFIX = 'base-message';
function BaseMessage(props: IUserMessageProps) { function BaseMessage(props: IUserMessageProps) {
const { id, message, isRead: isReadProps, children } = props; const { id, message, isRead: isReadProps, children, resumeId } = props;
const { userId } = useUserInfo(); const { userId } = useUserInfo();
const [isRead, setIsRead] = useState(message.isRead); const [isRead, setIsRead] = useState(message.isRead);
const isSender = message.senderUserId === userId; const isSender = message.senderUserId === userId;
@ -37,10 +38,12 @@ function BaseMessage(props: IUserMessageProps) {
// const timer = setTimeout(() => setIsRead(true), 1200); // const timer = setTimeout(() => setIsRead(true), 1200);
// return () => clearTimeout(timer); // return () => clearTimeout(timer);
// }, [isSender]); // }, [isSender]);
const handleClick = useCallback( const handleClick = useCallback(() => {
() => navigateTo(PageUrl.MaterialView, { resumeId: message.jobId, source: MaterialViewSource.Chat }), if (!resumeId || isSender) {
[message.jobId] return;
); }
navigateTo(PageUrl.MaterialView, { resumeId: resumeId, source: MaterialViewSource.Chat });
}, [resumeId, isSender]);
useEffect(() => { useEffect(() => {
if (isRead) { if (isRead) {
return; return;
@ -53,6 +56,7 @@ function BaseMessage(props: IUserMessageProps) {
<Image <Image
mode="aspectFit" mode="aspectFit"
className={`${PREFIX}__avatar`} className={`${PREFIX}__avatar`}
onClick={handleClick}
src={message.senderAvatarUrl || require('@/statics/png/default_avatar.png')} src={message.senderAvatarUrl || require('@/statics/png/default_avatar.png')}
/> />
<div className={`${PREFIX}__content-container`}> <div className={`${PREFIX}__content-container`}>

View File

@ -60,7 +60,9 @@ export default function PartnerBanner() {
)} )}
<div className={`${PREFIX}__close`} onClick={handlePartnerBannerClose} /> <div className={`${PREFIX}__close`} onClick={handlePartnerBannerClose} />
</div> </div>
{visible && <LoginDialog onCancel={() => setVisible(false)} onSuccess={handleBind} needPhone={needPhone} />} {visible && (
<LoginDialog disableCheck onCancel={() => setVisible(false)} onSuccess={handleBind} needPhone={needPhone} />
)}
</> </>
); );
} }

View File

@ -39,7 +39,9 @@ function JoinEntry({ onBindSuccess }: JoinEntryProps) {
</Button> </Button>
)} )}
</div> </div>
{visible && <LoginDialog onCancel={() => setVisible(false)} onSuccess={onBindSuccess} needPhone={needPhone} />} {visible && (
<LoginDialog disableCheck onCancel={() => setVisible(false)} onSuccess={onBindSuccess} needPhone={needPhone} />
)}
</> </>
); );
} }

View File

@ -125,7 +125,7 @@ function PartnerList(props: {
hasMore={hasMore} hasMore={hasMore}
onLoad={handleLoadMore} onLoad={handleLoadMore}
loading={loadingMore || refreshing} loading={loadingMore || refreshing}
disabled={loadMoreError} disabled={loadMoreError || !visible}
fixedHeight={typeof listHeight !== 'undefined'} fixedHeight={typeof listHeight !== 'undefined'}
style={listHeight ? { height: `${listHeight}px` } : undefined} style={listHeight ? { height: `${listHeight}px` } : undefined}
> >

View File

@ -1,14 +1,16 @@
import { Button, Image } from '@tarojs/components'; import { Button, Image } from '@tarojs/components';
import Taro, { useDidShow } from '@tarojs/taro';
import { Dialog } from '@taroify/core'; import { Dialog } from '@taroify/core';
import { Question } from '@taroify/icons'; import { Question } from '@taroify/icons';
import { useCallback, useState, useEffect } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { PageUrl } from '@/constants/app'; import { PageUrl } from '@/constants/app';
import { PartnerProfitsState } from '@/types/partner'; import { PartnerProfitsState } from '@/types/partner';
import { formatMoney, getPartnerProfitStat } from '@/utils/partner'; import { formatMoney, getPartnerProfitStat, withdrawMoney } from '@/utils/partner';
import { navigateTo } from '@/utils/route'; import { navigateTo } from '@/utils/route';
import Toast from '@/utils/toast'; import Toast from '@/utils/toast';
import './index.less'; import './index.less';
const PREFIX = 'partner-kanban'; const PREFIX = 'partner-kanban';
@ -31,14 +33,45 @@ function TipDialog(props: { open: boolean; onClose: () => void }) {
} }
function WithdrawDialog(props: { open: boolean; onClose: () => void; count: number }) { function WithdrawDialog(props: { open: boolean; onClose: () => void; count: number }) {
const handleWithdraw = useCallback(() => {}, []); const handleWithdraw = useCallback(async () => {
if (Taro.canIUse('requestMerchantTransfer')) {
try {
const result = await withdrawMoney();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
wx.requestMerchantTransfer({
mchId: '1642470088',
appId: 'wxf0724a83f8e377d2',
package: result.packageInfo,
success: (res: never) => {
// res.err_msg将在页面展示成功后返回应用时返回ok并不代表付款成功
console.log('success:', res);
Toast.success('提现成功');
props.onClose();
},
fail: (res: never) => {
Toast.error('提现失败');
console.log('fail:', res);
},
});
} catch (e) {
Toast.error('提现订单创建失败');
console.log(e);
}
} else {
await Taro.showModal({
content: '你的微信版本过低,请更新至最新版本。',
showCancel: false,
});
}
}, [props]);
return ( return (
<Dialog open={props.open} onClose={props.onClose}> <Dialog open={props.open} onClose={props.onClose}>
<Dialog.Content> <Dialog.Content>
<div className={`${PREFIX}-withdraw-dialog__container`}> <div className={`${PREFIX}-withdraw-dialog__container`}>
<div className={`${PREFIX}-withdraw-dialog__title`}></div> <div className={`${PREFIX}-withdraw-dialog__title`}></div>
<div className={`${PREFIX}-withdraw-dialog__count`}> <div className={`${PREFIX}-withdraw-dialog__count`}>
{props.count} {+props.count}
<div className="yuan"></div> <div className="yuan"></div>
</div> </div>
<div className={`${PREFIX}-withdraw-dialog__hint`}>500</div> <div className={`${PREFIX}-withdraw-dialog__hint`}>500</div>
@ -86,20 +119,24 @@ export default function PartnerKanban({ simple }: PartnerKanbanProps) {
const handleTipClose = useCallback(() => { const handleTipClose = useCallback(() => {
setTipOpen(false); setTipOpen(false);
}, []); }, []);
const handleViewWithdraw = useCallback(() => {
if (stats.availableBalance < 10 * 1000) {
Toast.info('提现金额需大于等于10元');
return;
}
setWithdrawOpen(true);
}, []);
const handleWithdrawClose = useCallback(() => {
setWithdrawOpen(false);
}, []);
const getProfitStats = useCallback(async () => { const getProfitStats = useCallback(async () => {
const data = await getPartnerProfitStat(); const data = await getPartnerProfitStat();
setStats(data); setStats(data);
}, []); }, []);
const handleViewWithdraw = useCallback(() => {
if (stats.availableBalance < 10 * 1000) {
Toast.error('提现金额需大于等于10元');
return;
}
setWithdrawOpen(true);
}, [stats.availableBalance]);
const handleWithdrawClose = useCallback(() => {
setWithdrawOpen(false);
getProfitStats();
}, [getProfitStats]);
useDidShow(() => {
getProfitStats();
});
useEffect(() => { useEffect(() => {
getProfitStats(); getProfitStats();
}, []); }, []);
@ -154,7 +191,13 @@ export default function PartnerKanban({ simple }: PartnerKanbanProps) {
)} )}
</div> </div>
{!simple && <TipDialog open={tipOpen} onClose={handleTipClose} />} {!simple && <TipDialog open={tipOpen} onClose={handleTipClose} />}
{!simple && <WithdrawDialog count={350} open={withdrawOpen} onClose={handleWithdrawClose} />} {!simple && (
<WithdrawDialog
count={Math.min(Number(formatMoney(stats.availableBalance)), 500)}
open={withdrawOpen}
onClose={handleWithdrawClose}
/>
)}
</div> </div>
); );
} }

View File

@ -96,7 +96,8 @@ function ProfitList(props: IPartnerProfitListProps) {
style={listHeight ? { height: `${listHeight}px` } : undefined} style={listHeight ? { height: `${listHeight}px` } : undefined}
> >
{dataList.map(item => { {dataList.map(item => {
const isChat = type === ProfitType.CHAT_SHARE || item.earnType.toString().toLowerCase().indexOf('chat') > -1; const isChat =
type === ProfitType.CHAT_SHARE || item.earnType.toString().toLowerCase().indexOf('chat') > -1;
return ( return (
<div className={`${PREFIX}__row`} key={item.id}> <div className={`${PREFIX}__row`} key={item.id}>
<div className={`${PREFIX}__row-content`}> <div className={`${PREFIX}__row-content`}>

View File

@ -78,10 +78,13 @@
&:last-child { &:last-child {
padding-right: 0; padding-right: 0;
} }
&.time, &.time {
&.project {
flex: 2; flex: 2;
} }
&.project {
width: 150px;
flex-shrink: 0;
}
&.status { &.status {
width: 96px; width: 96px;
padding: 0 8px; padding: 0 8px;

View File

@ -52,3 +52,9 @@ export const ProfitStatusDescriptions = {
OTHER: '', OTHER: '',
FINISHED: '已分账', FINISHED: '已分账',
}; };
export const WithdrawStatusDescriptions = {
0: '提现中',
1: '已提现',
2: '失败',
};

View File

@ -62,7 +62,7 @@ const getSalaryPrice = (fullSalary?: SalaryRange, partSalary?: SalaryRange) => {
function ProfileIntentionFragment(props: IProps, ref) { function ProfileIntentionFragment(props: IProps, ref) {
const { profile } = props; const { profile } = props;
const [cityCodes, setCityCodes] = useState(calcInitCityCodes(profile.cityCodes)); const [cityCodes, setCityCodes] = useState(calcInitCityCodes(profile.cityCodes || ''));
const [employType, setEmployType] = useState(profile.employType); const [employType, setEmployType] = useState(profile.employType);
const [fullSalary, setFullSalary] = useState(calcSalarySelect(profile, true)); const [fullSalary, setFullSalary] = useState(calcSalarySelect(profile, true));
const [partSalary, setPartSalary] = useState(calcSalarySelect(profile, false)); const [partSalary, setPartSalary] = useState(calcSalarySelect(profile, false));

View File

@ -1,7 +1,7 @@
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { selectRoleType } from '@/store/selector';
import { RoleType } from '@/constants/app'; import { RoleType } from '@/constants/app';
import { selectRoleType } from '@/store/selector';
function useRoleType() { function useRoleType() {
return useSelector(selectRoleType) || RoleType.Anchor; return useSelector(selectRoleType) || RoleType.Anchor;

View File

@ -82,4 +82,6 @@ export enum API {
BECOME_PARTNER = '/user/becomePartner', BECOME_PARTNER = '/user/becomePartner',
GET_PROFIT_LIST = '/user/profit/list', GET_PROFIT_LIST = '/user/profit/list',
GET_PROFIT_STAT = '/user/profits', GET_PROFIT_STAT = '/user/profits',
WITHDRAW = '/user/withdraw',
GET_WITHDRAW_LIST = '/user/withdraw/records',
} }

View File

@ -31,7 +31,7 @@ import {
PostMessageRequest, PostMessageRequest,
} from '@/types/message'; } from '@/types/message';
import { isAnchorMode } from '@/utils/app'; import { isAnchorMode } from '@/utils/app';
import { getScrollItemId, last, logWithPrefix } from '@/utils/common'; import { getScrollItemId, last, logWithPrefix, safeJsonParse } from '@/utils/common';
import { collectEvent } from '@/utils/event'; import { collectEvent } from '@/utils/event';
import { import {
isExchangeMessage, isExchangeMessage,
@ -55,6 +55,7 @@ import Toast from '@/utils/toast';
import { getUserId } from '@/utils/user'; import { getUserId } from '@/utils/user';
import './index.less'; import './index.less';
import useUserInfo from '@/hooks/use-user-info';
const PREFIX = 'page-message-chat'; const PREFIX = 'page-message-chat';
const LIST_CONTAINER_CLASS = `${PREFIX}__chat-list`; const LIST_CONTAINER_CLASS = `${PREFIX}__chat-list`;
@ -85,8 +86,19 @@ const getHeaderLeftButtonText = (job?: IJobMessage, material?: IMaterialMessage)
return isAnchorMode() ? '不感兴趣' : '标记为不合适'; return isAnchorMode() ? '不感兴趣' : '标记为不合适';
}; };
const getResumeId = (messages: IChatMessage[], userId?: string) => {
const resumeStr = messages.find(it => it.type === MessageType.Material && it.senderUserId !== userId)?.actionObject;
if (resumeStr) {
const { id } = safeJsonParse(resumeStr);
log('resumeId', id);
return id;
}
return undefined;
};
export default function MessageChat() { export default function MessageChat() {
const listHeight = useListHeight(CALC_LIST_PROPS); const listHeight = useListHeight(CALC_LIST_PROPS);
const { userId } = useUserInfo();
const [input, setInput] = useState(''); const [input, setInput] = useState('');
const [showMore, setShowMore] = useState(false); const [showMore, setShowMore] = useState(false);
const [chat, setChat] = useState<IChatInfo | null>(null); const [chat, setChat] = useState<IChatInfo | null>(null);
@ -96,6 +108,7 @@ export default function MessageChat() {
const [messageStatusList, setMessageStatusList] = useState<IMessageStatus[]>([]); const [messageStatusList, setMessageStatusList] = useState<IMessageStatus[]>([]);
const [jobId, setJobId] = useState<string>(); const [jobId, setJobId] = useState<string>();
const [job, setJob] = useState<IJobMessage>(); const [job, setJob] = useState<IJobMessage>();
const [resumeId, setResumeId] = useState<string | undefined>();
const [material, setMaterial] = useState<IMaterialMessage>(); const [material, setMaterial] = useState<IMaterialMessage>();
const [scrollItemId, setScrollItemId] = useState<string>(); const [scrollItemId, setScrollItemId] = useState<string>();
const scrollToLowerRef = useRef(false); const scrollToLowerRef = useRef(false);
@ -252,6 +265,14 @@ export default function MessageChat() {
// }; // };
// }, []); // }, []);
useEffect(() => {
if (resumeId) {
return;
}
setResumeId(getResumeId(messages, userId));
}, [messages, resumeId, userId]);
useEffect(() => { useEffect(() => {
if (!chat) { if (!chat) {
return; return;
@ -353,6 +374,7 @@ export default function MessageChat() {
id={message.msgId} id={message.msgId}
key={message.msgId} key={message.msgId}
message={message} message={message}
resumeId={resumeId}
isRead={messageStatusList.some(m => m.msgId === message.msgId && !!m.isRead)} isRead={messageStatusList.some(m => m.msgId === message.msgId && !!m.isRead)}
/> />
); );

View File

@ -1,20 +1,23 @@
import { useShareAppMessage } from '@tarojs/taro'; import { useShareAppMessage } from '@tarojs/taro';
import { Tabs } from '@taroify/core'; import { Tabs } from '@taroify/core';
import { useState } from 'react';
import PartnerIntro from '@/components/partner-intro'; import PartnerIntro from '@/components/partner-intro';
import PartnerInviteList from '@/components/partner-invite-list'; import PartnerInviteList from '@/components/partner-invite-list';
import PartnerProfit from '@/components/partner-profit'; import PartnerProfit from '@/components/partner-profit';
import useInviteCode from '@/hooks/use-invite-code'; import useInviteCode from '@/hooks/use-invite-code';
import { getCommonShareMessage } from '@/utils/share'; import { getCommonShareMessage } from '@/utils/share';
import './index.less'; import './index.less';
const PREFIX = 'partner'; const PREFIX = 'partner';
export default function Partner() { export default function Partner() {
const inviteCode = useInviteCode(); const inviteCode = useInviteCode();
const [tab, setTab] = useState<number>(0);
const handleChange = v => {
setTab(v);
};
useShareAppMessage(() => { useShareAppMessage(() => {
console.log('Partner inviteCode', inviteCode); console.log('Partner inviteCode', inviteCode);
return getCommonShareMessage(false, inviteCode); return getCommonShareMessage(false, inviteCode);
@ -22,12 +25,12 @@ export default function Partner() {
return ( return (
<div className={PREFIX}> <div className={PREFIX}>
<Tabs className={`${PREFIX}__tabs`}> <Tabs className={`${PREFIX}__tabs`} value={tab} onChange={handleChange}>
<Tabs.TabPane value={0} title="简介"> <Tabs.TabPane value={0} title="简介">
<PartnerIntro /> <PartnerIntro />
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane value={1} title="邀请名单"> <Tabs.TabPane value={1} title="邀请名单">
<PartnerInviteList /> <PartnerInviteList refreshDisabled={tab !== 1} visible={tab === 1} />
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane value={2} title="我的收益"> <Tabs.TabPane value={2} title="我的收益">
<PartnerProfit /> <PartnerProfit />

View File

@ -2,4 +2,52 @@
@import '@/styles/variables.less'; @import '@/styles/variables.less';
.withdraw-record { .withdraw-record {
&__item {
height: 131px;
width: 100%;
background: #fff;
padding: 24px 32px 0 32px;
box-sizing: border-box;
font-size: 28px;
&-border {
border-bottom: 1px solid #e6e7e8;
}
&-content {
.flex-row();
width: 100%;
padding-bottom: 24px;
}
&-time {
padding-right: 8px;
line-height: 40px;
flex: 1;
.noWrap();
}
&-withdraw {
width: 200px;
text-align: right;
padding-left: 8px;
flex-shrink: 0;
}
&-money {
line-height: 40px;
padding-bottom: 8px;
.noWrap();
font-weight: 600;
font-size: 30px;
color: #ff5051;
}
&-status {
font-size: 24px;
line-height: 36px;
color: #999999;
.noWrap();
}
}
} }

View File

@ -1,14 +1,119 @@
import { useShareAppMessage } from '@tarojs/taro'; import { useShareAppMessage } from '@tarojs/taro';
import { List, PullRefresh } from '@taroify/core';
import { useCallback, useEffect, useRef, useState } from 'react';
import ListPlaceholder from '@/components/list-placeholder';
import { WithdrawStatusDescriptions } from '@/constants/partner';
import useInviteCode from '@/hooks/use-invite-code';
import { WithdrawRecord } from '@/types/partner';
import { logWithPrefix } from '@/utils/common';
import { formatMoney, formatTimestamp, getWithdrawList as requestData } from '@/utils/partner';
import { getCommonShareMessage } from '@/utils/share'; import { getCommonShareMessage } from '@/utils/share';
import './index.less'; import './index.less';
const PREFIX = 'withdraw-record'; const PREFIX = 'withdraw-record';
const log = logWithPrefix(PREFIX);
const FIRST_PAGE = 0;
export default function WithdrawRecord() { export default function WithdrawRecords() {
const inviteCode = useInviteCode();
const [hasMore, setHasMore] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [loadingMore, setLoadingMore] = useState(false);
const [loadMoreError, setLoadMoreError] = useState(false);
const [dataList, setDataList] = useState<WithdrawRecord[]>([]);
const currentPage = useRef<number>(FIRST_PAGE);
const handleRefresh = useCallback(async () => {
log('start pull refresh');
try {
setRefreshing(true);
setLoadMoreError(false);
const { content, totalPages } = await requestData({ page: 1 });
setDataList(content);
currentPage.current = 1;
setHasMore(currentPage.current < totalPages);
log('pull refresh success');
} catch (e) {
setDataList([]);
setHasMore(false);
setLoadMoreError(true);
currentPage.current = FIRST_PAGE;
log('pull refresh failed');
} finally {
setRefreshing(false);
}
}, []);
const handleLoadMore = useCallback(async () => {
log('start load more', hasMore);
if (!hasMore) {
return;
}
setLoadMoreError(false);
setLoadingMore(true);
try {
const { totalPages, content } = await requestData({ page: currentPage.current + 1 });
setDataList([...dataList, ...content]);
currentPage.current = currentPage.current + 1;
setHasMore(currentPage.current < totalPages);
log('load more success');
} catch (e) {
setLoadMoreError(true);
log('load more failed');
} finally {
setLoadingMore(false);
}
}, [dataList, hasMore]);
// 初始化数据&配置变更后刷新数据
useEffect(() => {
const refresh = async () => {
log('visible changed, start refresh list data');
try {
setDataList([]);
setLoadingMore(true);
setLoadMoreError(false);
const { totalPages, content } = await requestData({ page: 1 });
setDataList(content);
currentPage.current = 1;
setHasMore(currentPage.current < totalPages);
} catch (e) {
setDataList([]);
setHasMore(false);
setLoadMoreError(true);
} finally {
log('visible changed, refresh list data end');
setLoadingMore(false);
}
};
refresh();
}, []);
useShareAppMessage(() => { useShareAppMessage(() => {
return getCommonShareMessage(false); return getCommonShareMessage(false, inviteCode);
}); });
return <div className={PREFIX}></div>; return (
<div className={PREFIX}>
<PullRefresh className={`${PREFIX}__pull-refresh`} loading={refreshing} onRefresh={handleRefresh}>
<List hasMore={hasMore} onLoad={handleLoadMore} loading={loadingMore || refreshing} disabled={loadMoreError}>
{dataList.map(item => (
<div className={`${PREFIX}__item`} key={item.id || item.userId}>
<div className={`${PREFIX}__item-border`}>
<div className={`${PREFIX}__item-content`}>
<div className={`${PREFIX}__item-time`}>{formatTimestamp(item.created)}</div>
<div className={`${PREFIX}__item-withdraw`}>
<div className={`${PREFIX}__item-money`}>{formatMoney(item.amt)}</div>
<div className={`${PREFIX}__item-status`}>{WithdrawStatusDescriptions[item.status]}</div>
</div>
</div>
</div>
</div>
))}
<ListPlaceholder hasMore={false} loadingMore={loadingMore} loadMoreError={loadMoreError} />
</List>
</PullRefresh>
</div>
);
} }

View File

@ -64,3 +64,26 @@ export interface PartnerProfitItem {
expectedSettlementDate: string; expectedSettlementDate: string;
actualSettlementDate: string; actualSettlementDate: string;
} }
export interface WithdrawResponse {
outBillNo: string;
transferBillNo: string;
createTime: string;
state: string;
packageInfo: string;
}
export interface WithdrawRecord {
id: number;
userId: string;
orderNo: string;
outTradeId: string;
amt: number;
status: number;
remark: string;
created: string;
updated: string;
finishedTime: string;
}
export interface PartnerPagination<T> {
content: T[];
totalPages: number;
}

View File

@ -10,8 +10,11 @@ import {
GetProfitRequest, GetProfitRequest,
InviteUserInfo, InviteUserInfo,
PartnerInviteCode, PartnerInviteCode,
PartnerPagination,
PartnerProfitItem, PartnerProfitItem,
PartnerProfitsState, PartnerProfitsState,
WithdrawRecord,
WithdrawResponse,
} from '@/types/partner'; } from '@/types/partner';
import { requestUserInfo } from '@/utils/user'; import { requestUserInfo } from '@/utils/user';
@ -53,7 +56,7 @@ export const getPartnerProfitStat = async () => {
return await http.post<PartnerProfitsState>(API.GET_PROFIT_STAT); return await http.post<PartnerProfitsState>(API.GET_PROFIT_STAT);
}; };
export const getPartnerInviteList = async (data: IPaginationRequest) => { export const getPartnerInviteList = async (data: IPaginationRequest) => {
return await http.post<{ content: InviteUserInfo[]; totalPages: number }>(API.GET_INVITE_LIST, { return await http.post<PartnerPagination<InviteUserInfo>>(API.GET_INVITE_LIST, {
data, data,
contentType: 'application/x-www-form-urlencoded', contentType: 'application/x-www-form-urlencoded',
}); });
@ -113,3 +116,14 @@ export function formatUserId(input: string): string {
// 拼接结果 // 拼接结果
return beforeMask + maskedPart + afterMask; return beforeMask + maskedPart + afterMask;
} }
export async function withdrawMoney() {
return await http.post<WithdrawResponse>(API.WITHDRAW);
}
export async function getWithdrawList(data: IPaginationRequest) {
return await http.post<PartnerPagination<WithdrawRecord>>(API.GET_WITHDRAW_LIST, {
data,
contentType: 'application/x-www-form-urlencoded',
});
}