page.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 Assets from '@src/components/Assets';
  6. import { getMap, formatDate } from '@src/services/Tools';
  7. import { CommentModal, FaqModal, TextbookFeedbackModal, FinishModal } from '../../../components/OtherModal';
  8. import { CommentFalls, AnswerCarousel, Consultation, Contact } from '../../../components/Other';
  9. import Modal from '../../../components/Modal';
  10. import Footer from '../../../components/Footer';
  11. import Button from '../../../components/Button';
  12. import UserTable from '../../../components/UserTable';
  13. import Tabs from '../../../components/Tabs';
  14. import { TextbookItem } from '../../../components/Item';
  15. import { TwoDate } from '../../../components/Date';
  16. import { Main } from '../../../stores/main';
  17. import { Textbook } from '../../../stores/textbook';
  18. import { Order } from '../../../stores/order';
  19. import { User } from '../../../stores/user';
  20. import { TextbookFeedbackTarget } from '../../../../Constant';
  21. const textbookHistoryColumns = [
  22. {
  23. title: '更新时间',
  24. key: 'createTime',
  25. width: 120,
  26. render: (text) => {
  27. return <div className="sub">
  28. <div className="t-2 t-s-12">{text.split(' ')[0]}</div>
  29. <div className="t-6 t-s-12">{text.split(' ')[1]}</div>
  30. </div>;
  31. },
  32. },
  33. { title: '版本', key: 'version', width: 120 },
  34. { title: '更新内容', key: 'content', width: 330 },
  35. ];
  36. export default class extends Page {
  37. initState() {
  38. return {
  39. tab: 'baselibrary',
  40. list: [],
  41. enroll: {},
  42. load: 0,
  43. };
  44. }
  45. init() {
  46. this.enrollMap = {};
  47. this.libraryMap = {};
  48. Main.getBase()
  49. .then(result => {
  50. this.setState({ base: result });
  51. });
  52. Textbook.getInfo().then((result) => {
  53. const { latest } = result;
  54. result.day = parseInt((new Date().getTime() - new Date(result.latest.startDate).getTime()) / 86400000, 10);
  55. result.expireDay =
  56. result.expireTime && parseInt((new Date(result.expireTime).getTime() - new Date().getTime()) / 86400000, 10);
  57. const list = [];
  58. list.push({ subject: 'quant', number: latest.quantNumber, time: latest.quantTime, version: latest.quantVersion });
  59. list.push({ subject: 'rc', number: latest.rcNumber, time: latest.rcTime, version: latest.rcVersion });
  60. list.push({ subject: 'ir', number: latest.irNumber, time: latest.irTime, version: latest.irVersion });
  61. this.setState({ data: result, list });
  62. });
  63. }
  64. initData() {
  65. this.refreshFaqs(this.state.tab);
  66. this.refreshComments();
  67. const start = new Date();
  68. start.setMinutes(0, 0, 0);
  69. start.setHours(0);
  70. start.setDate(1);
  71. start.setMonth(start.getMonth() - 2);
  72. const end = new Date();
  73. end.setMinutes(0, 0, 0);
  74. end.setHours(0);
  75. end.setDate(1);
  76. end.setMonth(end.getMonth() + 4);
  77. const startDate = formatDate(start, 'YYYY-MM-DD');
  78. const endDate = formatDate(end, 'YYYY-MM-DD');
  79. this.refreshEnroll(startDate, endDate);
  80. this.setState({ startDate, endDate });
  81. const nowYear = new Date().getFullYear();
  82. this.refreshYear(nowYear);
  83. if (nowYear > start.getFullYear()) {
  84. this.refreshYear(nowYear - 1);
  85. }
  86. }
  87. refreshFaqs(tab) {
  88. Main.listFaq({ page: 1, size: 1000, channel: `library-${tab}` })
  89. .then((result => {
  90. this.setState({ faqs: result.list });
  91. }));
  92. }
  93. refreshComments() {
  94. Main.listComment({ page: 1, size: 1000, channel: 'library' })
  95. .then(result => {
  96. this.setState({ comments: result.list });
  97. });
  98. }
  99. refreshEnroll(startDate, endDate) {
  100. const month = formatDate(new Date(), 'YYYY-MM');
  101. Textbook.listEnroll(startDate, endDate)
  102. .then(result => {
  103. result.times = result.times.map(row => {
  104. row.month = formatDate(row.month, 'YYYY-MM');
  105. if (row.month === month) {
  106. // 本月机经开通人数
  107. this.setState({ useNumber: row.useNumber });
  108. }
  109. return row;
  110. });
  111. this.enrollMap = getMap(result.times, 'month');
  112. if (result.date) {
  113. const d = new Date(result.date);
  114. result.dateF = formatDate(d, 'YYYY-MM-DD');
  115. result.day = parseInt((d.getTime() - new Date().getTime()) / 86400000, 10);
  116. }
  117. this.setState({ enroll: result, load: this.state.load + 1 });
  118. });
  119. }
  120. refreshYear(year) {
  121. Textbook.listYear(year)
  122. .then(result => {
  123. result = result.map(row => {
  124. row.day = formatDate(row.startDate, 'YYYY-MM-DD');
  125. this.libraryMap[row.day] = row;
  126. return row;
  127. });
  128. this.setState({ library: result, load: this.state.load + 1 });
  129. });
  130. }
  131. textbookHistory({ page, size, subject }) {
  132. this.setState({ subject });
  133. Textbook.allHistory(subject).then(result => {
  134. this.setState({
  135. showUpdate: true,
  136. updateList: result.map(row => {
  137. row.version = row[`${subject}Version`];
  138. row.content = row[`${subject}Content`];
  139. row.createTime = formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss');
  140. return row;
  141. }),
  142. // 不显示分页
  143. updateTotal: 0,
  144. maxHeight: 730,
  145. updatePage: page,
  146. updateData: { page, size, subject, columns: textbookHistoryColumns, type: 'textbook' },
  147. });
  148. });
  149. }
  150. enroll() {
  151. const { date, enroll } = this.state;
  152. if (enroll.date) return;
  153. if (!date) {
  154. this.setState({ showWarn: true, warn: { title: '报名', content: '请先选择报考日期' } });
  155. return;
  156. }
  157. User.needLogin()
  158. .then(() => {
  159. Textbook.enroll(date.format('YYYY-MM-DD'))
  160. .then(() => {
  161. enroll.date = new Date(date);
  162. enroll.dateF = date.format('YYYY-MM-DD');
  163. enroll.day = parseInt((enroll.date.getTime() - new Date().getTime()) / 86400000, 10);
  164. this.setState({ showWarn: true, warn: { title: '报名', content: `已报考${formatDate(date, 'YYYY-MM-DD')}` } });
  165. this.setState({ enroll });
  166. });
  167. });
  168. }
  169. unEnroll() {
  170. const { enroll } = this.state;
  171. if (!enroll.date) return;
  172. User.needLogin()
  173. .then(() => {
  174. Textbook.unEnroll()
  175. .then(() => {
  176. this.setState({ enroll: {} });
  177. });
  178. });
  179. }
  180. onTabChange(key) {
  181. this.refreshFaqs(key);
  182. this.setState({ tab: key });
  183. }
  184. open(recordId) {
  185. User.needLogin()
  186. .then(() => {
  187. Order.useRecord(recordId)
  188. .then(() => {
  189. this.refresh();
  190. });
  191. });
  192. }
  193. buy() {
  194. User.needLogin()
  195. .then(() => {
  196. return Order.speedPay({ productType: 'service', service: 'textbook' });
  197. })
  198. .then((order) => {
  199. return User.needPay(order);
  200. })
  201. .then(() => {
  202. this.refresh();
  203. });
  204. }
  205. renderView() {
  206. const { data = {}, base = {}, tab, faqs = [], comments = [], showFaq, faq = {}, showFinish, showComment, comment = {}, showUpdate, updateData = {}, updateList = [], updateTotal, maxHeight, showFeedback, feedback = {}, showWarn, warn = {} } = this.state;
  207. return (
  208. <div>
  209. {this.renderDate()}
  210. {!data.hasService && data.unUseRecord && this.renderLog()}
  211. {!data.hasService && !data.unUseRecord && this.renderCompare()}
  212. {data.hasService && this.renderList()}
  213. <AnswerCarousel
  214. hideBtn
  215. tabActive={tab}
  216. list={faqs}
  217. tabs={[{ title: '换库知识', key: 'baselibrary' }, { title: '机经知识', key: 'basetextbook' }, { title: '千行机经', key: 'qxtextbook' }]}
  218. onTabChange={(key) => this.onTabChange(key)}
  219. />
  220. <CommentFalls list={comments} />
  221. <Consultation />
  222. <Contact data={base.contact} />
  223. <Footer />
  224. <Modal show={showWarn} title={warn.title} confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showWarn: false })}>
  225. <div className="t-2 t-s-18">{warn.content}</div>
  226. </Modal>,
  227. <Modal
  228. show={showUpdate}
  229. maskClosable
  230. close={false}
  231. body={false}
  232. width={630}
  233. onClose={() => this.setState({ showUpdate: false, updateList: [] })}
  234. >
  235. <UserTable
  236. size="small"
  237. theme="top"
  238. columns={updateData.columns}
  239. data={updateList}
  240. current={updateData.page}
  241. pageSize={updateData.size}
  242. onChange={page => {
  243. updateData.page = page;
  244. if (updateData.type === 'data') {
  245. this.dataHistory(updateData);
  246. } else if (updateData.type === 'textbook') {
  247. this.textbookHistory(updateData);
  248. } else if (updateData.type === 'record') {
  249. this.recordList(updateData);
  250. }
  251. }}
  252. total={updateTotal}
  253. maxHeight={maxHeight}
  254. />
  255. </Modal>
  256. <TextbookFeedbackModal
  257. show={showFeedback}
  258. defaultData={feedback}
  259. onConfirm={() => this.setState({ showFeedback: false, showFinish: true })}
  260. onCancel={() => this.setState({ showFeedback: false })}
  261. onClose={() => this.setState({ showFeedback: false })}
  262. />
  263. <CommentModal
  264. show={showComment}
  265. defaultData={comment}
  266. onConfirm={() => this.setState({ showComment: false, showFinish: true })}
  267. onCancel={() => this.setState({ showComment: false })}
  268. onClose={() => this.setState({ showComment: false })}
  269. />
  270. <FaqModal show={showFaq} defaultData={faq} onCancel={() => this.setState({ showFaq: false })} onConfirm={() => this.setState({ showFaq: false, showFinish: true })} />
  271. <FinishModal
  272. getContainer={() => document.getElementById(this.video.state.id)}
  273. show={showFinish}
  274. onConfirm={() => this.setState({ showFinish: false })}
  275. />
  276. </div>
  277. );
  278. }
  279. renderDate() {
  280. const { data, enroll = {}, useNumber, startDate, endDate, load } = this.state;
  281. const { latest = {}, day } = data;
  282. return (
  283. <div className="date-layout">
  284. <div className="content">
  285. <div style={{ width: 845 }} className="b f-l">
  286. <div className="date-info">
  287. <span className="today">今日</span>
  288. <span className="type-1">换库</span>
  289. <span className="type-2">考试日</span>
  290. {enroll.date && <span>
  291. {enroll.day > 0 ? `距离考试还有${enroll.day}天` : `距离考试已过去${enroll.day * -1}天`}
  292. </span>}
  293. {enroll.date && <Button size="small" radius onClick={() => this.unEnroll()}>
  294. 取消报考
  295. </Button>}
  296. {!enroll.date && <Button size="small" radius onClick={() => this.enroll()}>
  297. 我已报考
  298. </Button>}
  299. <Link to="/textbook/year" className="f-r">
  300. 按年份查看 >
  301. </Link>
  302. </div>
  303. <TwoDate
  304. key={load}
  305. startDate={startDate}
  306. endDate={endDate}
  307. getType={date => {
  308. const d = date.format('YYYY-MM-DD');
  309. if (enroll.date && d === enroll.dateF) {
  310. return 'type-2';
  311. }
  312. if (this.libraryMap[d]) {
  313. return 'type-1';
  314. }
  315. return null;
  316. }}
  317. extendInfo={date => {
  318. const d = date.format('YYYY-MM');
  319. return `${this.enrollMap[d] ? this.enrollMap[d].enrollNumber : 0}人`;
  320. }}
  321. onChange={(date) => this.setState({ date })}
  322. />
  323. </div>
  324. <div style={{ width: 275 }} className="b f-r p-20">
  325. <div className="t-13 t-s-16">最近换库</div>
  326. <Assets name="" />
  327. <div className="t-13 t-s-32 t-c">{latest.startDate ? formatDate(latest.startDate, 'YYYY-MM-DD') : ''}</div>
  328. <div className="t-13 t-c t-s-16">
  329. 已换库 <span className="t-4">{day}</span> 天
  330. </div>
  331. <div className="m-t-2 t-c">
  332. <Button width={100} radius size="lager" onClick={() => User.needLogin().then(() => linkTo('/my/tools?tab=textbook'))}>
  333. 我的机经
  334. </Button>
  335. </div>
  336. <div className="m-t-2 t-13 t-c t-s-14">
  337. 本月共{useNumber || 0}人使用机经
  338. </div>
  339. </div>
  340. </div>
  341. </div>
  342. );
  343. }
  344. renderList() {
  345. const { list } = this.state;
  346. return (
  347. <div className="list-layout">
  348. <div className="content">
  349. {list.map(item => {
  350. return <TextbookItem
  351. data={item}
  352. menu={[
  353. { label: '更新', key: 'update' },
  354. { label: '反馈', key: 'feedback' },
  355. { label: '评价', key: 'comment' },
  356. ]}
  357. onClick={() => linkTo(`/textbook/topic/list/${item.subject}`)}
  358. onMenuClick={value => {
  359. const { key } = value;
  360. if (key === 'comment') {
  361. this.setState({ showComment: true, comment: { channel: 'library' } });
  362. } else if (key === 'update') {
  363. this.textbookHistory({ page: 1, size: 100, subject: item.subject });
  364. } else if (key === 'feedback') {
  365. this.setState({ showFeedback: true, feedback: { questionSubject: item.subject, target: TextbookFeedbackTarget[0].value } });
  366. }
  367. }} />;
  368. })}
  369. </div>
  370. </div>
  371. );
  372. }
  373. renderLog() {
  374. const { data, subject, updateList } = this.state;
  375. return (
  376. <div className="table-layout">
  377. <div className="content">
  378. <div className="t">
  379. <span className="d-i-b t-1 t-s-18">更新日志</span>
  380. <Tabs
  381. type="text"
  382. tabs={[{ title: '数学', key: 'quant' }, { title: '阅读RC', key: 'rc' }, { title: '逻辑IR', key: 'ir' }]}
  383. active={subject}
  384. onTabChange={(key) => this.textbookHistory({ subject: key })}
  385. />
  386. </div>
  387. <UserTable
  388. size="small"
  389. columns={[
  390. { title: '更新时间', key: 'date' },
  391. { title: '版本', key: 'version' },
  392. { title: '更新内容', key: 'content' },
  393. ]}
  394. data={updateList}
  395. />
  396. <Assets name="textbook_banner" onClick={() => this.open(data.unUseRecord.id)} />
  397. </div>
  398. </div>
  399. );
  400. }
  401. renderCompare() {
  402. return (
  403. <div className="compare-layout">
  404. <div className="t-14 t-c t-s-32 m-b-2">让机经帮上忙,而不是帮倒忙!</div>
  405. <div className="t-c m-b-2">
  406. <Button width={100} size="lager" radius className="m-r-2" onClick={() => this.buy()}>
  407. 立刻购买
  408. </Button>
  409. <Button width={100} size="lager" radius className="m-l-2" onClick={() => linkTo('/examination?tab1=textbook')}>
  410. 试用往期
  411. </Button>
  412. </div>
  413. <div className="table">
  414. <table>
  415. <thead>
  416. <tr>
  417. <th>千行机经</th>
  418. <th>其他机经</th>
  419. </tr>
  420. </thead>
  421. <tbody>
  422. <tr>
  423. <td>整理内容+梳理逻辑结构</td>
  424. <td>只关注内容</td>
  425. </tr>
  426. <tr>
  427. <td>最新版本自动更新至邮箱</td>
  428. <td>手动领取</td>
  429. </tr>
  430. <tr>
  431. <td>重视考场一手信息,越准越好</td>
  432. <td>越多越好</td>
  433. </tr>
  434. <tr>
  435. <td>独家资源,严格把关</td>
  436. <td>市面资源</td>
  437. </tr>
  438. <tr>
  439. <td>一键反馈,随时沟通</td>
  440. <td>无售后系统</td>
  441. </tr>
  442. <tr>
  443. <td>下载至本地、在线浏览、在线做题,多种查阅方式</td>
  444. <td>下载至本地</td>
  445. </tr>
  446. </tbody>
  447. </table>
  448. </div>
  449. </div>
  450. );
  451. }
  452. }