import { useState, useEffect } from 'react';
import Taro from '@tarojs/taro';
import withLayout from '@/layout';
import {
ScrollView,
Image,
RichText,
View,
Text,
Input,
Picker,
Button
} from '@tarojs/components';
import Disclaimer from '@/components/Disclaimer';
import { useSelector } from 'react-redux';
import {
signupActivity,
queryActivityDetail,
} from "@/services/activity";
import { getImgURL } from "@/utils/image";
import { formatDate } from "@/utils/chatDate";
import useParams from "@/utils/hooks/useParams";
import useShare from "@/utils/hooks/useShare";
import useFavor from "@/utils/hooks/useFavor";
import { times } from "@/utils/tools";
import useStatus from './useStatus'
import CountDown from './CountDown'
import "./index.scss";
const activityStatusDict = {
0: {
text: '立即参与',
text1: '立即参团',
className: 'yellow',
},
1: {
text: '未开始',
text1: '未开始',
className: 'blue',
},
2: {
text: '已结束',
text1: '已结束',
className: 'grey',
},
3: {
text: '已参与',
text1: '已结束',
className: 'yellow',
},
};
export default withLayout((props) => {
const { router, shareContent, trackData, person, page } = props;
const { id } = router.params;
const user = useSelector((state) => state.user);
const [detail, setDetail] = useState({})
const [canChoose, setCanChoose] = useState('none');
const [inputName, setInputName] = useState('');
const [selectorChecked, setSelectorChecked] = useState('1');
const [selector, setSelector] = useState('');
const buildingId = detail?.buildingId;
const [btnText, btnDisabled] = useStatus(detail)
const getDetail = (params) => {
Taro.showLoading();
queryActivityDetail(params).then((res) => {
const maxperson = 10
setSelector(times(maxperson).map((_, i) => `${i + 1}`));
setDetail(res);
Taro.hideLoading();
});
};
// 本页面分享或者海报参数
const paramsRef = useParams({
id,
buildingId,
person,
from: `${page.type}_share`,
});
const fullTrackData = { ...trackData, buildingId };
const [isSaved, handleFavor] = useFavor(detail?.isSaved, {
id,
buildingId,
...trackData,
});
useShare(
{
title: shareContent.shareContentTitle || detail?.title,
path: `${router.path}?${paramsRef.current}`,
image: shareContent.shareContentImg || getImgURL(detail?.imgUrl),
},
fullTrackData
);
useEffect(() => {
if (id) {
getDetail(id);
}
}, [id])
const handleSignup = () => {
setCanChoose("block");
};
const comfire = () => {
const { dynamicId } = detail
const { userInfo: { person: { phone, tel } } } = user
if (inputName === '') {
Taro.showToast({
title: '请输入姓名',
icon: 'none'
})
return
}
const payload = {
buildingId,
dynamicId,
name: inputName,
phone: phone ? phone : tel,
attendNum: selectorChecked,
};
signupActivity(payload).then(() => {
Taro.showToast({
title: "报名成功",
});
setCanChoose('none')
setTimeout(() => {
getDetail(id)
}, 500)
});
};
function hideModal () {
setCanChoose('none');
}
const onInputText = (e) => {
setInputName(e.detail.value);
};
const dymic = () => (
{detail.halfTitle}
{detail.enlisted || 0}人已报名
报名截止时间:
{formatDate(detail.enlistEnd, 'yyyy/M/d')}
{detail.title}
地址:
{detail.address}
时间:
{`${formatDate(detail.startDate, 'yyyy/M/d')} - ${formatDate(detail.endDate, 'yyyy/M/d')}`}
);
const house = () => (
{detail.title}
{detail.address}
价格待定
时间:{formatDate(detail.startDate, 'yyyy/M/d')} - {formatDate(detail.endDate, 'yyyy/M/d')}
分享
朋友圈
{isSaved ? '已收藏' : '收藏'}
{detail.enlisted || 0}人已报名
);
return (
<>
{detail && (
{detail.type == "dymic" && dymic()}
{detail.type !== "dymic" && house()}
活动介绍
{detail.type == "dymic" && (
{isSaved ? '已收藏' : '收藏'}
)}
)}
hideModal()}>
报名信息
setSelectorChecked(selector[e.detail.value])}
>
参加人数
{selectorChecked}
人
确认
>
);
});