page.js 16 KB

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