import React from 'react'; import './index.less'; import { Tabs } from 'antd-mobile'; import Page from '@src/containers/Page'; import Money from '../../../components/Money'; import Button from '../../../components/Button'; import { FAQItem, CommentItem } from '../../../components/Item'; import { Course } from '../../../stores/course'; import { Main } from '../../../stores/main'; import { Order } from '../../../stores/order'; import Icon from '../../../components/Icon'; export default class extends Page { initState() { return { tab: 'serviceContent', number: 1 }; } initData() { const { id } = this.params; Main.getPromote().then(result => { this.promote = result.vs_list || []; Course.get(id).then(data => { this.setState({ data }); this.changeNumber(data.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 { number } = this.state; Order.speedPay({ productType: 'course', productId: this.params.id, number }) .then((result) => { linkTo(`/pay/${result.id}`); }); } renderText() { const { tab, data } = this.state; let content; switch (tab) { case 'serviceContent': case 'crowdContent': case 'processContent': content =
; break; case 'faq': content =
{(data.faqs || []).map(row => )}
; break; case 'comment': content =
{(data.comments || []).map(row => )}
; break; default: break; } return content; } renderView() { const { data = {}, tab, number, price } = this.state; return (
{data.title}
{/*
访问{PcUrl}/course/detail/{data.id},试听该课程
*/}
{ this.setState({ tab: value.key }); }} /> {this.renderText()}
this.changeNumber(number === 1 ? number : number - 1)}>
{number}
this.changeNumber(number + 1)}>
总额:
); } }