1
0

page.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React from 'react';
  2. import './index.less';
  3. import { ListView } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import ListData from '@src/services/ListData';
  6. import { BuyBlock } from '../../../components/Block';
  7. import { Order } from '../../../stores/order';
  8. export default class extends Page {
  9. initState() {
  10. return {
  11. listMap: {},
  12. };
  13. }
  14. init() {
  15. }
  16. initData() {
  17. return this.initListKeys(['data']).then(() => {
  18. return this.getList('data', 1);
  19. });
  20. }
  21. initListKeys(keys) {
  22. const { listMap = {} } = this.state;
  23. keys.forEach(key => {
  24. listMap[key] = new ListData();
  25. });
  26. this.setState({ listMap });
  27. return Promise.resolve();
  28. }
  29. getList(key, page) {
  30. Order.listRecord(Object.assign({ page }, this.state.search)).then(result => {
  31. const { listMap = {} } = this.state;
  32. if (page === 1) {
  33. // todo 是否重新读取第一页为刷新所有数据
  34. listMap[key] = new ListData();
  35. }
  36. listMap[key].get(page, result, this.state.search.size);
  37. this.setState({ listMap });
  38. });
  39. }
  40. renderView() {
  41. return (
  42. this.renderList()
  43. );
  44. }
  45. renderRow(rowData) {
  46. let theme = 'default';
  47. if (!rowData.isUsed) {
  48. theme = 'not';
  49. } else if (rowData.useEndTime && new Date(rowData.useEndTime).getTime() < new Date().getTime()) {
  50. theme = 'end';
  51. }
  52. return <BuyBlock data={rowData} theme={theme} onOpen={() => {
  53. linkTo(`/open/${rowData.id}`);
  54. }} onBuy={() => {
  55. linkTo(`/product/service/${rowData.service}`);
  56. }} onRead={() => {
  57. openLink(rowData.data.resource);
  58. }} />;
  59. }
  60. renderList() {
  61. const { listMap } = this.state;
  62. const { data = {} } = listMap;
  63. const { dataSource = {}, bottom, loading, finish, maxSectionId = 1, total } = data;
  64. if (total === 0) return this.renderEmpty();
  65. return (
  66. <ListView
  67. className="list"
  68. ref={el => {
  69. this.lv = el;
  70. }}
  71. dataSource={dataSource}
  72. renderFooter={() => (
  73. <div style={{ padding: 30, textAlign: 'center' }}>{loading ? '加载中...' : bottom ? '没有更多了' : ''}</div>
  74. )}
  75. renderRow={(rowData, sectionID, rowID) => this.renderRow(rowData, sectionID, rowID)}
  76. style={{
  77. height: this.state.height,
  78. overflow: 'auto',
  79. }}
  80. pageSize={this.state.search.size}
  81. scrollRenderAheadDistance={500}
  82. onEndReached={() => {
  83. if (loading) return;
  84. if (bottom) {
  85. if (!finish) {
  86. data.finish = true;
  87. // this.setState({ time: new Date() })
  88. }
  89. return;
  90. }
  91. this.getList('data', maxSectionId + 1);
  92. }}
  93. onEndReachedThreshold={10}
  94. />
  95. );
  96. }
  97. renderEmpty() {
  98. return <div />;
  99. }
  100. }