feat: update of partner

This commit is contained in:
eleanor.mao
2025-05-15 01:02:00 +08:00
parent 7aafc3a789
commit d2ac64f20c
52 changed files with 1435 additions and 265 deletions

View File

@ -0,0 +1,41 @@
@import '@/styles/variables.less';
@import '@/styles/common.less';
.partner-fragment-banner {
width: 100%;
height: 90px;
position: relative;
margin-bottom: 24px;
&__image {
width: 100%;
height: 100%;
}
&__btn {
width: 100%;
height: 100%;
position: absolute;
left: 0;
padding: 0;
margin: 0;
top: 0;
font-size: 0;
background: transparent;
border: none;
&::after {
border: none;
}
&:active {
background: transparent;
}
}
&__close {
width: 64px;
height: 38px;
position: absolute;
right: 0;
top: 0;
}
}

View File

@ -0,0 +1,66 @@
import { Button, Image } from '@tarojs/components';
import { useCallback, useState } from 'react';
import LoginDialog from '@/components/login-dialog';
import { PageUrl } from '@/constants/app';
import useUserInfo from '@/hooks/use-user-info';
import { becomePartner, getPartnerBannerClose, setPartnerBannerClose } from '@/utils/partner';
import { navigateTo } from '@/utils/route';
import { isNeedPhone } from '@/utils/user';
import './index.less';
const PREFIX = 'partner-fragment-banner';
export default function PartnerBanner() {
const userInfo = useUserInfo();
const needPhone = isNeedPhone(userInfo);
const isPartner = userInfo.isPartner;
const [visible, setVisible] = useState(false);
const [bannerClose, setBannerClose] = useState<boolean>(getPartnerBannerClose());
const handlePartnerBannerClose = useCallback(e => {
e.preventDefault();
e.stopPropagation();
setBannerClose(true);
setPartnerBannerClose();
}, []);
const handleBind = useCallback(async () => {
if (!isPartner) {
await becomePartner();
}
await navigateTo(PageUrl.Partner);
}, [isPartner]);
const handleClick = useCallback(async () => {
if (needPhone) {
return;
}
await handleBind();
}, [handleBind, needPhone]);
if (bannerClose) {
return null;
}
return (
<>
<div className={PREFIX} onClick={handleClick}>
<Image
className={`${PREFIX}__image`}
src="https://publiccdn.neighbourhood.com.cn/img/partner_banner.png"
mode="scaleToFill"
/>
{needPhone && (
<Button className={`${PREFIX}__btn`} onClick={() => setVisible(true)}>
placeholder
</Button>
)}
<div className={`${PREFIX}__close`} onClick={handlePartnerBannerClose} />
</div>
{visible && <LoginDialog onCancel={() => setVisible(false)} onSuccess={handleBind} needPhone={needPhone} />}
</>
);
}

View File

@ -44,87 +44,4 @@
color: @blHighlightColor;
}
}
&__kanban {
border-radius: 16px;
margin-bottom: 24px;
position: relative;
background: #6d3df5;
color: #fff;
&-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
&-content {
position: relative;
min-height: 280px;
box-sizing: border-box;
padding: 36px 40px;
z-index: 1;
}
&-button {
position: absolute;
z-index: 2;
top: 44px;
right: 56px;
font-size: 24px;
line-height: 24px;
&__image {
width: 20px;
height: 20px;
display: inline-block;
margin-left: 4px;
}
}
&-title {
font-style: normal;
font-weight: 400;
letter-spacing: 0.02em;
opacity: 0.7;
}
&-money {
font-family: 'Helvetica Neue';
font-style: normal;
font-weight: 700;
}
&-total {
margin-bottom: 24px;
.partner-fragment-entry__kanban {
&-title {
font-size: 26px;
line-height: 40px;
margin-bottom: 12px;
}
&-money {
font-size: 48px;
line-height: 42px;
}
}
}
&-details {
.flex-row();
&-part {
flex: 1;
.partner-fragment-entry__kanban {
&-title {
font-size: 24px;
line-height: 36px;
margin-bottom: 4px;
}
&-money {
font-size: 32px;
line-height: 42px;
}
}
}
}
}
}

View File

@ -1,12 +1,12 @@
import { BaseEventOrig, Button, ButtonProps, Image } from '@tarojs/components';
import { Button } from '@tarojs/components';
import { useCallback, useState } from 'react';
import { PageUrl } from '@/constants/app';
import LoginDialog from '@/components/login-dialog';
import PartnerKanban from '@/components/partner-kanban';
import useUserInfo from '@/hooks/use-user-info';
import { navigateTo } from '@/utils/route';
import Toast from '@/utils/toast';
import { requestUserInfo, setPhoneNumber } from '@/utils/user';
import { becomePartner } from '@/utils/partner';
import { isNeedPhone, requestUserInfo } from '@/utils/user';
import './index.less';
const PREFIX = 'partner-fragment-entry';
@ -16,93 +16,42 @@ type JoinEntryProps = {
};
function JoinEntry({ onBindSuccess }: JoinEntryProps) {
const userInfo = useUserInfo();
const needPhone = isNeedPhone(userInfo);
const [visible, setVisible] = useState(false);
const hasPhone = !!userInfo.phone;
const handleGetPhoneNumber = useCallback(async (e: BaseEventOrig<ButtonProps.onGetPhoneNumberEventDetail>) => {
const encryptedData = e.detail.encryptedData;
const iv = e.detail.iv;
if (!encryptedData || !iv) {
return Toast.error('取消授权');
}
try {
await setPhoneNumber({ encryptedData, iv });
await requestUserInfo();
Toast.success('绑定成功');
onBindSuccess();
} catch (err) {
Toast.error('绑定失败');
}
}, []);
return (
<div className={`${PREFIX}__join`}>
<div className={`${PREFIX}__join-title`}>
<span className="highlight">75%</span>
<>
<div className={`${PREFIX}__join`}>
<div className={`${PREFIX}__join-title`}>
<span className="highlight">75%</span>
</div>
<div className={`${PREFIX}__join-desc`}></div>
{!needPhone && (
<Button className={`${PREFIX}__join-button`} onClick={onBindSuccess}>
</Button>
)}
{needPhone && (
<Button className={`${PREFIX}__join-button`} onClick={() => setVisible(true)}>
</Button>
)}
</div>
<div className={`${PREFIX}__join-desc`}></div>
{hasPhone && (
<Button className={`${PREFIX}__join-button`} onClick={onBindSuccess}>
</Button>
)}
{!hasPhone && (
<Button className={`${PREFIX}__join-button`} openType="getPhoneNumber" onGetPhoneNumber={handleGetPhoneNumber}>
</Button>
)}
</div>
);
}
function PartnerKanban() {
const handleNavigate = useCallback(() => {
navigateTo(PageUrl.Partner);
}, []);
return (
<div className={`${PREFIX}__kanban`}>
<Image className={`${PREFIX}__kanban-bg`} src={require('@/statics/png/partner_bg.png')} mode="scaleToFill" />
<div className={`${PREFIX}__kanban-content`}>
<div className={`${PREFIX}__kanban-button`} onClick={handleNavigate}>
<Image
className={`${PREFIX}__kanban-button__image`}
mode="aspectFit"
src={require('@/statics/svg/caret-right.svg')}
/>
</div>
<div className={`${PREFIX}__kanban-total`}>
<div className={`${PREFIX}__kanban-title`}></div>
<div className={`${PREFIX}__kanban-money`}>1666.66</div>
</div>
<div className={`${PREFIX}__kanban-details`}>
<div className={`${PREFIX}__kanban-details-part`}>
<div className={`${PREFIX}__kanban-title`}></div>
<div className={`${PREFIX}__kanban-money`}>666.23</div>
</div>
<div className={`${PREFIX}__kanban-details-part`}>
<div className={`${PREFIX}__kanban-title`}></div>
<div className={`${PREFIX}__kanban-money`}>666.23</div>
</div>
<div className={`${PREFIX}__kanban-details-part`}>
<div className={`${PREFIX}__kanban-title`}></div>
<div className={`${PREFIX}__kanban-money`}>666.23</div>
</div>
</div>
</div>
</div>
{visible && <LoginDialog onCancel={() => setVisible(false)} onSuccess={onBindSuccess} needPhone={needPhone} />}
</>
);
}
export default function PartnerEntry() {
const [state, setState] = useState(1);
// TODO: 开通状态检查
const handleBindSuccess = useCallback(() => {
setState(0);
const userInfo = useUserInfo();
const handleBindSuccess = useCallback(async () => {
await becomePartner();
await requestUserInfo();
}, []);
if (state === 0) {
return <JoinEntry onBindSuccess={handleBindSuccess} />;
if (userInfo.isPartner) {
return <PartnerKanban simple />;
}
return <PartnerKanban />;
return <JoinEntry onBindSuccess={handleBindSuccess} />;
}

View File

@ -12,8 +12,8 @@
line-height: 88px;
text-align: center;
font-size: 28px;
position: absolute;
top: 0;
position: fixed;
top: 98px;
left: 0;
right: 0;
width: 100vw;
@ -121,3 +121,10 @@
margin-left: 32px;
}
}
#posterCanvas {
position: fixed;
bottom: -99999px;
left: -99999px;
visibility: hidden;
}

View File

@ -1,12 +1,120 @@
import { Button } from '@tarojs/components';
import { Button, Canvas } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { useCallback } from 'react';
import { useCallback, useState } from 'react';
import { openCustomerServiceChat } from '@/utils/common';
import { getPartnerQrcode } from '@/utils/partner';
import './index.less';
const PREFIX = 'partner-intro';
export default function PartnerIntro() {
const [posterPath, setPosterPath] = useState('');
const getQrcode = async () => {
try {
const data = await getPartnerQrcode(); // 假设 getPartnerQrcode 返回 ArrayBuffer
const base64 = Taro.arrayBufferToBase64(data);
return `data:image/png;base64,${base64}`;
} catch (error) {
console.error('获取二维码失败', error);
Taro.showToast({ title: '获取二维码失败', icon: 'none' });
throw error;
}
};
const saveCanvasToTempFile = (): Promise<string> => {
return new Promise((resolve, reject) => {
try {
const query = Taro.createSelectorQuery().select('#posterCanvas');
query.fields({ node: true }).exec(async res => {
const canvas = res[0].node;
const tempFilePath = await Taro.canvasToTempFilePath({
canvas,
x: 0,
y: 0,
width: 1500, // 实际绘制宽度
height: 2668, // 实际绘制高度
destWidth: 750, // 目标显示宽度
destHeight: 1334, // 目标显示高度
fileType: 'jpg',
});
setPosterPath(tempFilePath.tempFilePath);
resolve(tempFilePath.tempFilePath);
});
} catch (error) {
console.error('保存 Canvas 到临时文件失败', error);
Taro.showToast({ title: '保存 Canvas 失败', icon: 'none' });
reject(error);
}
});
};
const drawCanvas = (qrCode: string): Promise<string> => {
const query = Taro.createSelectorQuery().select('#posterCanvas');
return new Promise(resolve => {
query.fields({ node: true, size: true }).exec(async res => {
const canvas = res[0].node;
const ctx = canvas.getContext('2d');
canvas.width = 1500;
canvas.height = 2668;
ctx.scale(2, 2);
// 绘制背景图片
const bgImage = canvas.createImage();
const poster = 'https://publiccdn.neighbourhood.com.cn/img/poster.png'
bgImage.src = poster;
bgImage.onload = () => {
ctx.drawImage(bgImage, 0, 0, 750, 1334);
const qrCodeImage = canvas.createImage();
qrCodeImage.src = qrCode; // 假设 getQrcode() 返回的是二维码图片的路径
qrCodeImage.onload = () => {
ctx.drawImage(qrCodeImage, 235, 894, 280, 280); // 绘制二维码,位置和大小
saveCanvasToTempFile().then(tempPath => {
resolve(tempPath);
});
};
};
bgImage.onerror = err => {
console.error(err);
};
});
});
};
const savePoster = async () => {
let filePath = posterPath;
if (!filePath) {
Taro.showLoading({ title: '正在生成海报' });
const qrCode = await getQrcode();
filePath = await drawCanvas(qrCode);
Taro.hideLoading();
}
const res = await Taro.getSetting();
const hasPermission = res.authSetting['scope.writePhotosAlbum'];
if (hasPermission === false) {
Taro.showModal({
title: '提示',
content: '需要访问相册权限才能保存图片,请前往设置开启权限',
showCancel: false,
success() {
Taro.openSetting();
},
});
} else {
try {
await Taro.authorize({ scope: 'scope.writePhotosAlbum' });
await Taro.saveImageToPhotosAlbum({ filePath });
Taro.showToast({ title: '保存成功', icon: 'success' });
} catch (error) {
console.error(error);
Taro.showToast({ title: '保存失败', icon: 'none' });
}
}
};
const handleOpenService = useCallback(() => {
openCustomerServiceChat('https://work.weixin.qq.com/kfid/kfc4fcf6b109b3771d7');
}, []);
@ -45,17 +153,16 @@ export default function PartnerIntro() {
<div className={`${PREFIX}__tip`}></div>
</div>
</div>
</div>
);
}
<Canvas id="posterCanvas" canvas-id="posterCanvas" type="2d" style="width: 750px; height: 1334px;" />
export function PartnerIntroFooter() {
return (
<div className={`${PREFIX}__footer`}>
<Button className={`${PREFIX}__download-button`}></Button>
<Button className={`${PREFIX}__share-button`} openType="share">
</Button>
<div className={`${PREFIX}__footer`}>
<Button className={`${PREFIX}__download-button`} onClick={savePoster}>
</Button>
<Button className={`${PREFIX}__share-button`} openType="share">
</Button>
</div>
</div>
);
}

View File

@ -0,0 +1,86 @@
@import '@/styles/common.less';
.partner-invite-list {
padding-top: 72px;
&__title {
height: 72px;
width: 100%;
background: #f7f7f7;
padding: 0 24px;
box-sizing: border-box;
line-height: 72px;
font-size: 24px;
color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 98rpx;
left: 0;
z-index: 1;
.flex-row();
&-time-id {
padding: 0 8px;
flex: 1;
}
&-created {
padding: 0 8px;
min-width: 96px;
max-width: 196px;
flex-shrink: 0;
}
&-joined {
text-align: right;
width: 96px;
padding: 0 8px;
flex-shrink: 0;
}
}
&__item {
height: 131px;
width: 100%;
background: #fff;
padding: 24px 32px;
box-sizing: border-box;
font-size: 28px;
&-content {
.flex-row();
width: 100%;
border-bottom: 1px solid #e6e7e8;
}
&-time-id {
padding-right: 8px;
flex: 1;
}
&-item {
line-height: 40px;
padding-bottom: 8px;
.noWrap();
}
&-id {
font-size: 24px;
line-height: 36px;
color: #999999;
.noWrap();
}
&-created {
padding: 0 8px;
min-width: 96px;
max-width: 196px;
line-height: 83px;
flex-shrink: 0;
}
&-joined {
width: 96px;
text-align: right;
line-height: 83px;
padding-left: 8px;
flex-shrink: 0;
}
}
}

View File

@ -0,0 +1,119 @@
import { List, PullRefresh } from '@taroify/core';
import classNames from 'classnames';
import { useCallback, useEffect, useRef, useState } from 'react';
import ListPlaceholder from '@/components/list-placeholder';
import { InviteUserInfo } from '@/types/partner';
import { logWithPrefix } from '@/utils/common';
import { formatTimestamp, formatUserId, getPartnerInviteList as requestData } from '@/utils/partner';
import './index.less';
const PREFIX = 'partner-invite-list';
const log = logWithPrefix(PREFIX);
function PartnerList(props: {
refreshDisabled?: boolean;
visible?: boolean;
listHeight?: number;
className?: string;
onListEmpty?: () => void;
}) {
const { className, listHeight, refreshDisabled, visible = true, onListEmpty } = props;
const [refreshing, setRefreshing] = useState(false);
const [loadingMore, setLoadingMore] = useState(false);
const [loadMoreError, setLoadMoreError] = useState(false);
const [dataList, setDataList] = useState<InviteUserInfo[]>([]);
const onListEmptyRef = useRef(onListEmpty);
const handleRefresh = useCallback(async () => {
log('start pull refresh');
try {
setRefreshing(true);
setLoadMoreError(false);
const list = await requestData();
setDataList(list);
!list.length && onListEmptyRef.current?.();
log('pull refresh success');
} catch (e) {
setDataList([]);
setLoadMoreError(true);
log('pull refresh failed');
} finally {
setRefreshing(false);
}
}, []);
useEffect(() => {
onListEmptyRef.current = onListEmpty;
}, [onListEmpty]);
// 初始化数据&配置变更后刷新数据
useEffect(() => {
// 列表不可见时,先不做处理
if (!visible) {
log('visible changed, but is not visible, only clear list');
return;
}
const refresh = async () => {
log('visible changed, start refresh list data');
try {
setDataList([]);
setLoadingMore(true);
setLoadMoreError(false);
const list = await requestData();
setDataList(list);
!list.length && onListEmptyRef.current?.();
} catch (e) {
setDataList([]);
setLoadMoreError(true);
} finally {
log('visible changed, refresh list data end');
setLoadingMore(false);
}
};
refresh();
}, [visible]);
return (
<div className={PREFIX}>
<div className={`${PREFIX}__title`}>
<div className={`${PREFIX}__title-time-id`}></div>
<div className={`${PREFIX}__title-created`}></div>
<div className={`${PREFIX}__title-joined`}></div>
</div>
<PullRefresh
className={classNames(`${PREFIX}__pull-refresh`, className)}
loading={refreshing}
onRefresh={handleRefresh}
disabled={refreshDisabled}
>
<List
hasMore={false}
onLoad={() => {}}
loading={loadingMore || refreshing}
disabled={loadMoreError}
fixedHeight={typeof listHeight !== 'undefined'}
style={listHeight ? { height: `${listHeight}px` } : undefined}
>
{dataList.map(item => (
<div className={`${PREFIX}__item`} key={item.id || item.userId}>
<div className={`${PREFIX}__item-content`}>
<div className={`${PREFIX}__item-time-id`}>
<div className={`${PREFIX}__item-time`}>{formatTimestamp(item.created)}</div>
<div className={`${PREFIX}__item-id`}>{formatUserId(item.userId)}</div>
</div>
<div className={`${PREFIX}__item-created`}>{item.isCreateResume ? '已创建' : '未创建'}</div>
<div className={`${PREFIX}__item-joined`}>{item.isPartner ? '已加入' : '未加入'}</div>
</div>
</div>
))}
<ListPlaceholder hasMore={false} loadingMore={loadingMore} loadMoreError={loadMoreError} />
</List>
</PullRefresh>
</div>
);
}
export default PartnerList;

View File

@ -0,0 +1,174 @@
@import '@/styles/variables.less';
@import '@/styles/common.less';
.partner-kanban {
border-radius: 16px;
margin-bottom: 24px;
position: relative;
background: #6d3df5;
color: #fff;
&__simple {
}
&__bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
border-radius: 16px;
height: 100%;
}
&__content {
position: relative;
min-height: 280px;
box-sizing: border-box;
padding: 36px 40px;
z-index: 1;
}
&__button {
position: absolute;
z-index: 2;
top: 44px;
right: 56px;
font-size: 24px;
line-height: 24px;
&-image {
width: 20px;
height: 20px;
display: inline-block;
margin-left: 4px;
}
}
&__title {
font-style: normal;
font-weight: 400;
letter-spacing: 0.02em;
opacity: 0.7;
}
&__money {
font-family: 'Helvetica Neue';
font-style: normal;
font-weight: 700;
}
&__total {
margin-bottom: 24px;
.partner-kanban {
&__title {
font-size: 26px;
line-height: 40px;
margin-bottom: 12px;
}
&__money {
font-size: 48px;
line-height: 42px;
}
}
}
&__details {
.flex-row();
&-part {
flex: 1;
.partner-kanban {
&__title {
font-size: 24px;
line-height: 36px;
margin-bottom: 4px;
}
&__money {
font-size: 32px;
line-height: 42px;
}
}
}
}
&__buttons {
margin-top: 30px;
.flex-row();
gap: 24px;
}
&__withdraw {
.button(@height: 72px; @borderRadius: 8px; @highlight: 0);
background: #fff;
flex: 1;
}
&__record {
.button(@height: 72px; @borderRadius: 8px; @highlight: 1);
background: #b6bef4;
flex: 1;
}
&-tip-dialog {
&__container {
.flex-column();
}
&__title {
font-size: 28px;
line-height: 42px;
color: #000;
}
&__confirm-button {
.button(@width: 360px, @height: 72px, @fontSize: 28px, @fontWeight: 400, @borderRadius: 44px);
margin-top: 40px;
}
}
&-withdraw-dialog {
&__container {
.flex-column();
color: @blColor;
}
&__title {
font-weight: 500;
font-size: 36px;
line-height: 57px;
text-align: center;
margin-bottom: 32px;
}
&__count {
font-weight: 500;
font-size: 80px;
line-height: 57px;
text-align: center;
margin-bottom: 38px;
.yuan {
display: inline-block;
margin-left: 8px;
font-size: 28px;
font-weight: 500;
}
}
&__hint {
font-weight: 500;
font-size: 24px;
line-height: 36px;
text-align: center;
color: @blColorG1;
margin-bottom: 40px;
}
&__confirm-button {
.button(@width: 360px, @height: 72px, @fontSize: 28px, @fontWeight: 400, @borderRadius: 44px);
margin-bottom: 40px;
}
&__cancel-button {
width: 204px;
height: 39px;
text-align: center;
font-weight: 400;
font-size: 28px;
line-height: 39px;
color: @blHighlightColor;
}
}
}

View File

@ -0,0 +1,148 @@
import { Button, Image } from '@tarojs/components';
import { Dialog } from '@taroify/core';
import { Question } from '@taroify/icons';
import { useCallback, useState, useEffect } from 'react';
import { PageUrl } from '@/constants/app';
import { PartnerProfitsState } from '@/types/partner';
import { formatMoney, getPartnerProfitStat } from '@/utils/partner';
import { navigateTo } from '@/utils/route';
import './index.less';
const PREFIX = 'partner-kanban';
function TipDialog(props: { open: boolean; onClose: () => void }) {
return (
<Dialog open={props.open} onClose={props.onClose}>
<Dialog.Content>
<div className={`${PREFIX}-tip-dialog__container`}>
<div
className={`${PREFIX}-tip-dialog__title`}
>{`会员支付的收益无需提现,\n支付15日后自动分账至微信零钱`}</div>
<Button className={`${PREFIX}-tip-dialog__confirm-button`} onClick={props.onClose}>
</Button>
</div>
</Dialog.Content>
</Dialog>
);
}
function WithdrawDialog(props: { open: boolean; onClose: () => void; count: number }) {
const handleWithdraw = useCallback(() => {}, []);
return (
<Dialog open={props.open} onClose={props.onClose}>
<Dialog.Content>
<div className={`${PREFIX}-withdraw-dialog__container`}>
<div className={`${PREFIX}-withdraw-dialog__title`}></div>
<div className={`${PREFIX}-withdraw-dialog__count`}>
{props.count}
<div className="yuan"></div>
</div>
<div className={`${PREFIX}-withdraw-dialog__hint`}>500</div>
<Button className={`${PREFIX}-withdraw-dialog__confirm-button`} onClick={handleWithdraw}>
</Button>
<div className={`${PREFIX}-withdraw-dialog__cancel-button`} onClick={props.onClose}>
</div>
</div>
</Dialog.Content>
</Dialog>
);
}
type PartnerKanbanProps = {
simple?: boolean;
};
export default function PartnerKanban({ simple }: PartnerKanbanProps) {
const [tipOpen, setTipOpen] = useState(false);
const [withdrawOpen, setWithdrawOpen] = useState(false);
const [stats, setStats] = useState<PartnerProfitsState>({
withdraw: 0,
available: 0,
withdrawing: 0,
});
const total = stats.withdrawing + stats.available + stats.withdraw;
const handleNavigate = useCallback(() => {
navigateTo(PageUrl.Partner);
}, []);
const handleNavigateRecord = useCallback(() => {
navigateTo(PageUrl.WithdrawRecord);
}, []);
const handleViewTip = useCallback(() => {
setTipOpen(true);
}, []);
const handleTipClose = useCallback(() => {
setTipOpen(false);
}, []);
const handleViewWithdraw = useCallback(() => {
setWithdrawOpen(true);
}, []);
const handleWithdrawClose = useCallback(() => {
setWithdrawOpen(false);
}, []);
const getProfitStats = useCallback(async () => {
const data = await getPartnerProfitStat();
setStats(data);
}, []);
useEffect(() => {
getProfitStats();
}, []);
return (
<div className={`${PREFIX} ${simple ? `${PREFIX}__simple` : ''}`}>
<Image
className={`${PREFIX}__bg`}
src="https://publiccdn.neighbourhood.com.cn/img/partner_bg.png"
mode="aspectFill"
/>
<div className={`${PREFIX}__content`}>
{simple && (
<div className={`${PREFIX}__button`} onClick={handleNavigate}>
<Image
className={`${PREFIX}__button-image`}
mode="aspectFit"
src={require('@/statics/svg/caret-right.svg')}
/>
</div>
)}
<div className={`${PREFIX}__total`}>
<div className={`${PREFIX}__title`}></div>
<div className={`${PREFIX}__money`}>{formatMoney(total)}</div>
</div>
<div className={`${PREFIX}__details`}>
<div className={`${PREFIX}__details-part`}>
<div className={`${PREFIX}__title`}></div>
<div className={`${PREFIX}__money`}>{formatMoney(stats.available)}</div>
</div>
<div className={`${PREFIX}__details-part`}>
<div className={`${PREFIX}__title`}></div>
<div className={`${PREFIX}__money`}>{formatMoney(stats.withdrawing)}</div>
</div>
<div className={`${PREFIX}__details-part`}>
<div className={`${PREFIX}__title`}>
{!simple && <Question onClick={handleViewTip} />}
</div>
<div className={`${PREFIX}__money`}>{formatMoney(stats.withdraw)}</div>
</div>
</div>
{!simple && (
<div className={`${PREFIX}__buttons`}>
<Button className={`${PREFIX}__withdraw`} onClick={handleViewWithdraw}>
</Button>
<Button className={`${PREFIX}__record`} onClick={handleNavigateRecord}>
</Button>
</div>
)}
</div>
{!simple && <TipDialog open={tipOpen} onClose={handleTipClose} />}
{!simple && <WithdrawDialog count={350} open={withdrawOpen} onClose={handleWithdrawClose} />}
</div>
);
}

View File

@ -0,0 +1,117 @@
import { List, PullRefresh } from '@taroify/core';
import classNames from 'classnames';
import { useCallback, useEffect, useRef, useState } from 'react';
import ListPlaceholder from '@/components/list-placeholder';
import { GetProfitRequest, PartnerProfitItem, ProfitType } from '@/types/partner';
import { logWithPrefix } from '@/utils/common';
import { formatMoney, formatTimestamp, getProfitList as requestData } from '@/utils/partner';
import './index.less';
import { PROFIT_STATUS_MAP, PROFIT_TYPE_MAP } from '@/constants/partner';
export interface IPartnerProfitListProps extends GetProfitRequest {
visible?: boolean;
refreshDisabled?: boolean;
listHeight?: number;
className?: string;
onListEmpty?: () => void;
}
const PREFIX = 'partner-profit';
const log = logWithPrefix(PREFIX);
function ProfitList(props: IPartnerProfitListProps) {
const { className, listHeight, refreshDisabled, visible = true, profitType, onListEmpty } = props;
const [refreshing, setRefreshing] = useState(false);
const [loadingMore, setLoadingMore] = useState(false);
const [loadMoreError, setLoadMoreError] = useState(false);
const [dataList, setDataList] = useState<PartnerProfitItem[]>([]);
const onListEmptyRef = useRef(onListEmpty);
const handleRefresh = useCallback(async () => {
log('start pull refresh');
try {
setRefreshing(true);
setLoadMoreError(false);
const list = await requestData({ profitType });
setDataList(list);
!list.length && onListEmptyRef.current?.();
log('pull refresh success');
} catch (e) {
setDataList([]);
setLoadMoreError(true);
log('pull refresh failed');
} finally {
setRefreshing(false);
}
}, []);
useEffect(() => {
onListEmptyRef.current = onListEmpty;
}, [onListEmpty]);
// 初始化数据&配置变更后刷新数据
useEffect(() => {
// 列表不可见时,先不做处理
if (!visible) {
log('visible changed, but is not visible, only clear list');
return;
}
const refresh = async () => {
log('visible changed, start refresh list data');
try {
setDataList([]);
setLoadingMore(true);
setLoadMoreError(false);
const list = await requestData({ profitType });
setDataList(list);
!list.length && onListEmptyRef.current?.();
} catch (e) {
setDataList([]);
setLoadMoreError(true);
} finally {
log('visible changed, refresh list data end');
setLoadingMore(false);
}
};
refresh();
}, [visible, profitType]);
return (
<div className={`${PREFIX}__tab-content`}>
<PullRefresh
className={classNames(`${PREFIX}__pull-refresh`, className)}
loading={refreshing}
onRefresh={handleRefresh}
disabled={refreshDisabled}
>
<List
hasMore={false}
onLoad={() => {}}
loading={loadingMore || refreshing}
disabled={loadMoreError}
fixedHeight={typeof listHeight !== 'undefined'}
style={listHeight ? { height: `${listHeight}px` } : undefined}
>
{dataList.map(item => (
<div className={`${PREFIX}__row`} key={item.id}>
<div className={`${PREFIX}__row-content`}>
<div className={`${PREFIX}__item time`}>{formatTimestamp(item.created)}</div>
<div className={`${PREFIX}__item project`}>{PROFIT_TYPE_MAP[profitType]}</div>
<div className={`${PREFIX}__item status`}>
{profitType === ProfitType.Anchor ? '已结算' : PROFIT_STATUS_MAP[item.status]}
</div>
<div className={`${PREFIX}__item income`}>+{formatMoney(item.profit)}</div>
</div>
</div>
))}
<ListPlaceholder hasMore={false} loadingMore={loadingMore} loadMoreError={loadMoreError} />
</List>
</PullRefresh>
</div>
);
}
export default ProfitList;

View File

@ -0,0 +1,96 @@
@import '@/styles/variables.less';
@import '@/styles/common.less';
.partner-profit {
height: calc(100vh - 98rpx);
overflow: hidden;
width: 100%;
.flex-column();
align-items: normal;
&__top {
padding: 12px 24px;
}
&__main {
position: relative;
flex-grow: 1;
overflow: hidden;
}
&__tabs {
height: 100%;
.taroify-tabs__content {
height: calc(100% - 98rpx);
}
.taroify-tabs__tab-pane {
height: 100%;
position: relative;
}
}
&__title {
height: 72px;
width: 100%;
background: #f7f7f7;
padding: 0 32px;
box-sizing: border-box;
line-height: 72px;
font-size: 24px;
color: rgba(0, 0, 0, 0.5);
position: absolute;
top:0;
left:0;
z-index: 1;
.flex-row();
}
&__row {
padding: 0 32px;
}
&__row-content {
border-bottom: 1px solid #e6e7e8;
font-size: 28px;
color: @blColor;
height: 100px;
.flex-row();
.income {
font-weight: 600;
font-size: 30px;
color: #ff5051;
}
}
&__item {
padding: 0 8px;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
&.time,
&.project {
flex: 2;
}
&.status {
width: 96px;
padding: 0 8px;
flex-shrink: 0;
}
&.income {
text-align: right;
flex: 1;
}
}
&__tab-content {
padding-top: 72rpx;
height: 100%;
box-sizing: border-box;
background: #fff;
overflow-y: auto;
overflow-x: hidden;
}
}

View File

@ -0,0 +1,47 @@
import { Tabs } from '@taroify/core';
import PartnerKanban from '@/components/partner-kanban';
import { ProfitType } from '@/types/partner';
import ProfitList from './ProfitList';
import './index.less';
const PREFIX = 'partner-profit';
function TableTitle() {
return (
<div className={`${PREFIX}__title`}>
<div className={`${PREFIX}__item time`}></div>
<div className={`${PREFIX}__item project`}></div>
<div className={`${PREFIX}__item status`}></div>
<div className={`${PREFIX}__item income`}>()</div>
</div>
);
}
export default function PartnerProfit() {
return (
<div className={PREFIX}>
<div className={`${PREFIX}__top`}>
<PartnerKanban />
</div>
<div className={`${PREFIX}__main`}>
<Tabs className={`${PREFIX}__tabs`}>
<Tabs.TabPane title="推荐主播收益">
<TableTitle />
<ProfitList profitType={ProfitType.Anchor} />
</Tabs.TabPane>
<Tabs.TabPane title="推荐会员权益">
<TableTitle />
<ProfitList profitType={ProfitType.Member} />
</Tabs.TabPane>
<Tabs.TabPane title="推荐合伙人收益">
<TableTitle />
<ProfitList profitType={ProfitType.Partner} />
</Tabs.TabPane>
</Tabs>
</div>
</div>
);
}

View File

@ -30,4 +30,9 @@
&__protocol {
margin-top: 20px;
}
}
.page-user--1 ~ & {
position: static;
padding-bottom: 174px;
}
}