1
0

page.js 9.2 KB

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