import React, { Component } from 'react'; import './index.less'; import { Icon, Radio } from 'antd'; import Assets from '@src/components/Assets'; import Page from '@src/containers/Page'; import { asyncSMessage } from '@src/services/AsyncTools'; import CheckboxItem from '../../../components/CheckboxItem'; import Button from '../../../components/Button'; import Modal from '../../../components/Modal'; import UserTable from '../../../components/UserTable'; import { Order } from '../../../stores/order'; import { Course } from '../../../stores/course'; import { User } from '../../../stores/user'; import { getMap } from '../../../../../src/services/Tools'; import { CourseVsType } from '../../../../Constant'; const CourseVsTypeMap = getMap(CourseVsType, 'value', 'tips'); export default class extends Page { initState() { return { courses: [] }; } init() { Course.allVs() .then(result => { // 赠送选择选择 this.setState({ courses: result.filter(row => ['novice', 'coach'].indexOf(row.vsType) >= 0) }); }); } initData() { // Order.getOrder(34) // .then((order) => { // User.needPay(order); // }); Order.allCheckout() .then(result => { User.formatOrder(result); this.setState({ order: result, list: result.checkouts }); }); } onAll(checked) { const { selectList = [] } = this.state; const { list = [] } = this.state; if (checked) { list.forEach(item => { if (selectList.indexOf(item.key) >= 0) return; selectList.push(item.key); }); } else { list.forEach(item => { const index = selectList.indexOf(item.key); if (index < 0) return; selectList.splice(index, 1); }); } this.setState({ selectList, allChecked: checked }); } onSelect(key, checked) { const { selectList = [] } = this.state; if (checked) { selectList.push(key); } else { selectList.splice(selectList.indexOf(key), 1); } this.setState({ selectList, allChecked: false }); } onDelete(list) { Promise.all(list.map(row => { return Order.removeCheckout(row); })) .then(() => { this.refresh(); }); } onChangeNumber(id, number) { Order.changeCheckout(id, number) .then(() => { this.refresh(); }); } pay() { const { courseId, list, order } = this.state; if (list.length === 0) return; if (order.gift && order.gift.filter(row => row.key === 'vs').length > 0 && !courseId) { // 请选择课程 asyncSMessage('请选择赠送的课程', 'warn'); return; } Order.confirmPay(courseId) .then(result => { return User.needPay(result) .then(() => { linkTo(`/order/${result.id}`); }) .catch(() => { this.refresh(); }); }); } renderView() { const { courses = [], order = {}, list = [], allChecked, selectList = [], courseId } = this.state; return (
购物车
{(list || []).map(item => { return [ item.productType === 'course_package' &&
您看中的课程已构成套餐,结算有优惠
, = 0} onDelete={() => this.onDelete([item.id])} onCheck={(checked) => this.onSelect(item.id, checked)} onChangeNumber={(number) => this.onChangeNumber(item.id, number)} />, ]; })}
{(order.gift || []).map(item => { return item.key === 'vs' && this.setState({ courseId: id })} />; })}
this.onAll(!allChecked)} /> 全选
{order.promote && order.promote.length > 0 && [
优惠活动:
,
{order.promote.map(row => { return
{row.message}
; })}
, ]}
实付 ¥ {order.money || 0}
原价¥ {order.originMoney || 0}
); } } class GiftItem extends Component { render() { const { data } = this.props; return (
{this.renderInfo()} {data.key === 'vs' && this.renderVs()}
); } renderInfo() { const { data } = this.props; let message = ''; if (data.money) { message = `实付金额满${data.money}元赠送`; } else if (data.from === 'vsNumber') { message = `1VS1课程满${data.number}节赠送`; } return (
{data.message}
{message}
); } renderVs() { const { courses, courseId, onSelectCourse } = this.props; return (
请选择
可至「个人中心-课程」预约辅导时间。
{courses.map(course => { return
onSelectCourse(course.id)} /> {course.title}
{CourseVsTypeMap[course.vsType]}
; })}
); } } class OrderItem extends Component { constructor(props) { super(props); this.state = { open: false, showList: false }; this.columns = [{ key: 'label', title: '服务', }, { key: 'expireDays', title: '开通有效期', render: (text, checkout) => { return checkout.expireDays ? `${checkout.expireDays}天` : '付款后立即生效'; }, }, { key: 'useExpireDays', title: '使用有效期', render: (text, checkout) => { return checkout.useExpireDays ? `${checkout.useExpireDays}天` : '永久'; }, }]; } render() { const { data } = this.props; const { showList } = this.state; return (
{this.renderInfo()} {(data.children || data.gift) && this.renderDetail()} this.setState({ showList: false })} className='order-modal' >
); } renderInfo() { const { data, onCheck, onDelete, onChangeNumber, checked } = this.props; const checkout = data; return (
onCheck(!checked)} /> onDelete()} />
{data.title}
{data.productType !== 'course_package' &&
开通有效期: {checkout.expireDays ? `${checkout.expireDays}天` : '付款后立即生效'} 使用有效期: {checkout.useExpireDays ? `${checkout.useExpireDays}天` : '永久'}
}
{data.number > 0 && ['数量', , data.number < data.maxNumber && onChangeNumber(data.number + 1)} />, data.number > 1 && data.number > data.minNumber && onChangeNumber(data.number - 1)} />]}
¥ {data.money}
); } renderDetail() { const { data = {} } = this.props; const { children = [], gift } = data; const { open } = this.state; return (
{gift &&
赠送服务 {gift.map(row => { return `${row.label}x${row.param ? row.param.label : row.number}`; }).join(' ')} { this.setState({ showList: true }); }} />
}
); } }