import React, { Component } from 'react';
import './index.less';
import Assets from '@src/components/Assets';
import { getMap, formatSeconds, formatDate } from '@src/services/Tools';
import Button from '../Button';
import More from '../More';
import { Order } from '../../stores/order';
import { User } from '../../stores/user';
import { ServiceKey, ServiceParamMap, CrowdList } from '../../../Constant';
const CrowdMap = getMap(CrowdList, 'value', 'label');
export class SingleItem extends Component {
constructor(props) {
super(props);
this.state = {};
}
buy() {
const { data } = this.props;
User.needLogin().then(() => {
Order.speedPay({ productType: 'course', productId: data.id }).then(result => {
User.needPay(result).then(() => {
linkTo('/my/course');
});
});
});
}
add() {
const { data } = this.props;
User.needLogin().then(() => {
Order.addCheckout({ productType: 'course', productId: data.id })
.then(() => {
this.setState({ add: true });
});
});
}
render() {
const { data = {}, noAction } = this.props;
const { add } = this.state;
return (
linkTo(`/course/detail/${data.id}`)}>
{CrowdMap[data.crowd]}
{data.title}
课时数: {data.noNumber}
{formatSeconds(data.time)}
{data.trailNumber || 0}次观看
授课老师:{data.teacher}
优质问答: {data.askNumber}
有效期: {data.useExpireDays}天
¥ {data.price}
{!noAction && (
{!data.have && (
)}
{data.have && (
)}
{!data.have && (
)}
)}
{!noAction && data.have &&
}
);
}
}
export class PackageItem extends Component {
constructor(props) {
super(props);
this.state = {};
}
buy() {
const { data } = this.props;
User.needLogin().then(() => {
Order.speedPay({ productType: 'course_package', productId: data.id }).then(result => {
User.needPay(result).then(() => {
linkTo('/my/course');
});
});
});
}
add() {
const { data } = this.props;
User.needLogin().then(() => {
Order.addCheckout({ productType: 'course_package', productId: data.id }).then(() => {
this.setState({ add: true });
});
});
}
render() {
const { data = {} } = this.props;
const { add } = this.state;
const originMoney = data.courses.reduce((a, y) => a + y.price, 0);
const novice = data.courses.filter(row => row.crowd !== 'novice').length === 0;
const teacherMap = {};
data.courses.forEach(row => {
teacherMap[row.teacher] = true;
});
const teachers = Object.keys(teacherMap);
return (
linkTo(`/course/package/detail/${data.id}`)}>
授课老师 {teachers.join(' ')}
{data.description}
包含课程
{data.courses.map(course => {
return (
{course.title}({course.noNumber}课时)
);
})}
配套服务
赠送服务
{data.gift &&
ServiceKey.map(row => {
if (!data.gift[row.value]) return null;
const list = ServiceParamMap[row.value];
if (list) {
const map = getMap(list, 'value', 'label');
return (
{row.label}×{map[data.gift[row.value]]}
);
}
return (
{row.label}×{data.gift[row.value]}
);
})}
原价: ¥{originMoney}
套餐价: ¥{data.price}
);
}
}
export class DataItem extends Component {
constructor(props) {
super(props);
this.state = {};
}
buy() {
const { data } = this.props;
User.needLogin().then(() => {
Order.speedPay({ productType: 'data', productId: data.id }).then(result => {
User.needPay(result).then(() => {
linkTo('/my/tools?tab=data');
});
});
});
}
add() {
const { data } = this.props;
User.needLogin().then(() => {
Order.addCheckout({ productType: 'data', productId: data.id }).then(() => {
this.setState({ add: true });
});
});
}
render() {
const { data = {} } = this.props;
const { add } = this.state;
return (
linkTo(`/course/data/detail/${data.id}`)}
/>
¥{data.price}
{data.saleNumber}人
{!data.have && (
)}
{data.have && (
)}
{!data.have && (
)}
{data.have && }
);
}
}
export class TextbookItem extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
const { data = {}, menu, onClick, onMenuClick } = this.props;
return (
onClick()} />
已更新至 {data.number} 题
{formatDate(data.time, 'YYYY-MM-DD HH:mm:ss')}
);
}
}