page.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import React from 'react';
  2. import './index.less';
  3. import { Icon, Radio } from 'antd';
  4. import Page from '@src/containers/Page';
  5. import { asyncSMessage } from '@src/services/AsyncTools';
  6. import { getMap, formatMoney, formatDate } from '@src/services/Tools';
  7. import UserLayout from '../../../layouts/User';
  8. import menu from '../index';
  9. import UserTable from '../../../components/UserTable';
  10. import Modal from '../../../components/Modal';
  11. import More from '../../../components/More';
  12. import IconButton from '../../../components/IconButton';
  13. import { Order } from '../../../stores/order';
  14. import { RecordSource, ServiceKey, InvoiceType } from '../../../../Constant';
  15. const RecordSourceMap = getMap(RecordSource, 'value', 'label');
  16. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  17. function formatTitle(record) {
  18. if (record.productType === 'course-package') {
  19. return (record.coursePackage || {}).title;
  20. }
  21. if (record.productType === 'course') {
  22. return (record.course || {}).title;
  23. }
  24. if (record.productType === 'data') {
  25. return (record.data || {}).title;
  26. }
  27. if (record.productType === 'service') {
  28. return `${ServiceKeyMap[record.service]}`;
  29. }
  30. return '';
  31. }
  32. export default class extends Page {
  33. constructor(props) {
  34. props.size = 15;
  35. super(props);
  36. }
  37. init() {
  38. this.columns = [
  39. {
  40. title: '订单编号',
  41. key: 'id',
  42. render: (text) => {
  43. return text;
  44. },
  45. },
  46. {
  47. title: '服务',
  48. key: 'title',
  49. render: (text, record) => {
  50. const actionList = [];
  51. // if (record.canInvoice && !record.hasInvoice) {
  52. actionList.push({ key: 'invoice', label: '开发票' });
  53. // }
  54. actionList.push({ key: 'detail', label: '订单详情' });
  55. const onAction = (value) => {
  56. const { key } = value;
  57. switch (key) {
  58. case 'invoice':
  59. this.setState({ showInvoice: true, invoice: { orderId: record.id, money: record.invoiceMoney, invoiceType: InvoiceType[0].value } });
  60. break;
  61. case 'detail':
  62. openLink(`/order/detail/${record.id}`);
  63. break;
  64. default:
  65. }
  66. };
  67. let content = [];
  68. if (record.checkouts.length > 3) {
  69. content.push(<div className="flex-layout m-b-5">
  70. <div className="flex-block">{formatTitle(record.checkouts[0])}<br />等{record.checkouts.length}个商品</div>
  71. <More menu={actionList} onClick={onAction} ><IconButton type="more" /></More>
  72. </div>);
  73. } else {
  74. content = record.checkouts.map((row, index) => {
  75. return <div className="flex-layout m-b-5">
  76. <div className="flex-block">{formatTitle(row)}</div>
  77. {index === 0 && <More menu={actionList} onClick={onAction} ><IconButton type="more" /></More>}
  78. {row.productType === 'data' && <IconButton type="download" onClick={() => {
  79. openLink(row.data.resource);
  80. }} />}
  81. </div>;
  82. });
  83. }
  84. return <div className="t-2">
  85. {content}
  86. </div >;
  87. },
  88. },
  89. {
  90. title: '购买时间',
  91. key: 'createTime',
  92. render: text => {
  93. return <div className="sub">
  94. <div className="t-2 t-s-12">{text.split(' ')[0]}</div>
  95. <div className="t-6 t-s-12">{text.split(' ')[1]}</div>
  96. </div>;
  97. },
  98. },
  99. {
  100. title: '付款方式',
  101. key: 'payMethod',
  102. render: (text) => {
  103. return RecordSourceMap[text];
  104. },
  105. },
  106. {
  107. title: '付款金额',
  108. key: 'money',
  109. render: text => {
  110. return <span className='t-7'>¥{formatMoney(text)}</span>;
  111. },
  112. },
  113. ];
  114. }
  115. initState() {
  116. return {
  117. list: [],
  118. };
  119. }
  120. initData() {
  121. Order.list(this.state.search).then(result => {
  122. result.list = result.list.map(row => {
  123. row.checkouts = row.checkouts || [];
  124. row.createTime = formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss');
  125. return row;
  126. });
  127. this.setState({ list: result.list, total: result.total, page: this.state.search.page });
  128. });
  129. }
  130. onChangePage(page) {
  131. this.search({ page });
  132. }
  133. submitInvoice(invoice) {
  134. if (!invoice.title) return;
  135. if (invoice.invoiceType === 'enterprise' && !invoice.identity) return;
  136. Order.openInvoice(invoice)
  137. .then(() => {
  138. this.refresh();
  139. this.setState({ showFinish: true, showInvoice: false, invoice: {} });
  140. })
  141. .catch(e => {
  142. asyncSMessage(e.message, 'error');
  143. });
  144. }
  145. renderView() {
  146. const { config } = this.props;
  147. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  148. }
  149. renderTable() {
  150. const { list, total, page, showInvoice, showInvoiceFinish, invoice = {} } = this.state;
  151. const { info } = this.props.user;
  152. return (
  153. <div className="table-layout">
  154. <UserTable
  155. size="small"
  156. columns={this.columns}
  157. data={list}
  158. onChange={p => this.onChangePage(p)}
  159. total={total}
  160. current={page}
  161. pageSize={this.state.search.size}
  162. />
  163. <Modal show={showInvoice} title="开发票" width={630} btnType="link" confirmText="申请" onConfirm={() => this.submitInvoice(invoice)} onCancel={() => this.setState({ showInvoice: false })}>
  164. <div className="input-layout m-b-2 t-2 t-s-16">
  165. <div className="label m-r-5">发票类型:</div>
  166. <div className="input-block">
  167. <Radio checked />
  168. 普通增值税电子发票
  169. </div>
  170. </div>
  171. <div className="input-layout m-b-2 t-2 t-s-16">
  172. <div className="label m-r-5">抬头类型:</div>
  173. <div className="input-block">
  174. {InvoiceType.map(row => {
  175. return <span className="m-r-2">
  176. <Radio checked={invoice.invoiceType === row.value} onChange={() => {
  177. invoice.invoiceType = row.value;
  178. this.setState({ invoice });
  179. }} />
  180. {row.label}
  181. </span>;
  182. })}
  183. </div>
  184. </div>
  185. <div className="input-layout m-b-2 t-2 t-s-16">
  186. <div className="label m-r-5">发票抬头:</div>
  187. <div className="input-block">
  188. <input value={invoice.title} style={{ width: 330, paddingTop: 3, paddingBottom: 3 }} className="b-c-1 p-l-1 p-r-1 p-l-1" onChange={e => {
  189. invoice.title = e.target.value;
  190. this.setState({ invoice });
  191. }} />
  192. </div>
  193. </div>
  194. {invoice.invoiceType === 'enterprise' && <div className="input-layout m-b-2 t-2 t-s-16">
  195. <div className="label m-r-5">纳税人识别号:</div>
  196. <div className="input-block">
  197. <input value={invoice.identity} style={{ width: 300, paddingTop: 3, paddingBottom: 3 }} className="b-c-1 p-l-1 p-r-1 p-l-1" onChange={e => {
  198. invoice.identity = e.target.value;
  199. this.setState({ invoice });
  200. }} />
  201. </div>
  202. </div>}
  203. <div className="input-layout m-b-2 t-2 t-s-16">
  204. <div className="label m-r-5">发票内容:</div>
  205. <div className="input-block">
  206. <Radio checked />
  207. 商品明细
  208. </div>
  209. </div>
  210. <div className="input-layout t-2 t-s-16">
  211. <div className="label m-r-5">发票金额:</div>
  212. <div className="input-block">¥ {formatMoney(invoice.money)}</div>
  213. </div>
  214. </Modal>
  215. <Modal show={showInvoiceFinish} title="申请成功" width={630} confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showInvoiceFinish: false })}>
  216. <div className="t-2 t-s-18">
  217. <Icon className="t-5 m-r-5" type="check" />
  218. 我们会在三个工作日内将电子发票发送至您的绑定邮箱:
  219. </div>
  220. <div className="t-2 t-s-18">{info.email}</div>
  221. <div className="m-b-2 t-2 t-s-18">请注意查收。</div>
  222. <div className="m-t-2 t-3 t-s-14">我们也会通过站内信的方式通知您</div>
  223. </Modal>
  224. </div>
  225. );
  226. }
  227. }