page.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import { timeRange, getMap } from '@src/services/Tools';
  6. import UserLayout from '../../../layouts/User';
  7. import UserTable from '../../../components/UserTable';
  8. import UserAction from '../../../components/UserAction';
  9. import UserPagination from '../../../components/UserPagination';
  10. import Switch from '../../../components/Switch';
  11. import menu, { refreshQuestionType, refreshStruct } from '../index';
  12. import Tabs from '../../../components/Tabs';
  13. import { TimeRange, AskTarget, QuestionType } from '../../../../Constant';
  14. import { My } from '../../../stores/my';
  15. import { OpenText } from '../../../components/Open';
  16. const AskTargetMap = getMap(AskTarget, 'value', 'label');
  17. const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
  18. const columns = [
  19. {
  20. key: 'questionType',
  21. title: '笔记对象',
  22. width: 140,
  23. render(text, row) {
  24. return row.group ? (
  25. <div className="group">
  26. <Link to={row.userQuestionId ? `/paper/question/${row.userQuestionId}` : `/question/detail/${row.questionNoId}`}>{QuestionTypeMap[text]}</Link>
  27. </div>
  28. ) : (
  29. <div className="sub">{QuestionTypeMap[text]}</div>
  30. );
  31. },
  32. },
  33. {
  34. key: 'title',
  35. title: '更新时间',
  36. width: 100,
  37. render(text, row) {
  38. return row.group ? (
  39. <div className="group">
  40. <Link to={row.userQuestionId ? `/paper/question/${row.userQuestionId}` : `/question/detail/${row.questionNoId}`}>{text}</Link>
  41. </div>
  42. ) : (<div className="sub">
  43. <div className="date">{text.split(' ')[0]}</div>
  44. <div className="date">{text.split(' ')[1]}</div>
  45. </div>
  46. );
  47. },
  48. },
  49. {
  50. key: 'content',
  51. title: '内容',
  52. width: 540,
  53. render(text, row) {
  54. return row.group ? (
  55. <div className="group text-hidden">
  56. <Link to={row.userQuestionId ? `/paper/question/${row.userQuestionId}` : `/question/detail/${row.questionNoId}`}>{text}</Link>
  57. </div>
  58. ) : (
  59. <div className="sub">{text}</div>
  60. );
  61. },
  62. },
  63. ];
  64. export default class extends Page {
  65. constructor(props) {
  66. props.size = 10;
  67. super(props);
  68. }
  69. initState() {
  70. return {
  71. filterMap: {},
  72. sortMap: {},
  73. list: [],
  74. selectList: [],
  75. tab: 'exercise',
  76. timerange: 'today',
  77. };
  78. }
  79. initData() {
  80. const data = Object.assign(this.state, this.state.search);
  81. data.filterMap = this.state.search;
  82. if (data.order) {
  83. data.sortMap = { [data.order]: data.direction };
  84. }
  85. if (data.timerange) {
  86. data.filterMap.timerange = data.timerange;
  87. }
  88. const [startTime, endTime] = timeRange(data.timerange);
  89. refreshQuestionType(this, data.subject, data.questionType, {
  90. all: true,
  91. needSentence: false,
  92. allSubject: true,
  93. }).then(({ questionTypes }) => {
  94. return refreshStruct(this, data.tab, data.one, data.two, {
  95. all: true,
  96. needPreview: false,
  97. needTextbook: true,
  98. }).then(({ structIds, latest, year }) => {
  99. My.listQuestionAsk(
  100. Object.assign(
  101. { module: data.tab, questionTypes, structIds, latest, year, startTime, endTime },
  102. this.state.search,
  103. {
  104. order: Object.keys(data.sortMap)
  105. .map(key => {
  106. return `${key} ${data.sortMap[key]}`;
  107. })
  108. .join(','),
  109. },
  110. ),
  111. ).then(result => {
  112. result.list = result.list.map(row => {
  113. row.group = true;
  114. row.questionType = row.question.questionType;
  115. row.title = row.questionNo.title;
  116. row.content = row.question.description;
  117. return row;
  118. });
  119. this.setState({ list: result.list, total: result.total, page: data.page });
  120. });
  121. });
  122. });
  123. }
  124. onTabChange(tab) {
  125. const data = { tab };
  126. this.refreshQuery(data);
  127. }
  128. onFilter(value) {
  129. this.search(value);
  130. }
  131. onSort(value) {
  132. const keys = Object.keys(value);
  133. // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null });
  134. const { sortMap } = this.state;
  135. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  136. this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null });
  137. }
  138. onChangePage(page) {
  139. this.search({ page });
  140. }
  141. onAction() { }
  142. onSelect(selectList) {
  143. this.setState({ selectList });
  144. }
  145. renderView() {
  146. const { config } = this.props;
  147. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  148. }
  149. renderTable() {
  150. const {
  151. tab,
  152. questionSubjectSelect,
  153. questionSubjectMap = {},
  154. oneSelect,
  155. twoSelectMap = {},
  156. filterMap = {},
  157. sortMap = {},
  158. list = [],
  159. } = this.state;
  160. const { total, page } = this.state;
  161. return (
  162. <div className="table-layout">
  163. <Tabs
  164. border
  165. type="division"
  166. theme="theme"
  167. size="small"
  168. space={2.5}
  169. width={100}
  170. active={tab}
  171. tabs={[{ key: 'exercise', title: '练习' }, { key: 'examination', title: '模考' }]}
  172. onChange={key => this.onTabChange(key)}
  173. />
  174. <UserAction
  175. search
  176. selectList={[
  177. {
  178. children: [
  179. {
  180. key: 'subject',
  181. placeholder: '学科',
  182. select: questionSubjectSelect,
  183. },
  184. {
  185. placeholder: '题型',
  186. key: 'questionType',
  187. be: 'subject',
  188. selectMap: questionSubjectMap,
  189. },
  190. ],
  191. },
  192. {
  193. label: '范围',
  194. children: [
  195. {
  196. key: 'one',
  197. placeholder: '全部',
  198. select: oneSelect,
  199. },
  200. {
  201. key: 'two',
  202. be: 'one',
  203. placeholder: '全部',
  204. selectMap: twoSelectMap,
  205. },
  206. ],
  207. },
  208. {
  209. right: true,
  210. key: 'timerange',
  211. select: TimeRange,
  212. },
  213. ]}
  214. filterMap={filterMap}
  215. onFilter={value => this.onFilter(value)}
  216. />
  217. <UserAction
  218. sortList={[
  219. { right: true, label: '提问时间', key: 'create_time' },
  220. { right: true, label: '回答时间', key: 'ask_time' },
  221. ]}
  222. sortMap={sortMap}
  223. left={
  224. <div className="email">
  225. 只看已回答{' '}
  226. <Switch
  227. checked={Number(filterMap.askStatus)}
  228. onChange={() => {
  229. filterMap.askStatus = Number(filterMap.askStatus) ? 0 : 1;
  230. this.onFilter(filterMap);
  231. }}
  232. />
  233. </div>
  234. }
  235. onSort={value => this.onSort(value)}
  236. />
  237. {list.map(item => {
  238. return (
  239. <div className="group">
  240. <UserTable border={false} size="small" columns={columns} data={[item]} header={false} />
  241. <div className="answer-layout">
  242. <div className="title">
  243. 提问区域: <b>{AskTargetMap[item.target]}</b>
  244. </div>
  245. <div className="small-tag">提问</div>
  246. <div className="desc">
  247. <OpenText>{item.content}</OpenText>
  248. </div>
  249. {item.answerStatus > 0 && <div className="small-tag">回答</div>}
  250. {item.answerStatus > 0 && <div className="desc">
  251. <OpenText>{item.answer}</OpenText>
  252. </div>}
  253. </div>
  254. </div>
  255. );
  256. })}
  257. {total > 0 && list.length > 0 && (
  258. <UserPagination total={total} current={page} onChange={p => this.onChangePage(p)} />
  259. )}
  260. </div>
  261. );
  262. }
  263. }