page.js 4.1 KB

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