This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
|
import { useParams, useNavigate, useSearchParams, useLocation } from 'react-router-dom';
|
||||||
import { Typography, Button, Spin, Empty, Descriptions, Tag, Row, Col, Modal, Form, Input, message, Statistic } from 'antd';
|
import { Typography, Button, Spin, Empty, Descriptions, Tag, Row, Col, Modal, Form, Input, message, Statistic } from 'antd';
|
||||||
import { ArrowLeftOutlined, ClockCircleOutlined, GiftOutlined, ShoppingCartOutlined } from '@ant-design/icons';
|
import { ArrowLeftOutlined, ClockCircleOutlined, GiftOutlined, ShoppingCartOutlined } from '@ant-design/icons';
|
||||||
import { getServiceDetail, createServiceOrder } from '../api';
|
import { getServiceDetail, createServiceOrder } from '../api';
|
||||||
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
|
|
||||||
const { Title, Paragraph } = Typography;
|
const { Title, Paragraph } = Typography;
|
||||||
@@ -10,7 +11,9 @@ const { Title, Paragraph } = Typography;
|
|||||||
const ServiceDetail = () => {
|
const ServiceDetail = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
const { user } = useAuth();
|
||||||
const [service, setService] = useState(null);
|
const [service, setService] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
@@ -38,6 +41,14 @@ const ServiceDetail = () => {
|
|||||||
fetchDetail();
|
fetchDetail();
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isModalOpen && user && user.phone_number) {
|
||||||
|
form.setFieldsValue({
|
||||||
|
phone_number: user.phone_number
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isModalOpen, user, form]);
|
||||||
|
|
||||||
const handlePurchase = async (values) => {
|
const handlePurchase = async (values) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
try {
|
try {
|
||||||
@@ -209,7 +220,14 @@ const ServiceDetail = () => {
|
|||||||
color: '#000',
|
color: '#000',
|
||||||
fontWeight: 'bold'
|
fontWeight: 'bold'
|
||||||
}}
|
}}
|
||||||
onClick={() => setIsModalOpen(true)}
|
onClick={() => {
|
||||||
|
if (!user) {
|
||||||
|
message.info('请先登录后再进行咨询');
|
||||||
|
navigate('/login', { state: { from: location.pathname } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
立即咨询 / 购买
|
立即咨询 / 购买
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
|
import { useParams, useNavigate, useSearchParams, useLocation } from 'react-router-dom';
|
||||||
import { Typography, Button, Spin, Empty, Descriptions, Tag, Row, Col, Modal, Form, Input, message } from 'antd';
|
import { Typography, Button, Spin, Empty, Descriptions, Tag, Row, Col, Modal, Form, Input, message } from 'antd';
|
||||||
import { ArrowLeftOutlined, ClockCircleOutlined, UserOutlined, BookOutlined, FormOutlined, CalendarOutlined, PlayCircleOutlined, LockOutlined } from '@ant-design/icons';
|
import { ArrowLeftOutlined, ClockCircleOutlined, UserOutlined, BookOutlined, FormOutlined, CalendarOutlined, PlayCircleOutlined, LockOutlined } from '@ant-design/icons';
|
||||||
import { getVCCourseDetail, createOrder, nativePay, queryOrderStatus } from '../api';
|
import { getVCCourseDetail, createOrder, nativePay, queryOrderStatus } from '../api';
|
||||||
@@ -19,6 +19,7 @@ const { Title, Paragraph } = Typography;
|
|||||||
const VCCourseDetail = () => {
|
const VCCourseDetail = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const [course, setCourse] = useState(null);
|
const [course, setCourse] = useState(null);
|
||||||
@@ -272,7 +273,14 @@ const VCCourseDetail = () => {
|
|||||||
color: '#000',
|
color: '#000',
|
||||||
fontWeight: 'bold'
|
fontWeight: 'bold'
|
||||||
}}
|
}}
|
||||||
onClick={() => setIsModalOpen(true)}
|
onClick={() => {
|
||||||
|
if (!user) {
|
||||||
|
message.info('请先登录后再进行报名或购买');
|
||||||
|
navigate('/login', { state: { from: location.pathname } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
立即解锁观看
|
立即解锁观看
|
||||||
</Button>
|
</Button>
|
||||||
@@ -436,7 +444,15 @@ const VCCourseDetail = () => {
|
|||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
cursor: course.is_purchased ? 'not-allowed' : 'pointer'
|
cursor: course.is_purchased ? 'not-allowed' : 'pointer'
|
||||||
}}
|
}}
|
||||||
onClick={() => !course.is_purchased && setIsModalOpen(true)}
|
onClick={() => {
|
||||||
|
if (course.is_purchased) return;
|
||||||
|
if (!user) {
|
||||||
|
message.info('请先登录后再进行报名或购买');
|
||||||
|
navigate('/login', { state: { from: location.pathname } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{course.is_purchased ? '已购买' : (course.is_video_course ? '购买视频课程' : '立即报名 / 咨询')}
|
{course.is_purchased ? '已购买' : (course.is_video_course ? '购买视频课程' : '立即报名 / 咨询')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user