1
0

page.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. if (!result.hasService) {
  48. linkTo('/textbook');
  49. }
  50. this.setState(result);
  51. });
  52. const { subject } = this.params;
  53. this.setState({ filter: false });
  54. Textbook.listTopic(Object.assign({ latest: true, subject, order: 'updateTime' }, this.state.search))
  55. .then(result => {
  56. this.setTableData(result.list, result.total);
  57. const pageData = [];
  58. let i = 0;
  59. let page = 1;
  60. while (i < result.total) {
  61. pageData.push({ label: page, value: page });
  62. i += this.state.search.size;
  63. page += 1;
  64. }
  65. this.setState({ pageData });
  66. });
  67. }
  68. prev() {
  69. const { search } = this.state;
  70. if (search.page > 1) {
  71. search.page -= 1;
  72. } else {
  73. return;
  74. }
  75. this.setState({ search });
  76. this.refresh();
  77. }
  78. next() {
  79. const { search, page } = this.state;
  80. if (search.page < Math.ceil(page.total / page.pageSize)) {
  81. search.page += 1;
  82. } else {
  83. return;
  84. }
  85. this.setState({ search });
  86. this.refresh();
  87. }
  88. changeQuality(value) {
  89. const { search = {} } = this.state;
  90. const { qualitys = [] } = search;
  91. const index = qualitys.indexOf(value);
  92. if (index >= 0) {
  93. qualitys.splice(index, 1);
  94. } else {
  95. qualitys.push(value);
  96. }
  97. search.qualitys = qualitys;
  98. this.setState({ search });
  99. }
  100. changeOld() {
  101. const { search = {} } = this.state;
  102. search.isOld = !search.isOld;
  103. this.setState({ search });
  104. }
  105. changeDirection(direction) {
  106. const { search = {} } = this.state;
  107. search.direction = direction;
  108. this.setState({ search });
  109. }
  110. changePage(page) {
  111. const { search = {} } = this.state;
  112. if (search.page === page) return;
  113. search.page = page;
  114. this.refresh();
  115. }
  116. renderView() {
  117. const { subject } = this.params;
  118. const { filter, search, pageData, list, latest = {} } = this.state;
  119. return (
  120. <Drawer
  121. style={{ minHeight: document.documentElement.clientHeight }}
  122. position="right"
  123. open={filter}
  124. sidebar={this.renderFilter()}
  125. onOpenChange={isOpen => this.setState({ filter: isOpen })}
  126. >
  127. <div className="title">【{TextbookSubjectMap[subject]}】{latest.startDate ? formatDate(latest.startDate, 'MMDD') : ''} 起{TextbookSubjectMap[subject]}机经整理</div>
  128. <div className="detail-list">
  129. {list.map(row => <Detail data={row} />)}
  130. </div>
  131. <div className="fixed">
  132. <div className="prev" onClick={() => {
  133. this.prev();
  134. }}>
  135. <Icon type="left" />
  136. Previous
  137. </div>
  138. <div className="next" onClick={() => {
  139. this.next();
  140. }}>
  141. Next
  142. <Icon type="right" />
  143. </div>
  144. <div className="page">
  145. <Picker title="选择页数"
  146. cols={1}
  147. value={[this.state.search.page]}
  148. data={pageData}
  149. onChange={(i) => {
  150. this.changePage(i[0]);
  151. }}><List.Item><span>跳转至</span>第{search.page}页<Assets name="down_down3" /></List.Item>
  152. </Picker>
  153. </div>
  154. </div>
  155. <div hidden={filter} className="filter-switch">
  156. <Assets name="setting" onClick={() => this.setState({ filter: true })} />
  157. </div>
  158. </Drawer>
  159. );
  160. }
  161. renderFilter() {
  162. const { search } = this.state;
  163. return (
  164. <div className="filter">
  165. <div className="body">
  166. <div className="item">
  167. <div className="label">机经质量</div>
  168. <div className="value">
  169. <SpecialRadioGroup
  170. list={TextbookQuality}
  171. values={search.qualitys}
  172. onChange={(value) => {
  173. this.changeQuality(value);
  174. }}
  175. />
  176. </div>
  177. </div>
  178. <div className="item">
  179. <div className="label left">更新时间</div>
  180. <div className="value right">
  181. <Picker title="更新时间"
  182. cols={1}
  183. value={[this.state.search.direction]}
  184. data={[{ label: '由远到近', value: 'asc' }, { label: '由近到远', value: 'desc' }]}
  185. onChange={(i) => {
  186. this.changeDirection(i[0]);
  187. }}><List.Item extra={false}>{search.direction === 'asc' ? '由远到近' : '由近到远'} <Assets className="arrow" name="down_down3" /></List.Item>
  188. </Picker>
  189. </div>
  190. </div>
  191. <div className="item">
  192. <div className="label left">看考古</div>
  193. <div className="value right">
  194. <Switch checked={search.isOld} onClick={() => {
  195. this.changeOld();
  196. }} />
  197. </div>
  198. </div>
  199. </div>
  200. <div className="footer">
  201. <Button radius width={90} onClick={() => {
  202. this.search({ page: 1 });
  203. }}>
  204. 确定
  205. </Button>
  206. </div>
  207. </div>
  208. );
  209. }
  210. }