page.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. <a
  27. href={row.userQuestionId ? `/paper/question/${row.userQuestionId}` : `/question/detail/${row.questionNoId}`} target="_blank"
  28. >
  29. {QuestionTypeMap[text]}
  30. </a>
  31. </div>
  32. );
  33. },
  34. },
  35. {
  36. key: 'title',
  37. width: 100,
  38. render(text, row) {
  39. return (
  40. <div className="group">
  41. <a
  42. href={row.userQuestionId ? `/paper/question/${row.userQuestionId}` : `/question/detail/${row.questionNoId}`} target="_blank"
  43. >
  44. {text}
  45. </a>
  46. </div>
  47. );
  48. },
  49. },
  50. {
  51. key: 'content',
  52. width: 540,
  53. render(text, row) {
  54. return (
  55. <div className="group text-hidden" style={{ width: '540px' }}>
  56. <a
  57. href={row.userQuestionId ? `/paper/question/${row.userQuestionId}` : `/question/detail/${row.questionNoId}`} target="_blank"
  58. >
  59. {text}
  60. </a>
  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. oneSelectPlaceholder,
  171. twoSelectPlaceholder,
  172. filterMap = {},
  173. sortMap = {},
  174. list = [],
  175. } = this.state;
  176. const { total, page } = this.state;
  177. return (
  178. <div className="table-layout">
  179. <Tabs
  180. border
  181. type="division"
  182. theme="theme"
  183. size="small"
  184. space={2.5}
  185. width={100}
  186. active={tab}
  187. tabs={[{ key: 'exercise', title: '练习' }, { key: 'examination', title: '模考' }]}
  188. onChange={key => this.onTabChange(key)}
  189. />
  190. <UserAction
  191. search
  192. defaultSearch={filterMap.keyword}
  193. selectList={[
  194. {
  195. children: [
  196. {
  197. key: 'subject',
  198. placeholder: '学科',
  199. select: questionSubjectSelect,
  200. },
  201. {
  202. placeholder: '题型',
  203. key: 'questionType',
  204. be: 'subject',
  205. selectMap: questionSubjectMap,
  206. },
  207. ],
  208. },
  209. {
  210. label: '范围',
  211. children: [
  212. {
  213. key: 'one',
  214. placeholder: oneSelectPlaceholder,
  215. select: oneSelect,
  216. },
  217. {
  218. key: 'two',
  219. be: 'one',
  220. placeholder: twoSelectPlaceholder,
  221. selectMap: twoSelectMap,
  222. },
  223. ],
  224. },
  225. {
  226. right: true,
  227. key: 'timerange',
  228. select: TimeRange,
  229. },
  230. ]}
  231. filterMap={filterMap}
  232. onFilter={value => this.onFilter(value)}
  233. onSearch={value => this.onSearch(value)}
  234. />
  235. <UserAction
  236. sortList={[
  237. { right: true, label: '提问时间', key: 'create_time' },
  238. { right: true, label: '回答时间', key: 'ask_time' },
  239. ]}
  240. sortMap={sortMap}
  241. left={
  242. <div className="email">
  243. 只看已回答{' '}
  244. <Switch
  245. checked={Number(filterMap.answerStatus)}
  246. onChange={() => {
  247. filterMap.answerStatus = Number(filterMap.answerStatus) ? null : 1;
  248. this.onFilter(filterMap);
  249. }}
  250. />
  251. </div>
  252. }
  253. onSort={value => this.onSort(value)}
  254. />
  255. {list.map(item => {
  256. return (
  257. <div className="group">
  258. <UserTable border={false} size="small" columns={columns} data={[item]} header={false} />
  259. <div className="answer-layout">
  260. <div className="title">
  261. 提问区域: <b>{AskTargetMap[item.target]}</b>
  262. {item.answerStatus === 0 && (
  263. <div className="f-r">
  264. <Button radius size="small" onClick={() => this.delAsk(item.id)}>
  265. 删除
  266. </Button>
  267. </div>
  268. )}
  269. </div>
  270. <div>
  271. <div className="small-tag">提问</div>
  272. <div className="f-r t-2 t-s-12">{formatDate(item.createTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  273. </div>
  274. <div className="desc">
  275. <OpenText><div dangerouslySetInnerHTML={{ __html: item.content }} /></OpenText>
  276. </div>
  277. {item.answerStatus > 0 && (
  278. <div>
  279. <div className="small-tag">回答</div>
  280. <div className="f-r t-2 t-s-12">{formatDate(item.answerTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  281. </div>
  282. )}
  283. {item.answerStatus > 0 && (
  284. <div className="desc">
  285. <OpenText><div dangerouslySetInnerHTML={{ __html: item.answerStatus === 2 ? '与题目内容无关,老师无法作出回答,敬请谅解。' : item.answer }} /></OpenText>
  286. </div>
  287. )}
  288. </div>
  289. </div>
  290. );
  291. })}
  292. {total > 0 && list.length > 0 && (
  293. <UserPagination
  294. total={total}
  295. pageSize={this.state.search.size}
  296. current={page}
  297. onChange={p => this.onChangePage(p)}
  298. />
  299. )}
  300. </div>
  301. );
  302. }
  303. }