1
0

page.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Drawer, Picker, List } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { getMap, formatDate } from '@src/services/Tools';
  7. import Switch from '../../../components/Switch';
  8. import Icon from '../../../components/Icon';
  9. import { SpecialRadioGroup } from '../../../components/Radio';
  10. import Button from '../../../components/Button';
  11. import { TextbookQuality, TextbookSubject } from '../../../../Constant';
  12. import { Textbook } from '../../../stores/textbook';
  13. const TextbookSubjectMap = getMap(TextbookSubject, 'value', 'label');
  14. class Detail extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = { show: false };
  18. }
  19. render() {
  20. const { show, data = {} } = this.state;
  21. return (
  22. <div className="detail">
  23. <div className="detail-title">{data.no || 0}.{data.keyword}</div>
  24. <div className="detail-desc" dangerouslySetInnerHTML={{ __html: data.detail }} />
  25. <div className="detail-switch">
  26. 显示答案
  27. <Switch size="small" checked={show} onClick={() => this.setState({ show: !show })} />
  28. </div>
  29. <div hidden={!show} className="detail-result" dangerouslySetInnerHTML={{ __html: data.content }} />
  30. </div>
  31. );
  32. }
  33. }
  34. export default class extends Page {
  35. initState() {
  36. return { pageData: [{ label: 1, value: 1 }] };
  37. }
  38. init() {
  39. const { search } = this.state;
  40. search.isOld = false;
  41. search.qualitys = [];
  42. this.setState({ search });
  43. }
  44. initData() {
  45. Textbook.getInfo()
  46. .then(result => {
  47. this.setState(result);
  48. });
  49. const { subject } = this.params;
  50. this.setState({ filter: false });
  51. Textbook.listTopic(Object.assign({ latest: true, subject, order: 'updateTime' }, this.state.search))
  52. .then(result => {
  53. this.setTableData(result.list, result.total);
  54. const pageData = [];
  55. let i = 0;
  56. let page = 1;
  57. while (i < result.total) {
  58. pageData.push({ label: page, value: page });
  59. i += this.state.search.size;
  60. page += 1;
  61. }
  62. this.setState({ pageData });
  63. });
  64. }
  65. prev() {
  66. const { search } = this.state;
  67. if (search.page > 1) {
  68. search.page -= 1;
  69. } else {
  70. return;
  71. }
  72. this.setState({ search });
  73. this.refresh();
  74. }
  75. next() {
  76. const { search, page } = this.state;
  77. if (search.page < Math.ceil(page.total / page.pageSize)) {
  78. search.page += 1;
  79. } else {
  80. return;
  81. }
  82. this.setState({ search });
  83. this.refresh();
  84. }
  85. changeQuality(value) {
  86. const { search = {} } = this.state;
  87. const { qualitys = [] } = search;
  88. const index = qualitys.indexOf(value);
  89. if (index >= 0) {
  90. qualitys.splice(index, 1);
  91. } else {
  92. qualitys.push(value);
  93. }
  94. search.qualitys = qualitys;
  95. this.setState({ search });
  96. }
  97. changeOld() {
  98. const { search = {} } = this.state;
  99. search.isOld = !search.isOld;
  100. this.setState({ search });
  101. }
  102. changeDirection(direction) {
  103. const { search = {} } = this.state;
  104. search.direction = direction;
  105. this.setState({ search });
  106. }
  107. changePage(page) {
  108. const { search = {} } = this.state;
  109. if (search.page === page) return;
  110. search.page = page;
  111. this.refresh();
  112. }
  113. renderView() {
  114. const { subject } = this.params;
  115. const { filter, search, pageData, list, latest = {} } = this.state;
  116. return (
  117. <Drawer
  118. style={{ minHeight: document.documentElement.clientHeight }}
  119. position="right"
  120. open={filter}
  121. sidebar={this.renderFilter()}
  122. onOpenChange={isOpen => this.setState({ filter: isOpen })}
  123. >
  124. <div className="title">【{TextbookSubjectMap[subject]}】{latest.startDate ? formatDate(latest.startDate, 'MMDD') : ''} 起{TextbookSubjectMap[subject]}机经整理</div>
  125. <div className="detail-list">
  126. {list.map(row => <Detail data={row} />)}
  127. </div>
  128. <div className="fixed">
  129. <div className="prev" onClick={() => {
  130. this.prev();
  131. }}>
  132. <Icon type="left" />
  133. Previous
  134. </div>
  135. <div className="next" onClick={() => {
  136. this.next();
  137. }}>
  138. Next
  139. <Icon type="right" />
  140. </div>
  141. <div className="page">
  142. <Picker title="选择页数"
  143. cols={1}
  144. value={[this.state.search.page]}
  145. data={pageData}
  146. onChange={(i) => {
  147. this.changePage(i[0]);
  148. }}><List.Item><span>跳转至</span>第{search.page}页<Assets name="down_down3" /></List.Item>
  149. </Picker>
  150. </div>
  151. </div>
  152. <div hidden={filter} className="filter-switch">
  153. <Assets name="setting" onClick={() => this.setState({ filter: true })} />
  154. </div>
  155. </Drawer>
  156. );
  157. }
  158. renderFilter() {
  159. const { search } = this.state;
  160. return (
  161. <div className="filter">
  162. <div className="body">
  163. <div className="item">
  164. <div className="label">机经质量</div>
  165. <div className="value">
  166. <SpecialRadioGroup
  167. list={TextbookQuality}
  168. values={search.qualitys}
  169. onChange={(value) => {
  170. this.changeQuality(value);
  171. }}
  172. />
  173. </div>
  174. </div>
  175. <div className="item">
  176. <div className="label left">更新时间</div>
  177. <div className="value right">
  178. <Picker title="更新时间"
  179. cols={1}
  180. value={[this.state.search.direction]}
  181. data={[{ label: '由远到近', value: 'asc' }, { label: '由近到远', value: 'desc' }]}
  182. onChange={(i) => {
  183. this.changeDirection(i[0]);
  184. }}><List.Item extra={false}>{search.direction === 'asc' ? '由远到近' : '由近到远'} <Assets className="arrow" name="down_down3" /></List.Item>
  185. </Picker>
  186. </div>
  187. </div>
  188. <div className="item">
  189. <div className="label left">看考古</div>
  190. <div className="value right">
  191. <Switch checked={search.isOld} onClick={() => {
  192. this.changeOld();
  193. }} />
  194. </div>
  195. </div>
  196. </div>
  197. <div className="footer">
  198. <Button radius width={90} onClick={() => {
  199. this.refresh();
  200. }}>
  201. 确定
  202. </Button>
  203. </div>
  204. </div>
  205. );
  206. }
  207. }