feat:
This commit is contained in:
@ -6,51 +6,59 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import Badge from '@/components/badge';
|
||||
import { PREFIX } from '@/components/product-dialog/const';
|
||||
import { PageUrl } from '@/constants/app';
|
||||
import { CollectEventName } from '@/constants/event';
|
||||
import { OrderStatus, OrderType, ProductSpecId, ProductType } from '@/constants/product';
|
||||
import { OrderStatus, OrderType, ProductType } from '@/constants/product';
|
||||
import { SubscribeTempId } from '@/constants/subscribe';
|
||||
import { ProductSpecResult } from '@/types/product';
|
||||
import { logWithPrefix } from '@/utils/common';
|
||||
import { collectEvent } from '@/utils/event';
|
||||
import { getOrderPrice, isCancelPay, requestCreatePayInfo, requestOrderInfo, requestPayment } from '@/utils/product';
|
||||
import {
|
||||
isCancelPay,
|
||||
requestCreatePayInfo,
|
||||
requestOrderInfo,
|
||||
requestPayment,
|
||||
requestProductTypeList,
|
||||
} from '@/utils/product';
|
||||
import { navigateTo } from '@/utils/route';
|
||||
import { postSubscribe, subscribeMessage } from '@/utils/subscribe';
|
||||
import Toast from '@/utils/toast';
|
||||
|
||||
interface IProps {
|
||||
buyOnly?: boolean;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
interface Item {
|
||||
id: ProductSpecId;
|
||||
title: string;
|
||||
content: string;
|
||||
buyOnlyContent?: string;
|
||||
price: string;
|
||||
amt: number;
|
||||
badge?: string;
|
||||
}
|
||||
// interface Item {
|
||||
// id: ProductSpecId;
|
||||
// title: string;
|
||||
// content: string;
|
||||
// buyOnlyContent?: string;
|
||||
// price: string;
|
||||
// amt: number;
|
||||
// badge?: string;
|
||||
// }
|
||||
|
||||
const LIST: Item[] = [
|
||||
{ id: ProductSpecId.WeeklyVIP, title: '非会员', content: '每日2次', price: '免费', amt: 0 },
|
||||
{
|
||||
id: ProductSpecId.DailyVIP,
|
||||
title: '日会员',
|
||||
content: '每日+10次',
|
||||
buyOnlyContent: '每日12次',
|
||||
price: '60播豆',
|
||||
amt: 6,
|
||||
badge: '限时体验',
|
||||
},
|
||||
{
|
||||
id: ProductSpecId.WeeklyVIP,
|
||||
title: '周会员',
|
||||
content: '每日+10次',
|
||||
buyOnlyContent: '每日12次',
|
||||
price: '180播豆',
|
||||
amt: 18,
|
||||
badge: ' 超值',
|
||||
},
|
||||
];
|
||||
// const LIST: Item[] = [
|
||||
// { id: ProductSpecId.WeeklyVIP, title: '非会员', content: '每日2次', price: '免费', amt: 0 },
|
||||
// {
|
||||
// id: ProductSpecId.DailyVIP,
|
||||
// title: '日会员',
|
||||
// content: '每日+10次',
|
||||
// buyOnlyContent: '每日12次',
|
||||
// price: '60播豆',
|
||||
// amt: 6,
|
||||
// badge: '限时体验',
|
||||
// },
|
||||
// {
|
||||
// id: ProductSpecId.WeeklyVIP,
|
||||
// title: '周会员',
|
||||
// content: '每日+10次',
|
||||
// buyOnlyContent: '每日12次',
|
||||
// price: '180播豆',
|
||||
// amt: 18,
|
||||
// badge: ' 超值',
|
||||
// },
|
||||
// ];
|
||||
|
||||
const log = logWithPrefix('job-buy');
|
||||
const SUBSCRIBE_ID = SubscribeTempId.SUBSCRIBE_VIP;
|
||||
@ -66,20 +74,26 @@ const subscribe = async () => {
|
||||
};
|
||||
|
||||
export default function JobBuy(props: IProps) {
|
||||
const { onConfirm, buyOnly } = props;
|
||||
const [selectItem, setSelectItem] = useState(LIST[1]);
|
||||
const { onConfirm } = props;
|
||||
const [productList, setProductList] = useState<ProductSpecResult[]>([]);
|
||||
const [selectItem, setSelectItem] = useState<ProductSpecResult | undefined>();
|
||||
|
||||
const handleClickItem = useCallback((newSelectItem: Item) => setSelectItem(newSelectItem), []);
|
||||
const handleClickItem = useCallback((newSelectItem: ProductSpecResult) => setSelectItem(newSelectItem), []);
|
||||
|
||||
const handleBuy = useCallback(async () => {
|
||||
log('handleBuy', selectItem);
|
||||
if (!selectItem) {
|
||||
Toast.error('请选择购买的产品');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Taro.showLoading();
|
||||
|
||||
const { payOrderNo, createPayInfo } = await requestCreatePayInfo({
|
||||
type: OrderType.VIP,
|
||||
amt: getOrderPrice(selectItem.amt),
|
||||
amt: selectItem.payPrice,
|
||||
productCode: ProductType.VIP,
|
||||
productSpecId: selectItem.id,
|
||||
productSpecId: selectItem.productSpecId,
|
||||
});
|
||||
log('handleBuy payInfo', payOrderNo, createPayInfo);
|
||||
await requestPayment({
|
||||
@ -104,59 +118,65 @@ export default function JobBuy(props: IProps) {
|
||||
}
|
||||
}, [selectItem, onConfirm]);
|
||||
|
||||
const handleGetProductInfo = useCallback(async () => {
|
||||
const result = await requestProductTypeList(ProductType.VIP);
|
||||
setProductList(result);
|
||||
setSelectItem(result[0]);
|
||||
}, []);
|
||||
|
||||
const handleResume = useCallback(() => {
|
||||
navigateTo(PageUrl.MaterialUploadVideo);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
handleGetProductInfo();
|
||||
collectEvent(CollectEventName.CREATE_ORDER_VIEW, { orderType: OrderType.VIP });
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={`${PREFIX}__job-buy`}>
|
||||
{buyOnly ? (
|
||||
<div className={`${PREFIX}__job-buy__header`}>开通播络会员即可直接查看联系方式</div>
|
||||
) : (
|
||||
<div className={`${PREFIX}__job-buy__header`}>
|
||||
<div>今日通告对接次数</div>
|
||||
<div className="highlight">已用完</div>
|
||||
<div className={`${PREFIX}__job-buy__header`}>
|
||||
<div>免费查看次数已用完</div>
|
||||
<div className="highlight">请升级会员</div>
|
||||
</div>
|
||||
<div className={`${PREFIX}__job-buy__describe`}>
|
||||
<div>完善模卡</div>
|
||||
<div> 赠10次查看 </div>
|
||||
<div className="highlight" onClick={handleResume}>
|
||||
去完善
|
||||
</div>
|
||||
)}
|
||||
{buyOnly ? (
|
||||
<div className={`${PREFIX}__job-buy__describe`}>每天可获取12个联系方式</div>
|
||||
) : (
|
||||
<div className={`${PREFIX}__job-buy__describe`}>
|
||||
<div>请</div>
|
||||
<div className="highlight">明日</div>
|
||||
<div>再来 或 </div>
|
||||
<div className="highlight">升级会员</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={`${PREFIX}__job-buy__container`}>
|
||||
{LIST.map(item => {
|
||||
if (buyOnly && !item.amt) {
|
||||
return null;
|
||||
}
|
||||
{productList.map(item => {
|
||||
return (
|
||||
<div
|
||||
key={item.price}
|
||||
key={item.payPrice}
|
||||
className={classNames(`${PREFIX}__job-buy__item`, {
|
||||
selected: item.amt === selectItem.amt,
|
||||
disabled: item.amt === 0,
|
||||
selected: selectItem && item.payPrice === selectItem.payPrice,
|
||||
disabled: item.payPrice === 0,
|
||||
})}
|
||||
onClick={item.amt === 0 ? undefined : () => handleClickItem(item)}
|
||||
onClick={item.payPrice === 0 ? undefined : () => handleClickItem(item)}
|
||||
>
|
||||
<div className={classNames(`${PREFIX}__job-buy__item__title`, { free: item.amt === 0 })}>
|
||||
<div className={classNames(`${PREFIX}__job-buy__item__title`, { free: item.payPrice === 0 })}>
|
||||
{item.title}
|
||||
</div>
|
||||
<div className={`${PREFIX}__job-buy__item__content`}>{buyOnly ? item.buyOnlyContent : item.content}</div>
|
||||
<div className={`${PREFIX}__job-buy__item__price`}>{item.price}</div>
|
||||
<div className={`${PREFIX}__job-buy__item__content`}>{item.contentSingle}</div>
|
||||
<div className={`${PREFIX}__job-buy__item__price`}>{item.showPrice}元</div>
|
||||
{item.badge && <Badge className={`${PREFIX}__job-buy__item__badge`} text={item.badge} />}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className={`${PREFIX}__job-buy__hint`}>
|
||||
注:日会员有效期为 <div className="highlight">支付后24小时</div>
|
||||
</div>
|
||||
<Button className={`${PREFIX}__job-buy__button`} onClick={handleBuy}>
|
||||
{`支付 ${selectItem.amt} 元`}
|
||||
{selectItem && (
|
||||
<div className={`${PREFIX}__job-buy__hint`}>
|
||||
注:{selectItem?.title}有效期为
|
||||
<div className="highlight">
|
||||
支付后{selectItem?.expire > 1 ? `${selectItem.expire}天` : `${selectItem.expire * 24}小时`}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Button className={`${PREFIX}__job-buy__button`} disabled={!selectItem} onClick={handleBuy}>
|
||||
{`支付 ${selectItem?.showPrice} 元`}
|
||||
</Button>
|
||||
{/* <div className={`${PREFIX}__job-buy__tips`}>{`已选:${selectItem.title},含进本地群服务`}</div> */}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user