page.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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({
  60. showInvoice: true,
  61. invoice: { orderId: record.id, money: record.invoiceMoney, invoiceType: InvoiceType[0].value },
  62. });
  63. break;
  64. case 'detail':
  65. openLink(`/order/detail/${record.id}`);
  66. break;
  67. default:
  68. }
  69. };
  70. let content = [];
  71. if (record.checkouts.length > 3) {
  72. content.push(
  73. <div className="flex-layout m-b-5">
  74. <div className="flex-block">
  75. {formatTitle(record.checkouts[0])}
  76. <br />等{record.checkouts.length}个商品
  77. </div>
  78. <More menu={actionList} onClick={onAction}>
  79. <IconButton type="more" />
  80. </More>
  81. </div>,
  82. );
  83. } else {
  84. content = record.checkouts.map((row, index) => {
  85. return (
  86. <div className="flex-layout m-b-5">
  87. <div className="flex-block">{formatTitle(row)}</div>
  88. {index === 0 && (
  89. <More menu={actionList} onClick={onAction}>
  90. <IconButton type="more" />
  91. </More>
  92. )}
  93. {row.productType === 'data' && (
  94. <IconButton
  95. type="download"
  96. onClick={() => {
  97. openLink(row.data.resource);
  98. }}
  99. />
  100. )}
  101. </div>
  102. );
  103. });
  104. }
  105. return <div className="t-2">{content}</div>;
  106. },
  107. },
  108. {
  109. title: '购买时间',
  110. key: 'createTime',
  111. render: text => {
  112. return (
  113. <div className="sub">
  114. <div className="t-2 t-s-12">{text.split(' ')[0]}</div>
  115. <div className="t-6 t-s-12">{text.split(' ')[1]}</div>
  116. </div>
  117. );
  118. },
  119. },
  120. {
  121. title: '付款方式',
  122. key: 'payMethod',
  123. render: text => {
  124. return RecordSourceMap[text];
  125. },
  126. },
  127. {
  128. title: '付款金额',
  129. key: 'money',
  130. render: text => {
  131. return <span className="t-7">¥{formatMoney(text)}</span>;
  132. },
  133. },
  134. ];
  135. }
  136. initState() {
  137. return {
  138. list: [],
  139. };
  140. }
  141. initData() {
  142. Order.list(this.state.search).then(result => {
  143. result.list = result.list.map(row => {
  144. row.checkouts = row.checkouts || [];
  145. row.createTime = formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss');
  146. return row;
  147. });
  148. this.setState({ list: result.list, total: result.total, page: this.state.search.page });
  149. });
  150. }
  151. onChangePage(page) {
  152. this.search({ page });
  153. }
  154. submitInvoice(invoice) {
  155. if (!invoice.title) return;
  156. if (invoice.invoiceType === 'enterprise' && !invoice.identity) return;
  157. Order.openInvoice(invoice)
  158. .then(() => {
  159. this.refresh();
  160. this.setState({ showFinish: true, showInvoice: false, invoice: {} });
  161. })
  162. .catch(e => {
  163. asyncSMessage(e.message, 'error');
  164. });
  165. }
  166. renderView() {
  167. const { config } = this.props;
  168. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  169. }
  170. renderTable() {
  171. const { list, total, page, showInvoice, showInvoiceFinish, invoice = {} } = this.state;
  172. const { info } = this.props.user;
  173. return (
  174. <div className="table-layout">
  175. <UserTable
  176. size="small"
  177. columns={this.columns}
  178. data={list}
  179. onChange={p => this.onChangePage(p)}
  180. total={total}
  181. current={page}
  182. pageSize={this.state.search.size}
  183. />
  184. <Modal
  185. show={showInvoice}
  186. title="开发票"
  187. width={630}
  188. btnType="link"
  189. confirmText="申请"
  190. onConfirm={() => this.submitInvoice(invoice)}
  191. onCancel={() => this.setState({ showInvoice: false })}
  192. >
  193. <div className="input-layout m-b-2 t-2 t-s-16">
  194. <div className="label m-r-5">发票类型:</div>
  195. <div className="input-block">
  196. <Radio checked />
  197. 普通增值税电子发票
  198. </div>
  199. </div>
  200. <div className="input-layout m-b-2 t-2 t-s-16">
  201. <div className="label m-r-5">抬头类型:</div>
  202. <div className="input-block">
  203. {InvoiceType.map(row => {
  204. return (
  205. <span className="m-r-2">
  206. <Radio
  207. checked={invoice.invoiceType === row.value}
  208. onChange={() => {
  209. invoice.invoiceType = row.value;
  210. this.setState({ invoice });
  211. }}
  212. />
  213. {row.label}
  214. </span>
  215. );
  216. })}
  217. </div>
  218. </div>
  219. <div className="input-layout m-b-2 t-2 t-s-16">
  220. <div className="label m-r-5">发票抬头:</div>
  221. <div className="input-block">
  222. <input
  223. value={invoice.title}
  224. style={{ width: 330, paddingTop: 3, paddingBottom: 3 }}
  225. className="b-c-1 p-l-1 p-r-1 p-l-1"
  226. onChange={e => {
  227. invoice.title = e.target.value;
  228. this.setState({ invoice });
  229. }}
  230. />
  231. </div>
  232. </div>
  233. {invoice.invoiceType === 'enterprise' && (
  234. <div className="input-layout m-b-2 t-2 t-s-16">
  235. <div className="label m-r-5">纳税人识别号:</div>
  236. <div className="input-block">
  237. <input
  238. value={invoice.identity}
  239. style={{ width: 300, paddingTop: 3, paddingBottom: 3 }}
  240. className="b-c-1 p-l-1 p-r-1 p-l-1"
  241. onChange={e => {
  242. invoice.identity = e.target.value;
  243. this.setState({ invoice });
  244. }}
  245. />
  246. </div>
  247. </div>
  248. )}
  249. <div className="input-layout m-b-2 t-2 t-s-16">
  250. <div className="label m-r-5">发票内容:</div>
  251. <div className="input-block">
  252. <Radio checked />
  253. 商品明细
  254. </div>
  255. </div>
  256. <div className="input-layout t-2 t-s-16">
  257. <div className="label m-r-5">发票金额:</div>
  258. <div className="input-block">¥ {formatMoney(invoice.money)}</div>
  259. </div>
  260. </Modal>
  261. <Modal
  262. show={showInvoiceFinish}
  263. title="申请成功"
  264. width={630}
  265. confirmText="好的,知道了"
  266. btnAlign="center"
  267. onConfirm={() => this.setState({ showInvoiceFinish: false })}
  268. >
  269. <div className="t-2 t-s-18">
  270. <Icon className="t-5 m-r-5" type="check" />
  271. 我们会在三个工作日内将电子发票发送至您的绑定邮箱:
  272. </div>
  273. <div className="t-2 t-s-18">{info.email}</div>
  274. <div className="m-b-2 t-2 t-s-18">请注意查收。</div>
  275. <div className="m-t-2 t-3 t-s-14">我们也会通过站内信的方式通知您</div>
  276. </Modal>
  277. </div>
  278. );
  279. }
  280. }