import React from 'react';
import './index.less';
import { Icon, Radio } from 'antd';
import Page from '@src/containers/Page';
import { asyncSMessage } from '@src/services/AsyncTools';
import { getMap, formatMoney, formatDate } from '@src/services/Tools';
import UserLayout from '../../../layouts/User';
import menu from '../index';
import UserTable from '../../../components/UserTable';
import Modal from '../../../components/Modal';
import More from '../../../components/More';
import IconButton from '../../../components/IconButton';
import { Order } from '../../../stores/order';
import { RecordSource, ServiceKey, InvoiceType } from '../../../../Constant';
const RecordSourceMap = getMap(RecordSource, 'value', 'label');
const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
function formatTitle(record) {
if (record.productType === 'course-package') {
return (record.coursePackage || {}).title;
}
if (record.productType === 'course') {
return (record.course || {}).title;
}
if (record.productType === 'data') {
return (record.data || {}).title;
}
if (record.productType === 'service') {
return `${ServiceKeyMap[record.service]}`;
}
return '';
}
export default class extends Page {
constructor(props) {
props.size = 15;
super(props);
}
init() {
this.columns = [
{
title: '订单编号',
key: 'id',
render: text => {
return text;
},
},
{
title: '服务',
key: 'title',
render: (text, record) => {
const actionList = [];
// if (record.canInvoice && !record.hasInvoice) {
actionList.push({ key: 'invoice', label: '开发票' });
// }
actionList.push({ key: 'detail', label: '订单详情' });
const onAction = value => {
const { key } = value;
switch (key) {
case 'invoice':
this.setState({
showInvoice: true,
invoice: { orderId: record.id, money: record.invoiceMoney, invoiceType: InvoiceType[0].value },
});
break;
case 'detail':
openLink(`/order/detail/${record.id}`);
break;
default:
}
};
let content = [];
if (record.checkouts.length > 3) {
content.push(
{formatTitle(record.checkouts[0])}
等{record.checkouts.length}个商品
,
);
} else {
content = record.checkouts.map((row, index) => {
return (
{formatTitle(row)}
{index === 0 && (
)}
{row.productType === 'data' && (
{
openLink(row.data.resource);
}}
/>
)}
);
});
}
return {content}
;
},
},
{
title: '购买时间',
key: 'createTime',
render: text => {
return (
{text.split(' ')[0]}
{text.split(' ')[1]}
);
},
},
{
title: '付款方式',
key: 'payMethod',
render: text => {
return RecordSourceMap[text];
},
},
{
title: '付款金额',
key: 'money',
render: text => {
return ¥{formatMoney(text)};
},
},
];
}
initState() {
return {
list: [],
};
}
initData() {
Order.list(this.state.search).then(result => {
result.list = result.list.map(row => {
row.checkouts = row.checkouts || [];
row.createTime = formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss');
return row;
});
this.setState({ list: result.list, total: result.total, page: this.state.search.page });
});
}
onChangePage(page) {
this.search({ page });
}
submitInvoice(invoice) {
if (!invoice.title) return;
if (invoice.invoiceType === 'enterprise' && !invoice.identity) return;
Order.openInvoice(invoice)
.then(() => {
this.refresh();
this.setState({ showFinish: true, showInvoice: false, invoice: {} });
})
.catch(e => {
asyncSMessage(e.message, 'error');
});
}
renderView() {
const { config } = this.props;
return ;
}
renderTable() {
const { list, total, page, showInvoice, showInvoiceFinish, invoice = {} } = this.state;
const { info } = this.props.user;
return (
this.onChangePage(p)}
total={total}
current={page}
pageSize={this.state.search.size}
/>
this.submitInvoice(invoice)}
onCancel={() => this.setState({ showInvoice: false })}
>
抬头类型:
{InvoiceType.map(row => {
return (
{
invoice.invoiceType = row.value;
this.setState({ invoice });
}}
/>
{row.label}
);
})}
{invoice.invoiceType === 'enterprise' && (
)}
发票金额:
¥ {formatMoney(invoice.money)}
this.setState({ showInvoiceFinish: false })}
>
我们会在三个工作日内将电子发票发送至您的绑定邮箱:
{info.email}
请注意查收。
我们也会通过站内信的方式通知您
);
}
}