123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import React from 'react';
- import './index.less';
- import { Tabs } from 'antd-mobile';
- import Page from '@src/containers/Page';
- import Assets from '@src/components/Assets';
- import { formatDate, getMap } from '@src/services/Tools';
- import Money from '../../../components/Money';
- import Button from '../../../components/Button';
- import Tag from '../../../components/Tag';
- import { Course } from '../../../stores/course';
- import { Order } from '../../../stores/order';
- import { DataType } from '../../../../Constant';
- import { FAQItem, CommentItem } from '../../../components/Item';
- const DataTypeMap = getMap(DataType, 'value', 'label');
- export default class extends Page {
- initState() {
- return { tab: 'content' };
- }
- initData() {
- const { id } = this.params;
- Course.getData(id).then(data => {
- this.setState({ data });
- });
- }
- buy() {
- Order.speedPay({ productType: 'data', productId: this.params.id })
- .then((result) => {
- linkTo(`/pay/${result.id}`);
- });
- }
- renderText() {
- const { tab, data } = this.state;
- let content;
- switch (tab) {
- case 'content':
- case 'authorContent':
- case 'methodContent':
- content = <div dangerouslySetInnerHTML={{ __html: data[tab] }} />;
- break;
- case 'faq':
- content = (
- <div>
- {(data.faqs || []).map(row => (
- <FAQItem data={row} />
- ))}
- </div>
- );
- break;
- case 'comment':
- content = (
- <div>
- {(data.comments || []).map(row => (
- <CommentItem data={row} />
- ))}
- </div>
- );
- break;
- default:
- break;
- }
- return content;
- }
- renderView() {
- const { data = {}, tab } = this.state;
- return (
- <div>
- <div className="detail">
- <Assets className="info-img" name="d_b" src={data.cover} />
- <div className="info">
- <div className="title">{data.title}</div>
- <div className="tags">
- {data.isOriginal > 0 && <Tag size="small">原创</Tag>}
- {data.isNovice > 0 && <Tag size="small">适合新手</Tag>}
- </div>
- <div className="data">页数: {data.pages}页</div>
- <div className="data">格式: {DataTypeMap[data.dataType]}</div>
- <div className="data">{data.updateTime && formatDate(data.updateTime, 'YYYY-MM-DD HH:mm')} 更新</div>
- <Money value={data.price} size="lager" theme="sell" />
- </div>
- </div>
- <div className="desc" dangerouslySetInnerHTML={{ __html: data.description }} />
- <Tabs
- page={tab}
- tabs={[
- { title: '资料介绍', key: 'content' },
- { title: '作者介绍', key: 'authorContent' },
- { title: '获取方式', key: 'methodContent' },
- { title: 'FAQs', key: 'faq' },
- { title: '用户评价', key: 'comment' },
- ]}
- onChange={value => {
- this.setState({ tab: value.key });
- }}
- />
- {this.renderText()}
- <div className="fixed">
- <div className="fee">
- 总额: <Money value={data.price} size="lager" />
- </div>
- <Button
- width={110}
- className="f-r"
- radius
- onClick={() => {
- this.buy();
- }}
- >
- 立即购买
- </Button>
- </div>
- </div>
- );
- }
- }
|