page.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React, { Component } from 'react';
  2. import { ListView } from 'antd-mobile';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import ListData from '@src/services/ListData';
  7. // import Tag from '../../../components/Tag';
  8. import { My } from '../../../stores/my';
  9. import { formatDate } from '../../../../../src/services/Tools';
  10. class Item extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = { show: false };
  14. }
  15. render() {
  16. const { data } = this.props;
  17. const { show } = this.state;
  18. return (
  19. <div className="item">
  20. <div className="title">
  21. {data.data.title}<span className="date">{data.time && formatDate(data.time, 'YYYY-MM-DD')}</span>
  22. </div>
  23. <div className="tip">
  24. 变更点:{data.version}
  25. </div>
  26. <div hidden={!show} className="desc">
  27. 位置 {data.position}原内容 {data.originContent} 更改为 {data.content}
  28. </div>
  29. <Assets
  30. className="drop"
  31. name={!show ? 'drop_down1' : 'drop_up1'}
  32. onClick={() => this.setState({ show: !show })}
  33. />
  34. </div>
  35. );
  36. }
  37. }
  38. export default class extends Page {
  39. initState() {
  40. return {
  41. listMap: {},
  42. };
  43. }
  44. initData() {
  45. My.listData(this.state.search).then(result => {
  46. this.setTableData(result.list, result.total);
  47. });
  48. return this.initListKeys(['history'])
  49. .then(() => {
  50. return this.getList('history', 1);
  51. });
  52. }
  53. initListKeys(keys) {
  54. const { listMap } = this.state;
  55. keys.forEach((key) => {
  56. listMap[key] = new ListData();
  57. });
  58. this.setState({ listMap });
  59. return Promise.resolve();
  60. }
  61. getList(key, page) {
  62. My.dataHistory(Object.assign({ page }, this.state.search))
  63. .then((result) => {
  64. const { listMap } = this.state;
  65. if (page === 1) { // todo 是否重新读取第一页为刷新所有数据
  66. listMap[key] = new ListData();
  67. }
  68. listMap[key].get(page, result, this.state.search.size);
  69. this.setState({ listMap });
  70. });
  71. }
  72. renderView() {
  73. return this.renderList();
  74. }
  75. renderRow(rowData) {
  76. return <Item data={rowData} />;
  77. }
  78. renderList() {
  79. const { listMap } = this.state;
  80. const { history = {} } = listMap;
  81. const { dataSource = {}, bottom, loading, finish, maxSectionId = 1, total } = history;
  82. if (total === 0) return this.renderEmpty();
  83. return <ListView
  84. className="list"
  85. ref={el => { this.lv = el; }}
  86. dataSource={dataSource}
  87. renderFooter={() => (<div style={{ padding: 30, textAlign: 'center' }}>
  88. {loading ? '加载中...' : (bottom ? '没有更多了' : '')}
  89. </div>)}
  90. renderRow={(rowData, sectionID, rowID) => this.renderRow(rowData, sectionID, rowID)}
  91. style={{
  92. height: this.state.height,
  93. overflow: 'auto',
  94. }}
  95. pageSize={this.state.search.size}
  96. scrollRenderAheadDistance={500}
  97. onEndReached={() => {
  98. if (loading) return;
  99. if (bottom) {
  100. if (!finish) {
  101. history.finish = true;
  102. // this.setState({ time: new Date() })
  103. }
  104. return;
  105. }
  106. this.getList('history', maxSectionId + 1);
  107. }}
  108. onEndReachedThreshold={10}
  109. />;
  110. }
  111. renderEmpty() {
  112. const { list = [] } = this.state;
  113. return list.length === 0 ? this.renderNoData() : <div className="empty">资料还没有更新记录</div>;
  114. }
  115. renderNoData() {
  116. return <div className="empty">还未购买或订阅资料</div>;
  117. }
  118. }