revert ad
This commit is contained in:
@ -3,23 +3,20 @@ import Taro from '@tarojs/taro';
|
||||
import { Dialog } from '@taroify/core';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { PrejobPopup } from '@/components/prejob-popup';
|
||||
import { DialogStatus, PREFIX } from '@/components/product-dialog/const';
|
||||
import JobBuy from '@/components/product-dialog/steps-ui/job-buy';
|
||||
import ContactCustomerService from '@/components/product-dialog/steps-ui/job-contact-customer';
|
||||
import ContactDirect from '@/components/product-dialog/steps-ui/job-contact-direct';
|
||||
import UnableUnlockContent from '@/components/product-dialog/steps-ui/job-unable';
|
||||
import { EventName } from '@/constants/app';
|
||||
import { GET_CONTACT_TYPE } from '@/constants/job';
|
||||
import { DeclarationType, ProductType } from '@/constants/product';
|
||||
import { JobDetails } from '@/types/job';
|
||||
import { ProductInfo } from '@/types/product';
|
||||
import { logWithPrefix } from '@/utils/common';
|
||||
import {
|
||||
requestAllBuyProduct,
|
||||
requestProductBalance,
|
||||
requestProductUseRecord,
|
||||
requestProductBalance,
|
||||
requestUseProduct,
|
||||
requestAllBuyProduct,
|
||||
} from '@/utils/product';
|
||||
import Toast from '@/utils/toast';
|
||||
|
||||
@ -36,32 +33,13 @@ const log = logWithPrefix('product-job-dialog');
|
||||
function ProductJobDialog(props: Omit<IProps, 'visible'>) {
|
||||
const { data, onClose } = props;
|
||||
const [status, setStatus] = useState<DialogStatus>(DialogStatus.LOADING);
|
||||
const [showContact, setShowContact] = useState(false);
|
||||
const [showPrejob, setShowPrejob] = useState(false);
|
||||
const [publisherAcctNo, setPublisherAcctNo] = useState<string>('');
|
||||
const initRef = useRef<(skipPreAction?: boolean, skipRecordGet?: boolean) => void | Promise<void>>(() => {});
|
||||
const initRef = useRef(() => {});
|
||||
|
||||
const handleCloseDialog = useCallback(() => {
|
||||
setShowContact(false);
|
||||
onClose();
|
||||
}, [onClose]);
|
||||
|
||||
const handleClosePrejob = useCallback(() => {
|
||||
setShowPrejob(false);
|
||||
onClose();
|
||||
}, []);
|
||||
|
||||
const handleConfirmPrejob = useCallback(async (type: GET_CONTACT_TYPE) => {
|
||||
if (type === GET_CONTACT_TYPE.VIP) {
|
||||
const allowBuy = await requestAllBuyProduct(PRODUCT_CODE);
|
||||
setShowContact(true);
|
||||
setShowPrejob(false);
|
||||
setStatus(allowBuy ? DialogStatus.PREACTION_JOB_BUY : DialogStatus.JOB_UNABLE_UNLOCK);
|
||||
} else if (type === GET_CONTACT_TYPE.VIDEO) {
|
||||
Taro.eventCenter.trigger(EventName.SHOW_VIDEO_REWARD);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleAfterBuy = useCallback(async () => {
|
||||
const [time] = await requestProductBalance(PRODUCT_CODE);
|
||||
if (time <= 0) {
|
||||
@ -71,8 +49,6 @@ function ProductJobDialog(props: Omit<IProps, 'visible'>) {
|
||||
}
|
||||
const productInfo = await requestUseProduct(PRODUCT_CODE, { jobId: data.id });
|
||||
const declarationTypeResult = productInfo.declarationTypeResult;
|
||||
setShowContact(true);
|
||||
setShowPrejob(false);
|
||||
if (declarationTypeResult?.type === DeclarationType.Direct && declarationTypeResult.publisherAcctNo) {
|
||||
setStatus(DialogStatus.JOB_CONTACT_DIRECT);
|
||||
setPublisherAcctNo(declarationTypeResult.publisherAcctNo);
|
||||
@ -86,9 +62,8 @@ function ProductJobDialog(props: Omit<IProps, 'visible'>) {
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
initRef.current = async (skipPreAction?: boolean, skipRecordGet?: boolean) => {
|
||||
initRef.current = async () => {
|
||||
const handleContact = (declarationTypeResult?: ProductInfo['declarationTypeResult']) => {
|
||||
setShowContact(true);
|
||||
if (declarationTypeResult?.type === DeclarationType.Direct && declarationTypeResult.publisherAcctNo) {
|
||||
setStatus(DialogStatus.JOB_CONTACT_DIRECT);
|
||||
setPublisherAcctNo(declarationTypeResult.publisherAcctNo);
|
||||
@ -102,32 +77,21 @@ function ProductJobDialog(props: Omit<IProps, 'visible'>) {
|
||||
// setStatus(DialogStatus.JOB_CONTACT_CS);
|
||||
// return;
|
||||
// }
|
||||
if (!skipRecordGet) {
|
||||
const result = await requestProductUseRecord(PRODUCT_CODE, { jobId: data.id });
|
||||
log('requestProductUseRecord result', result);
|
||||
if (result) {
|
||||
handleContact(result.declarationTypeResult);
|
||||
return;
|
||||
}
|
||||
const result = await requestProductUseRecord(PRODUCT_CODE, { jobId: data.id });
|
||||
log('requestProductUseRecord result', result);
|
||||
if (result) {
|
||||
handleContact(result.declarationTypeResult);
|
||||
return;
|
||||
}
|
||||
const [time, isPaidVip] = await requestProductBalance(PRODUCT_CODE);
|
||||
const [time] = await requestProductBalance(PRODUCT_CODE);
|
||||
if (time <= 0) {
|
||||
// const allowBuy = await requestAllBuyProduct(PRODUCT_CODE);
|
||||
setShowContact(true);
|
||||
setStatus(DialogStatus.JOB_UNABLE_UNLOCK);
|
||||
} else if (isPaidVip || skipPreAction) {
|
||||
const productInfo = await requestUseProduct(PRODUCT_CODE, { jobId: data.id });
|
||||
setShowPrejob(false);
|
||||
handleContact(productInfo.declarationTypeResult);
|
||||
const allowBuy = await requestAllBuyProduct(PRODUCT_CODE);
|
||||
setStatus(allowBuy ? DialogStatus.JOB_BUY : DialogStatus.JOB_UNABLE_UNLOCK);
|
||||
} else {
|
||||
setShowPrejob(true);
|
||||
setStatus(DialogStatus.PRE_ACTION);
|
||||
|
||||
// const productInfo = await requestUseProduct(PRODUCT_CODE, { jobId: data.id });
|
||||
// handleContact(productInfo.declarationTypeResult);
|
||||
const productInfo = await requestUseProduct(PRODUCT_CODE, { jobId: data.id });
|
||||
handleContact(productInfo.declarationTypeResult);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
Toast.error('出错了,请重试');
|
||||
handleCloseDialog();
|
||||
} finally {
|
||||
@ -140,44 +104,21 @@ function ProductJobDialog(props: Omit<IProps, 'visible'>) {
|
||||
initRef.current();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
Taro.eventCenter.once(EventName.PRE_ACTION_SHARE_SUCCESS, () => {
|
||||
initRef.current(true, true);
|
||||
});
|
||||
Taro.eventCenter.on(EventName.PRE_ACTION_VIDEO_SUCCESS, () => {
|
||||
initRef.current(true, true);
|
||||
});
|
||||
|
||||
return () => {
|
||||
Taro.eventCenter.off(EventName.PRE_ACTION_SHARE_SUCCESS);
|
||||
Taro.eventCenter.off(EventName.PRE_ACTION_VIDEO_SUCCESS);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (status === DialogStatus.LOADING) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PrejobPopup open={showPrejob} onCancel={handleClosePrejob} onConfirm={handleConfirmPrejob} />
|
||||
<Dialog className={PREFIX} onClose={onClose} open={showContact}>
|
||||
<Dialog.Content>
|
||||
{status === DialogStatus.JOB_CONTACT_CS && <ContactCustomerService onAfterConfirm={handleCloseDialog} />}
|
||||
{status === DialogStatus.JOB_CONTACT_DIRECT && (
|
||||
<ContactDirect
|
||||
publisherAcctNo={publisherAcctNo}
|
||||
onAfterConfirm={handleCloseDialog}
|
||||
onReport={handleReport}
|
||||
/>
|
||||
)}
|
||||
{(status === DialogStatus.JOB_BUY || status === DialogStatus.PREACTION_JOB_BUY) && (
|
||||
<JobBuy onConfirm={handleAfterBuy} justBuy={status === DialogStatus.PREACTION_JOB_BUY} />
|
||||
)}
|
||||
{status === DialogStatus.JOB_UNABLE_UNLOCK && <UnableUnlockContent onConfirm={handleCloseDialog} />}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
<Dialog className={PREFIX} onClose={onClose} open>
|
||||
<Dialog.Content>
|
||||
{status === DialogStatus.JOB_CONTACT_CS && <ContactCustomerService onAfterConfirm={handleCloseDialog} />}
|
||||
{status === DialogStatus.JOB_CONTACT_DIRECT && (
|
||||
<ContactDirect publisherAcctNo={publisherAcctNo} onAfterConfirm={handleCloseDialog} onReport={handleReport} />
|
||||
)}
|
||||
{status === DialogStatus.JOB_BUY && <JobBuy onConfirm={handleAfterBuy} />}
|
||||
{status === DialogStatus.JOB_UNABLE_UNLOCK && <UnableUnlockContent onConfirm={handleCloseDialog} />}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user