feat: withdraw
This commit is contained in:
@ -1,14 +1,16 @@
|
||||
import { Button, Image } from '@tarojs/components';
|
||||
import Taro, { useDidShow } from '@tarojs/taro';
|
||||
|
||||
import { Dialog } from '@taroify/core';
|
||||
import { Question } from '@taroify/icons';
|
||||
import { useCallback, useState, useEffect } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { PageUrl } from '@/constants/app';
|
||||
import { PartnerProfitsState } from '@/types/partner';
|
||||
import { formatMoney, getPartnerProfitStat } from '@/utils/partner';
|
||||
import { formatMoney, getPartnerProfitStat, withdrawMoney } from '@/utils/partner';
|
||||
import { navigateTo } from '@/utils/route';
|
||||
import Toast from '@/utils/toast';
|
||||
|
||||
import './index.less';
|
||||
|
||||
const PREFIX = 'partner-kanban';
|
||||
@ -31,14 +33,45 @@ function TipDialog(props: { open: boolean; onClose: () => void }) {
|
||||
}
|
||||
|
||||
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 (
|
||||
<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}
|
||||
{+props.count}
|
||||
<div className="yuan">元</div>
|
||||
</div>
|
||||
<div className={`${PREFIX}-withdraw-dialog__hint`}>单笔最大500元</div>
|
||||
@ -86,20 +119,24 @@ export default function PartnerKanban({ simple }: PartnerKanbanProps) {
|
||||
const handleTipClose = useCallback(() => {
|
||||
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 data = await getPartnerProfitStat();
|
||||
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(() => {
|
||||
getProfitStats();
|
||||
}, []);
|
||||
@ -154,7 +191,13 @@ export default function PartnerKanban({ simple }: PartnerKanbanProps) {
|
||||
)}
|
||||
</div>
|
||||
{!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>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user