1
0

page.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { asyncConfirm, asyncSMessage } from '@src/services/AsyncTools';
  5. import { formatTreeData, formatSeconds, formatPercent, formatDate } from '@src/services/Tools';
  6. import Panel, { WaitPanel, BuyPanel, SmallPanel, SmallWaitPanel, SmallBuyPanel } from '../../../components/Panel';
  7. import Tabs from '../../../components/Tabs';
  8. import Module from '../../../components/Module';
  9. import Division from '../../../components/Division';
  10. import ProgressText from '../../../components/ProgressText';
  11. import IconButton from '../../../components/IconButton';
  12. import { Main } from '../../../stores/main';
  13. // import { My } from '../../../stores/my';
  14. import { Question } from '../../../stores/question';
  15. import { Textbook } from '../../../stores/textbook';
  16. // import { User } from '../../../stores/user';
  17. // import { CourseModuleShow, CourseModule } from '../../../../Constant';
  18. import { Order } from '../../../stores/order';
  19. const TEXTBOOK = 'textbook';
  20. export default class extends Page {
  21. constructor(props) {
  22. super(props);
  23. this.examinationColumns = [{
  24. title: '练习册',
  25. width: 250,
  26. align: 'left',
  27. render: item => {
  28. return (
  29. <div className="table-row">
  30. <div className="night f-s-16">{item.title}</div>
  31. <div>
  32. <ProgressText
  33. progress={item.report.id ? formatPercent(item.repport.userNumber, item.report.questionNumber) : 0}
  34. size="small"
  35. />
  36. </div>
  37. </div>
  38. );
  39. },
  40. },
  41. {
  42. title: '正确率',
  43. width: 150,
  44. align: 'left',
  45. render: item => {
  46. return (
  47. <div className="table-row">
  48. <div className="night f-s-16 f-w-b">--</div>
  49. <div className="f-s-12">{formatPercent(item.stat.totalCorrect, item.stat.totalNumber, false)}</div>
  50. </div>
  51. );
  52. },
  53. },
  54. {
  55. title: '全站用时',
  56. width: 150,
  57. align: 'left',
  58. render: item => {
  59. return (
  60. <div className="table-row">
  61. <div className="night f-s-16 f-w-b">--</div>
  62. <div className="f-s-12">全站{formatSeconds(item.stat.totalTime / item.stat.totalNumber)}</div>
  63. </div>
  64. );
  65. },
  66. },
  67. {
  68. title: '最近做题',
  69. width: 150,
  70. align: 'left',
  71. render: () => {
  72. return (
  73. <div className="table-row">
  74. <div>2019-04-28</div>
  75. <div>07:30</div>
  76. </div>
  77. );
  78. },
  79. },
  80. {
  81. title: '操作',
  82. width: 180,
  83. align: 'left',
  84. render: item => {
  85. return (
  86. <div className="table-row p-t-1">
  87. {!item.report && <IconButton type="start" tip="Start" onClick={() => Question.startLink('preview', item)} />}
  88. {item.report.id && !item.report.isFinish && (
  89. <IconButton
  90. className="m-r-2"
  91. type="continue"
  92. tip="Continue"
  93. onClick={() => Question.continueLink('preview', item)}
  94. />
  95. )}
  96. {item.report.id && <IconButton type="restart" tip="Restart" onClick={() => this.restart('preview', item)} />}
  97. </div>
  98. );
  99. },
  100. },
  101. {
  102. title: '报告',
  103. width: 30,
  104. align: 'right',
  105. render: item => {
  106. return (
  107. <div className="table-row p-t-1">
  108. {item.report.isFinish && <IconButton type="report" tip="Report" onClick={() => Question.reportLink(item)} />}
  109. </div>
  110. );
  111. },
  112. }];
  113. }
  114. initState() {
  115. this.examinationProgress = {};
  116. this.textbookProgress = {};
  117. this.inited = false;
  118. return {
  119. tab1: '',
  120. tab2: '',
  121. tabs: [],
  122. };
  123. }
  124. init() {
  125. Main.getExamination().then(result => {
  126. const list = result.filter(row => row.level === 1).map(row => {
  127. row.title = `${row.titleZh}${row.titleEn}`;
  128. row.key = row.extend;
  129. return row;
  130. });
  131. const tabs = formatTreeData(list, 'id', 'title', 'parentId');
  132. tabs.push({ key: TEXTBOOK, name: '数学机经' });
  133. this.setState({
  134. tabs,
  135. });
  136. this.inited = true;
  137. this.refreshData();
  138. });
  139. }
  140. initData() {
  141. const data = Object.assign(this.state, this.state.search);
  142. if (!data.tab1) {
  143. data.tab1 = TEXTBOOK;
  144. }
  145. this.setState(data);
  146. if (this.inited) this.refreshData();
  147. }
  148. refreshData(tab) {
  149. const { tab1 } = this.state;
  150. switch (tab || tab1) {
  151. case TEXTBOOK:
  152. this.refreshTextbook();
  153. break;
  154. default:
  155. this.refreshExamination(tab || tab1);
  156. }
  157. }
  158. refreshTextbook() {
  159. Textbook.progress().then(result => {
  160. // const exerciseProgress = getMap(r, 'id');
  161. result = result.map(row => {
  162. row.info = [
  163. {
  164. title: '已做',
  165. number: row.userNumber || '-',
  166. unit: '题',
  167. },
  168. {
  169. title: '剩余',
  170. number: row.userNumber ? row.questionNumber - row.userNumber : '-',
  171. unit: '题',
  172. },
  173. {
  174. title: '正确率',
  175. number: row.userNumber ? formatPercent(row.userStat.userCorrect, row.userStat.userNumber, false) : '-%',
  176. unit: '',
  177. },
  178. {
  179. title: '全站',
  180. number: row.userNumber ? formatPercent(row.stat.totalCorrect, row.stat.totalNumber, false) : '-%',
  181. unit: '题',
  182. },
  183. ];
  184. row.progress = formatPercent(row.questionNumber - row.userNumber || 0, row.questionNumber);
  185. row.totalCorrect = formatPercent(row.stat.totalCorrect, row.stat.totalNumber, false);
  186. row.children = row.children.map(r => {
  187. r.title = r.title || r.titleZh;
  188. r.progress = formatPercent(r.userNumber, r.questionNumber);
  189. return r;
  190. });
  191. if (row.isLatest) {
  192. const day = parseInt((new Date().getTime() - new Date(row.startDate).getTime()) / 86400000, 10);
  193. row.desc = [`最近换库:${formatDate(row.startDate, 'YYYY-MM-DD')} ,已换库${day}天`, `最后更新:${formatDate(row.updateTime)}`];
  194. }
  195. return row;
  196. });
  197. this.setState({ textbookProgress: result });
  198. });
  199. }
  200. refreshExamination(tab) {
  201. const { tabs, tab1 } = this.state;
  202. if (!tabs) {
  203. // 等待数据加载
  204. return;
  205. }
  206. const [subject] = tabs.filter(row => row.key === tab || row.key === tab1);
  207. Question.getExaminationProgress(subject.id).then(result => {
  208. // const exerciseProgress = getMap(r, 'id');
  209. result = result.map(row => {
  210. row.title = `${row.titleZh}${row.titleEn}`;
  211. row.info = [
  212. {
  213. title: '已做',
  214. number: row.userNumber || '-',
  215. unit: '套',
  216. },
  217. {
  218. title: '剩余',
  219. number: row.userNumber ? row.questionNumber - row.userNumber : '-',
  220. unit: '套',
  221. },
  222. ];
  223. return row;
  224. });
  225. this.setState({ examinationProgress: result });
  226. });
  227. }
  228. onChangeTab(level, tab) {
  229. const { tab1 } = this.state;
  230. const data = {};
  231. if (level > 1) {
  232. data.tab1 = tab1;
  233. data.tab2 = tab;
  234. } else {
  235. data.tab1 = tab;
  236. }
  237. // this.refreshData(tab);
  238. this.refreshQuery(data);
  239. }
  240. onTextbook() {
  241. const { tab1, tab2, struct } = this.state;
  242. const data = {
  243. tab1, tab2, struct,
  244. };
  245. this.refreshQuery(data);
  246. }
  247. // 开通模考或者机经
  248. open(recordId) {
  249. Order.useRecord(recordId).then(() => {
  250. asyncSMessage('开通成功');
  251. this.refresh();
  252. });
  253. }
  254. restart(item) {
  255. asyncConfirm('提示', '是否重置', () => {
  256. Question.restart(item.paper.id).then(() => {
  257. this.refresh();
  258. });
  259. });
  260. }
  261. examinationList(item) {
  262. linkTo(`/examination/list/${item.id}`);
  263. }
  264. textbookList(item) {
  265. linkTo(`/textbook/list/${item.id}`);
  266. }
  267. renderView() {
  268. const { tab1, tab2, tabs } = this.state;
  269. const [subject] = tabs.filter(row => row.key === tab1);
  270. const children = (subject && subject.children) ? subject.children : [];
  271. return (
  272. <div>
  273. <div className="content">
  274. <Module className="m-t-2">
  275. <Tabs
  276. type="card"
  277. active={tab1}
  278. tabs={tabs}
  279. onChange={key => {
  280. this.onChangeTab(1, key);
  281. }}
  282. />
  283. {children && children.length > 1 && (
  284. <Tabs active={tab2} tabs={children} onChange={key => this.onChangeTab(2, key)} />
  285. )}
  286. </Module>
  287. {tab1 !== TEXTBOOK && this.renderExamination()}
  288. {tab1 === TEXTBOOK && this.renderTextbook()}
  289. </div>
  290. </div>
  291. );
  292. }
  293. renderTextbook() {
  294. const { textbookProgress = [] } = this.state;
  295. return (
  296. <div>
  297. <Division col={2}>
  298. {(textbookProgress || []).map(struct => {
  299. if (struct.needService && !struct.hasService) {
  300. if (struct.unUseRecord) {
  301. return <WaitPanel
  302. title={struct.isLatest ? '最新' : '往期'}
  303. col="3"
  304. data={struct}
  305. />;
  306. }
  307. return <BuyPanel
  308. title={struct.isLatest ? '最新' : '往期'}
  309. onBuy={() => {
  310. this.buyTextbook();
  311. }}
  312. />;
  313. }
  314. return <Panel
  315. title={struct.isLatest ? '最新' : '往期'}
  316. col="3"
  317. data={struct}
  318. onClick={(item) => {
  319. this.textbookList(item);
  320. }}
  321. />;
  322. })}
  323. </Division>
  324. </div>
  325. );
  326. }
  327. renderExamination() {
  328. const { examinationProgress = [] } = this.state;
  329. return (
  330. <div>
  331. <Division col={3} type="compact">
  332. {(examinationProgress || []).map(struct => {
  333. if (struct.hasService) {
  334. return <SmallPanel
  335. title={struct.title}
  336. data={struct}
  337. onClick={() => {
  338. this.examinationList(struct);
  339. }}
  340. />;
  341. } if (struct.unUseRecord) {
  342. return <SmallWaitPanel
  343. title={struct.title}
  344. data={struct}
  345. onOpen={() => {
  346. this.open(struct.unUseRecord);
  347. }}
  348. />;
  349. }
  350. return <SmallBuyPanel
  351. title={struct.title}
  352. data={struct}
  353. onBuy={() => {
  354. this.buyQxCat();
  355. }}
  356. />;
  357. })}
  358. </Division>
  359. </div>
  360. );
  361. }
  362. }