page.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. show={showFinish}
  273. onConfirm={() => this.setState({ showFinish: false })}
  274. />
  275. </div>
  276. );
  277. }
  278. renderDate() {
  279. const { data, enroll = {}, useNumber, startDate, endDate, load } = this.state;
  280. const { latest = {}, day } = data;
  281. return (
  282. <div className="date-layout">
  283. <div className="content">
  284. <div style={{ width: 845 }} className="b f-l">
  285. <div className="date-info">
  286. <span className="today">今日</span>
  287. <span className="type-1">换库</span>
  288. <span className="type-2">考试日</span>
  289. {enroll.date && <span>
  290. {enroll.day > 0 ? `距离考试还有${enroll.day}天` : `距离考试已过去${enroll.day * -1}天`}
  291. </span>}
  292. {enroll.date && <Button size="small" radius onClick={() => this.unEnroll()}>
  293. 取消报考
  294. </Button>}
  295. {!enroll.date && <Button size="small" radius onClick={() => this.enroll()}>
  296. 我已报考
  297. </Button>}
  298. <Link to="/textbook/year" className="f-r">
  299. 按年份查看 >
  300. </Link>
  301. </div>
  302. <TwoDate
  303. key={load}
  304. startDate={startDate}
  305. endDate={endDate}
  306. getType={date => {
  307. const d = date.format('YYYY-MM-DD');
  308. if (enroll.date && d === enroll.dateF) {
  309. return 'type-2';
  310. }
  311. if (this.libraryMap[d]) {
  312. return 'type-1';
  313. }
  314. return null;
  315. }}
  316. extendInfo={date => {
  317. const d = date.format('YYYY-MM');
  318. return `${this.enrollMap[d] ? this.enrollMap[d].enrollNumber : 0}人`;
  319. }}
  320. onChange={(date) => this.setState({ date })}
  321. />
  322. </div>
  323. <div style={{ width: 275 }} className="b f-r p-20">
  324. <div className="t-13 t-s-16">最近换库</div>
  325. <Assets name="" />
  326. <div className="t-13 t-s-32 t-c">{latest.startDate ? formatDate(latest.startDate, 'YYYY-MM-DD') : ''}</div>
  327. <div className="t-13 t-c t-s-16">
  328. 已换库 <span className="t-4">{day}</span> 天
  329. </div>
  330. <div className="m-t-2 t-c">
  331. <Button width={100} radius size="lager" onClick={() => User.needLogin().then(() => linkTo('/my/tools?tab=textbook'))}>
  332. 我的机经
  333. </Button>
  334. </div>
  335. <div className="m-t-2 t-13 t-c t-s-14">
  336. 本月共{useNumber || 0}人使用机经
  337. </div>
  338. </div>
  339. </div>
  340. </div>
  341. );
  342. }
  343. renderList() {
  344. const { list } = this.state;
  345. return (
  346. <div className="list-layout">
  347. <div className="content">
  348. {list.map(item => {
  349. return <TextbookItem
  350. data={item}
  351. menu={[
  352. { label: '更新', key: 'update' },
  353. { label: '反馈', key: 'feedback' },
  354. { label: '评价', key: 'comment' },
  355. ]}
  356. onClick={() => linkTo(`/textbook/topic/list/${item.subject}`)}
  357. onMenuClick={value => {
  358. const { key } = value;
  359. if (key === 'comment') {
  360. this.setState({ showComment: true, comment: { channel: 'library' } });
  361. } else if (key === 'update') {
  362. this.textbookHistory({ page: 1, size: 100, subject: item.subject });
  363. } else if (key === 'feedback') {
  364. this.setState({ showFeedback: true, feedback: { questionSubject: item.subject, target: TextbookFeedbackTarget[0].value } });
  365. }
  366. }} />;
  367. })}
  368. </div>
  369. </div>
  370. );
  371. }
  372. renderLog() {
  373. const { data, subject, updateList } = this.state;
  374. return (
  375. <div className="table-layout">
  376. <div className="content">
  377. <div className="t">
  378. <span className="d-i-b t-1 t-s-18">更新日志</span>
  379. <Tabs
  380. type="text"
  381. tabs={[{ title: '数学', key: 'quant' }, { title: '阅读RC', key: 'rc' }, { title: '逻辑IR', key: 'ir' }]}
  382. active={subject}
  383. onTabChange={(key) => this.textbookHistory({ subject: key })}
  384. />
  385. </div>
  386. <UserTable
  387. size="small"
  388. columns={[
  389. { title: '更新时间', key: 'date' },
  390. { title: '版本', key: 'version' },
  391. { title: '更新内容', key: 'content' },
  392. ]}
  393. data={updateList}
  394. />
  395. <Assets name="textbook_banner" onClick={() => this.open(data.unUseRecord.id)} />
  396. </div>
  397. </div>
  398. );
  399. }
  400. renderCompare() {
  401. return (
  402. <div className="compare-layout">
  403. <div className="t-14 t-c t-s-32 m-b-2">让机经帮上忙,而不是帮倒忙!</div>
  404. <div className="t-c m-b-2">
  405. <Button width={100} size="lager" radius className="m-r-2" onClick={() => this.buy()}>
  406. 立刻购买
  407. </Button>
  408. <Button width={100} size="lager" radius className="m-l-2" onClick={() => linkTo('/examination?tab1=textbook')}>
  409. 试用往期
  410. </Button>
  411. </div>
  412. <div className="table">
  413. <table>
  414. <thead>
  415. <tr>
  416. <th>千行机经</th>
  417. <th>其他机经</th>
  418. </tr>
  419. </thead>
  420. <tbody>
  421. <tr>
  422. <td>整理内容+梳理逻辑结构</td>
  423. <td>只关注内容</td>
  424. </tr>
  425. <tr>
  426. <td>最新版本自动更新至邮箱</td>
  427. <td>手动领取</td>
  428. </tr>
  429. <tr>
  430. <td>重视考场一手信息,越准越好</td>
  431. <td>越多越好</td>
  432. </tr>
  433. <tr>
  434. <td>独家资源,严格把关</td>
  435. <td>市面资源</td>
  436. </tr>
  437. <tr>
  438. <td>一键反馈,随时沟通</td>
  439. <td>无售后系统</td>
  440. </tr>
  441. <tr>
  442. <td>下载至本地、在线浏览、在线做题,多种查阅方式</td>
  443. <td>下载至本地</td>
  444. </tr>
  445. </tbody>
  446. </table>
  447. </div>
  448. </div>
  449. );
  450. }
  451. }