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 (