1
0

page.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. import React from 'react';
  2. import { Breadcrumb, Tooltip, Switch } from 'antd';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import { asyncConfirm, asyncSMessage } from '@src/services/AsyncTools';
  6. import { formatPercent, formatDate } from '@src/services/Tools';
  7. import ListTable from '../../../components/ListTable';
  8. import ProgressText from '../../../components/ProgressText';
  9. import IconButton from '../../../components/IconButton';
  10. import Button from '../../../components/Button';
  11. import { Main } from '../../../stores/main';
  12. import { Question } from '../../../stores/question';
  13. export default class extends Page {
  14. initState() {
  15. this.qxCatColumns = [{
  16. title: '模考',
  17. width: 250,
  18. align: 'left',
  19. render: (record) => {
  20. let progress = 0;
  21. if (record.report) {
  22. progress = formatPercent(record.report.userNumber, record.report.questionNumber);
  23. }
  24. return (
  25. <div className="table-row">
  26. <div className="night f-s-16">{record.title}{record.paper && record.paper.paperNo > 0 ? String.fromCharCode(64 + record.paper.paperNo) : ''}</div>
  27. <div>
  28. <ProgressText progress={progress} size="small" />
  29. </div>
  30. {this.state.showPrev && <div className="prev">
  31. <div className="night f-s-16">{record.title}{record.prevPaper && record.prevPaper.paperNo > 0 ? String.fromCharCode(64 + record.prevPaper.paperNo) : ''}</div>
  32. </div>}
  33. </div>
  34. );
  35. },
  36. }, {
  37. title: 'Total',
  38. width: 150,
  39. align: 'left',
  40. render: (record) => {
  41. return (
  42. <div className="table-row">
  43. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  44. <div className="f-s-12">全站: {Math.round(record.totalScore / record.totalTimes)}分</div>
  45. {this.state.showPrev && record.prevReport && <div className="prev">
  46. <div className="night f-s-16 f-w-b">{record.prevReport.score.total}分{record.prevReport.score.totalRank}th</div>
  47. <div className="f-s-12">全站: {Math.round(record.totalScore / record.totalTimes)}分</div>
  48. </div>}
  49. </div>
  50. );
  51. },
  52. }, {
  53. title: 'Verbal',
  54. width: 150,
  55. align: 'left',
  56. render: (record) => {
  57. return (
  58. <div className="table-row">
  59. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  60. <div className="f-s-12">全站: {Math.round(record.verbalScore / record.totalTimes)}分</div>
  61. {this.state.showPrev && record.prevReport && <div className="prev">
  62. <div className="night f-s-16 f-w-b">{record.prevReport.score.verbal}分{record.prevReport.score.verbalRank}th</div>
  63. <div className="f-s-12">全站: {Math.round(record.verbalScore / record.totalTimes)}分</div>
  64. </div>}
  65. </div>
  66. );
  67. },
  68. }, {
  69. title: 'Quant',
  70. width: 150,
  71. align: 'left',
  72. render: (record) => {
  73. return (
  74. <div className="table-row">
  75. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  76. <div className="f-s-12">全站: {Math.round(record.quantScore / record.totalTimes)}分</div>
  77. {this.state.showPrev && record.prevReport && <div className="prev">
  78. <div className="night f-s-16 f-w-b">{record.prevReport.score.quant}分{record.prevReport.score.quantRank}th</div>
  79. <div className="f-s-12">全站: {Math.round(record.quantScore / record.totalTimes)}分</div>
  80. </div>}
  81. </div>
  82. );
  83. },
  84. }, {
  85. title: 'IR',
  86. width: 150,
  87. align: 'left',
  88. render: (record) => {
  89. return (
  90. <div className="table-row">
  91. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  92. <div className="f-s-12">全站: {Math.round(record.irScore / record.totalTimes)}分</div>
  93. {this.state.showPrev && record.prevReport && <div className="prev">
  94. <div className="night f-s-16 f-w-b">{record.prevReport.score.ir}分{record.prevReport.score.irRank}th</div>
  95. <div className="f-s-12">全站: {Math.round(record.irScore / record.totalTimes)}分</div>
  96. </div>}
  97. </div>
  98. );
  99. },
  100. }, {
  101. title: '做题时间',
  102. width: 150,
  103. align: 'left',
  104. render: (record) => {
  105. return (
  106. <div className="table-row">
  107. <div>{record.report && formatDate(record.report.updateTime, 'YYYY-MM-DD')}</div>
  108. <div>{record.report && formatDate(record.report.updateTime, 'HH:mm')}</div>
  109. {this.state.showPrev && record.prevReport && <div className="prev">
  110. <div>{formatDate(record.prevReport.updateTime, 'YYYY-MM-DD')}</div>
  111. <div>{formatDate(record.prevReport.updateTime, 'HH:mm')}</div>
  112. </div>}
  113. </div>
  114. );
  115. },
  116. }, {
  117. title: '操作',
  118. width: 180,
  119. align: 'left',
  120. render: (record) => {
  121. return (
  122. <div className="table-row p-t-1">
  123. {!record.report && <IconButton type="start" tip="Start" onClick={() => {
  124. Question.startLink('examination', record);
  125. }} />}
  126. {(record.report && !record.report.isFinish) && <IconButton className="m-r-2" type="continue" tip="Continue" onClick={() => {
  127. Question.continueLink('examination', record);
  128. }} />}
  129. </div>
  130. );
  131. },
  132. }, {
  133. title: '报告',
  134. width: 30,
  135. align: 'right',
  136. render: (record) => {
  137. return (
  138. <div className="table-row p-t-1">
  139. {record.report && record.report.isFinish && <IconButton type="report" tip="Report" onClick={() => {
  140. Question.reportLink(record);
  141. }} />}
  142. {this.state.showPrev && <div className="prev">
  143. {record.prevReport && <IconButton type="report" tip="Report" onClick={() => {
  144. Question.reportPrevLink(record);
  145. }} />}
  146. </div>}
  147. </div>
  148. );
  149. },
  150. }];
  151. this.catColumns = [{
  152. title: '模考',
  153. width: 250,
  154. align: 'left',
  155. render: (record) => {
  156. let progress = 0;
  157. if (record.report) {
  158. progress = formatPercent(record.report.userNumber, record.report.questionNumber);
  159. }
  160. return (
  161. <div className="table-row">
  162. <div className="night f-s-16">{record.title}{record.paper && record.paper.paperNo > 0 ? String.fromCharCode(64 + record.paper.paperNo) : ''}</div>
  163. <div>
  164. <ProgressText progress={progress} size="small" />
  165. </div>
  166. </div>
  167. );
  168. },
  169. }, {
  170. title: 'Total',
  171. width: 150,
  172. align: 'left',
  173. render: (record) => {
  174. return (
  175. <div className="table-row">
  176. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  177. <div className="f-s-12">全站: {Math.round(record.totalScore / record.totalTimes)}分</div>
  178. </div>
  179. );
  180. },
  181. }, {
  182. title: 'Verbal',
  183. width: 150,
  184. align: 'left',
  185. render: (record) => {
  186. return (
  187. <div className="table-row">
  188. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  189. <div className="f-s-12">全站: {Math.round(record.verbalScore / record.totalTimes)}分</div>
  190. </div>
  191. );
  192. },
  193. }, {
  194. title: 'Quant',
  195. width: 150,
  196. align: 'left',
  197. render: (record) => {
  198. return (
  199. <div className="table-row">
  200. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  201. <div className="f-s-12">全站: {Math.round(record.quantScore / record.totalTimes)}分</div>
  202. </div>
  203. );
  204. },
  205. }, {
  206. title: 'IR',
  207. width: 150,
  208. align: 'left',
  209. render: (record) => {
  210. return (
  211. <div className="table-row">
  212. <div className="night f-s-16 f-w-b">{record.report ? `${record.report.score.total}分${record.report.score.totalRank}th` : '-分-th'}</div>
  213. <div className="f-s-12">全站: {Math.round(record.irScore / record.totalTimes)}分</div>
  214. </div>
  215. );
  216. },
  217. }, {
  218. title: '做题时间',
  219. width: 150,
  220. align: 'left',
  221. render: (record) => {
  222. return (
  223. <div className="table-row">
  224. <div>{record.report && formatDate(record.report.updateTime, 'YYYY-MM-DD')}</div>
  225. <div>{record.report && formatDate(record.report.updateTime, 'HH:mm')}</div>
  226. </div>
  227. );
  228. },
  229. }, {
  230. title: '操作',
  231. width: 180,
  232. align: 'left',
  233. render: (record) => {
  234. return (
  235. <div className="table-row p-t-1">
  236. {!record.report && <IconButton type="start" tip="Start" onClick={() => {
  237. Question.startLink('examination', record);
  238. }} />}
  239. {(record.report && !record.report.isFinish) && <IconButton className="m-r-2" type="continue" tip="Continue" onClick={() => {
  240. Question.continueLink('examination', record);
  241. }} />}
  242. <IconButton type="restart" tip="Restart" onClick={() => {
  243. this.restart(record);
  244. }} />
  245. </div>
  246. );
  247. },
  248. }, {
  249. title: '报告',
  250. width: 30,
  251. align: 'right',
  252. render: (record) => {
  253. return (
  254. <div className="table-row p-t-1">
  255. {record.report && record.report.isFinish && <IconButton type="report" tip="Report" onClick={() => {
  256. Question.reportLink(record);
  257. }} />}
  258. {this.state.showPrev && <div className="prev">
  259. {record.prevReport && <IconButton type="report" tip="Report" onClick={() => {
  260. Question.reportPrevLink(record);
  261. }} />}
  262. </div>}
  263. </div>
  264. );
  265. },
  266. }];
  267. this.columns = [{
  268. title: '模考',
  269. width: 250,
  270. align: 'left',
  271. render: (record) => {
  272. let progress = 0;
  273. if (record.report) {
  274. progress = formatPercent(record.report.userNumber, record.report.questionNumber);
  275. }
  276. return (
  277. <div className="table-row">
  278. <div className="night f-s-16">{record.title}</div>
  279. <div>
  280. <ProgressText progress={progress} times={record.paper ? record.paper.times : 0} size="small" />
  281. </div>
  282. </div>
  283. );
  284. },
  285. }, {
  286. title: 'Total',
  287. width: 150,
  288. align: 'left',
  289. render: () => {
  290. return (
  291. <div className="table-row">
  292. <div className="f-s-12">仅CAT模考</div>
  293. </div>
  294. );
  295. },
  296. }, {
  297. title: 'Verbal',
  298. width: 150,
  299. align: 'left',
  300. render: (record) => {
  301. return (
  302. <div className="table-row">
  303. <div className="f-s-12">{record.report ? formatPercent(record.report.setting.number.verbal, this.nums.verbal.number, false) : '0%'}</div>
  304. </div>
  305. );
  306. },
  307. }, {
  308. title: 'Quant',
  309. width: 150,
  310. align: 'left',
  311. render: (record) => {
  312. return (
  313. <div className="table-row">
  314. <div className="f-s-12">{record.report ? formatPercent(record.report.setting.number.quant, this.nums.quant.number, false) : '0%'}</div>
  315. </div>
  316. );
  317. },
  318. }, {
  319. title: 'IR',
  320. width: 150,
  321. align: 'left',
  322. render: (record) => {
  323. return (
  324. <div className="table-row">
  325. <div className="f-s-12">{record.report ? formatPercent(record.report.setting.number.ir, this.nums.ir.number, false) : '0%'}</div>
  326. </div>
  327. );
  328. },
  329. }, {
  330. title: '做题时间',
  331. width: 150,
  332. align: 'left',
  333. render: (record) => {
  334. if (!record.report) return null;
  335. return (
  336. <div className="table-row">
  337. <div>{formatDate(record.report.updateTime, 'YYYY-MM-DD')}</div>
  338. <div>{formatDate(record.report.updateTime, 'HH:mm')}</div>
  339. </div>
  340. );
  341. },
  342. }, {
  343. title: '操作',
  344. width: 180,
  345. align: 'left',
  346. render: (record) => {
  347. return (
  348. <div className="table-row p-t-1">
  349. {!record.report && <IconButton type="start" tip="Start" onClick={() => {
  350. Question.startLink('examination', record);
  351. }} />}
  352. {(record.report && !record.report.isFinish) && <IconButton className="m-r-2" type="continue" tip="Continue" onClick={() => {
  353. Question.continueLink('examination', record);
  354. }} />}
  355. <IconButton type="restart" tip="Restart" onClick={() => {
  356. this.restart(record);
  357. }} />
  358. </div>
  359. );
  360. },
  361. }, {
  362. title: '报告',
  363. width: 30,
  364. align: 'right',
  365. render: (record) => {
  366. if (!record.report || !record.report.isFinish) return null;
  367. return (
  368. <div className="table-row p-t-1">
  369. <IconButton type="report" tip="Report" onClick={() => {
  370. Question.reportLink(record);
  371. }} />
  372. </div>
  373. );
  374. },
  375. }];
  376. this.inited = false;
  377. return {
  378. };
  379. }
  380. init() {
  381. const { id } = this.params;
  382. Main.getExaminationParent(id).then(result => {
  383. const navs = result.map(row => {
  384. row.title = `${row.titleZh}${row.titleEn}`;
  385. return row;
  386. });
  387. this.cat = navs.filter(row => row.isAdapt > 0).length > 0;
  388. this.qxCat = navs.filter(row => row.isAdapt > 1).length > 0;
  389. Main.getExaminationNumber().then(nums => {
  390. this.nums = nums;
  391. this.inited = true;
  392. this.setState({ navs });
  393. this.refreshData();
  394. });
  395. });
  396. }
  397. initData() {
  398. const data = Object.assign(this.state, this.state.search);
  399. this.setState(data);
  400. if (this.inited) this.refreshData();
  401. }
  402. refreshData() {
  403. if (this.cat) {
  404. Question.getExaminationInfo().then((result) => {
  405. this.setState({ examination: result });
  406. });
  407. }
  408. this.refreshExamination();
  409. }
  410. refreshExamination() {
  411. Question.getExaminationList(Object.assign({ structId: this.params.id }, this.state.search))
  412. .then((result) => {
  413. this.setState({ list: result.list, total: result.total });
  414. })
  415. .catch(err => {
  416. asyncSMessage(err.message, 'warn');
  417. // linkTo('/examination');
  418. });
  419. }
  420. restart(item) {
  421. asyncConfirm('提示', '是否重置', () => {
  422. Question.restart(item.paper.id).then(() => {
  423. this.refresh();
  424. });
  425. });
  426. }
  427. resetCat() {
  428. asyncConfirm('提示', '是否重置', () => {
  429. Question.resetCat().then(() => {
  430. this.refresh();
  431. });
  432. });
  433. }
  434. renderView() {
  435. const { list, navs, search, examination = {} } = this.state;
  436. const { finish } = search;
  437. return (
  438. <div>
  439. <div className="content">
  440. <Breadcrumb separator=">">
  441. <Breadcrumb.Item href="/examination">模考</Breadcrumb.Item>
  442. {(navs || []).map(row => {
  443. return <Breadcrumb.Item>{row.title}</Breadcrumb.Item>;
  444. })}
  445. </Breadcrumb>
  446. <ListTable
  447. rightAction={<div hidden={!this.qxCat}>
  448. <span>有效期至:{examination.expireTime && formatDate(examination.expireTime, 'YYYY-MM-DD')}</span>
  449. {examination.reset && <span>第一遍模考成绩<Switch checked={this.state.showPrev} onChange={() => {
  450. this.setState({ showPrev: !this.state.showPrev });
  451. }} /></span>}
  452. {!examination.reset && examination.canReset && <Button size="small" radius onClick={() => {
  453. this.resetExamination();
  454. }}>
  455. Reset</Button>}
  456. {!examination.reset && !examination.canReset && <Tooltip overlayClassName="gray" placement="top" title="全部模考做完才可重置">
  457. <a>
  458. <Button size="small" disabled radius>
  459. Reset
  460. </Button>
  461. </a >
  462. </Tooltip>}
  463. </div>}
  464. filters={[
  465. {
  466. type: 'radio',
  467. checked: finish,
  468. list: [{ key: '0', title: '未完成' }, { key: '1', title: '已完成' }],
  469. onChange: item => {
  470. if (item.key === finish) {
  471. this.search({ finish: null });
  472. } else if (item.key === '0') {
  473. this.search({ finish: 0 });
  474. } else if (item.key === '1') {
  475. this.search({ finish: 1 });
  476. } else {
  477. this.search({ finish: null });
  478. }
  479. },
  480. },
  481. ]}
  482. data={list}
  483. columns={this.qxCat ? this.qxCatColumns : (this.cat ? this.catColumns : this.columns)}
  484. />
  485. </div>
  486. </div>
  487. );
  488. }
  489. }