import React from 'react'; import './index.less'; import { Icon } from 'antd'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import Footer from '../../../components/Footer'; import { FaqModal, CommentModal, FinishModal } from '../../../components/OtherModal'; import { Contact, Comment, Consultation, AnswerCarousel } from '../../../components/Other'; import Tabs from '../../../components/Tabs'; import Button from '../../../components/Button'; import { Main } from '../../../stores/main'; import { Order } from '../../../stores/order'; import { User } from '../../../stores/user'; import { Course } from '../../../stores/course'; import { CourseVsType } from '../../../../Constant'; export default class extends Page { initState() { return { info: '1', number: 0, }; } init() { this.courseVsMap = {}; this.faqMap = {}; this.faqs = null; this.commentMap = {}; this.comments = null; this.promote = []; this.teacherMap = {}; Main.getPromote().then(result => { this.promote = result.vs_list || []; this.setState({ promote: result }); }); Main.getBase().then(result => { this.setState({ base: result }); }); } initData() { Course.allVs().then(result => { result.forEach(row => { this.courseVsMap[row.vsType] = row; }); this.onChangeItem(CourseVsType[0].value); }); } onChangeTab(info) { this.setState({ info }); } onChangeItem(key) { const item = this.courseVsMap[key]; if (!this.faqs) { Main.listFaq({ page: 1, size: 100, channel: 'course-vs_index' }).then(result => { this.faqs = result.list; this.setState({ faqs: result.list }); }); } if (!this.commentMap[key]) { Main.listComment({ page: 1, size: 100, channel: 'course-vs', position: item.id }).then(result => { this.commentMap[key] = result.list; this.setState({ comments: result.list }); }); } if (!this.teacherMap[key]) { Course.allTeacher(item.id).then(result => { this.teacherMap[key] = result; this.setState({ teachers: result }); }); } this.setState({ key, data: item, faqs: this.faqs, comments: this.commentMap[key], teachers: this.teacherMap[key] }); this.changeNumber(item.minNumber || 1); } changeNumber(number) { const { data } = this.state; let price = data.price * number; let max = 0; let maxIndex = -1; this.promote.forEach((row, i) => { if (row.number <= number) { if (row.number > max) { max = number; maxIndex = i; } } }); if (maxIndex >= 0) { price *= this.promote[maxIndex].percent / 100; } this.setState({ number, price }); } buy() { const { data } = this.props; Order.speedPay({ productType: 'course', productId: data.id }).then(result => { User.needPay(result).then(() => { linkTo('/my/course'); }); }); } add() { const { data } = this.props; Order.addCheckout({ productType: 'course', productId: data.id }).then(() => { this.setState({ add: true }); }); } renderView() { const { number } = this.props.order; const { promote = {}, base = {}, showComment, comment = {}, showFaq, faq = {}, showFinish } = this.state; return (
{(promote.vs || {}).text ? `优惠活动:${promote.vs.text}` : ''} linkTo('/cart')} /> ( {number || 0} )
{this.renderDetail()}
); } renderDetail() { const { info, key, data, number, price } = this.state; return [
{CourseVsType.map(t => { const course = this.courseVsMap[t.value] || {}; return (
this.onChangeItem(t.value)}>
{course.title}
{course.comment}
); })}
适合人群
课时数
授课流程
课程有效期
{data.expirePreDays}天/10课时
购买课时
number < data.maxNumber && this.setState({ number: number + 1 })} /> number !== 1 && number > data.minNumber && this.setState({ number: number - 1 })} />
课程总价
¥ {price}
{data.have && } {!data.have && } {!data.have && }
,
this.onChangeTab(tab)} /> {this[`renderTab${info}`]()}
, ]; } renderTab1() { const { teachers = [] } = this.state; const [teacher] = teachers; if (!teacher) return null; return (
{teacher.realname}
{teacher.description}
); } renderTab2() { const { base } = this.state; return (
); } renderTab3() { const { faqs, data = {} } = this.state; return (
User.needLogin().then(() => this.setState({ showFaq: true, faq: { channel: 'course-vs', position: data.id } }))} />
); } renderTab4() { const { data, comments } = this.state; return (
{data.have &&
} {(comments || []).map(item => { return ; })}
); } }