page.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Block from '@src/components/Block';
  5. import FilterLayout from '@src/layouts/FilterLayout';
  6. import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { getMap, formatDate, bindSearch } from '@src/services/Tools';
  9. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  10. import { SwitchSelect, InvoiceType } from '../../../../Constant';
  11. import { User } from '../../../stores/user';
  12. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  13. const InvoiceTypeMap = getMap(InvoiceType, 'value', 'label');
  14. export default class extends Page {
  15. init() {
  16. this.exerciseMap = {};
  17. this.filterForm = [{
  18. key: 'userId',
  19. type: 'select',
  20. allowClear: true,
  21. name: '用户',
  22. select: [],
  23. number: true,
  24. placeholder: '请输入',
  25. }, {
  26. key: 'isDownload',
  27. type: 'select',
  28. allowClear: true,
  29. name: '下载状态',
  30. select: SwitchSelect,
  31. number: true,
  32. }, {
  33. key: 'isFinish',
  34. type: 'select',
  35. allowClear: true,
  36. name: '开票状态',
  37. select: SwitchSelect,
  38. number: true,
  39. }];
  40. this.actionList = [{
  41. key: 'download',
  42. name: '下载',
  43. needSelect: 1,
  44. }, {
  45. key: 'finish',
  46. name: '批量开票',
  47. needSelect: 1,
  48. }];
  49. this.columns = [{
  50. title: '申请时间',
  51. dataIndex: 'createTime',
  52. render: (text) => {
  53. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  54. },
  55. }, {
  56. title: '申请用户',
  57. dataIndex: 'userId',
  58. render: (text, record) => {
  59. return `${record.user.nickname}`;
  60. },
  61. }, {
  62. title: '发票金额',
  63. dataIndex: 'order.invoiceMoney',
  64. }, {
  65. title: '抬头类型',
  66. dataIndex: 'invoiceType',
  67. render: (text) => {
  68. return InvoiceTypeMap[text] || text;
  69. },
  70. }, {
  71. title: '抬头',
  72. dataIndex: 'title',
  73. }, {
  74. title: '纳税人识别号',
  75. dataIndex: 'identity',
  76. }, {
  77. title: '邮箱',
  78. dataIndex: 'user.email',
  79. }, {
  80. title: '开票状态',
  81. dataIndex: 'isFinish',
  82. render: (text) => {
  83. return SwitchSelectMap[text ? 1 : 0];
  84. },
  85. }, {
  86. title: '下载状态',
  87. dataIndex: 'isDownload',
  88. render: (text) => {
  89. return SwitchSelectMap[text ? 1 : 0];
  90. },
  91. }];
  92. bindSearch(this.filterForm, 'userId', this, (search) => {
  93. return User.list(search);
  94. }, (row) => {
  95. return {
  96. title: `${row.nickname}(${row.mobile})`,
  97. value: row.id,
  98. };
  99. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  100. }
  101. initData() {
  102. User.listInvoice(this.state.search).then(result => {
  103. this.setTableData(result.list, result.total);
  104. });
  105. }
  106. downloadAction() {
  107. const { selectedKeys } = this.state;
  108. asyncDelConfirm('下载确认', '是否下载选中记录?', () => {
  109. openLink(`/api/user/invoice/download?${selectedKeys.map(row => `ids=${row}`).join('&')}`);
  110. });
  111. }
  112. finishAction() {
  113. const { selectedKeys } = this.state;
  114. asyncDelConfirm('开票确认', '是否开票选中记录?', () => {
  115. return User.finishInvoice({ ids: selectedKeys }).then(() => {
  116. asyncSMessage('操作成功!');
  117. this.refresh();
  118. });
  119. });
  120. }
  121. renderView() {
  122. return <Block flex>
  123. {<FilterLayout
  124. show
  125. itemList={this.filterForm}
  126. data={this.state.search}
  127. onChange={data => {
  128. data.page = 1;
  129. this.search(data);
  130. }} />}
  131. <ActionLayout
  132. itemList={this.actionList}
  133. selectedKeys={this.state.selectedKeys}
  134. onAction={key => this.onAction(key)}
  135. />
  136. <TableLayout
  137. select
  138. columns={this.tableSort(this.columns)}
  139. list={this.state.list}
  140. pagination={this.state.page}
  141. loading={this.props.core.loading}
  142. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  143. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  144. selectedKeys={this.state.selectedKeys}
  145. />
  146. </Block>;
  147. }
  148. }