page.js 8.9 KB

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