page.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. import React from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { asyncSMessage } from '@src/services/AsyncTools';
  7. import { formatDate, getMap } from '@src/services/Tools';
  8. import UserLayout from '../../../layouts/User';
  9. import UserAction from '../../../components/UserAction';
  10. import menu from '../index';
  11. import Tabs from '../../../components/Tabs';
  12. import More from '../../../components/More';
  13. import Button from '../../../components/Button';
  14. import Switch from '../../../components/Switch';
  15. import TotalSort from '../../../components/TotalSort';
  16. import Modal from '../../../components/Modal';
  17. import UserTable from '../../../components/UserTable';
  18. import UserPagination from '../../../components/UserPagination';
  19. import { My } from '../../../stores/my';
  20. import { User } from '../../../stores/user';
  21. import { Order } from '../../../stores/order';
  22. import { Textbook } from '../../../stores/textbook';
  23. import { DataType, ServiceKey } from '../../../../Constant';
  24. import { Main } from '../../../stores/main';
  25. import { Question } from '../../../stores/question';
  26. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  27. const dataHistoryColumns = [
  28. { title: '更新时间', key: 'time', width: 120 },
  29. { title: '位置', key: 'position', width: 120 },
  30. { title: '原内容', key: 'originContent', width: 120 },
  31. { title: '更改为', key: 'content', width: 120 },
  32. { title: '更新至', key: 'version', width: 90 },
  33. ];
  34. const textbookHistoryColumns = [
  35. { title: '更新时间', key: 'createTime', width: 120 },
  36. { title: '版本', key: 'version', width: 120 },
  37. { title: '更新内容', key: 'content', width: 330 },
  38. ];
  39. const openColumns = [
  40. { title: '商品名称', key: 'title', width: 240 },
  41. { title: '开通期限', key: 'endTime', width: 240 },
  42. { title: '操作', key: 'handler', width: 90 },
  43. ];
  44. export default class extends Page {
  45. initState() {
  46. return {
  47. tab: 'data',
  48. sortMap: {},
  49. filterMap: {},
  50. };
  51. }
  52. initData() {
  53. const data = Object.assign(this.state, this.state.search);
  54. if (data.order) {
  55. data.sortMap = { [data.order]: data.direction };
  56. }
  57. data.filterMap = this.state.search;
  58. this.setState(data);
  59. const { tab } = this.state;
  60. switch (tab) {
  61. case 'textbook':
  62. this.refreshTextbook();
  63. break;
  64. case 'examination':
  65. this.refreshExamination();
  66. break;
  67. case 'vip':
  68. this.refreshVip();
  69. break;
  70. case 'cal':
  71. break;
  72. case 'data':
  73. default:
  74. this.refreshData();
  75. break;
  76. }
  77. }
  78. refreshTextbook() {
  79. Main.getService('textbook').then(result => {
  80. this.setState({ service: result });
  81. });
  82. Textbook.getInfo()
  83. .then(result => {
  84. const { latest } = result;
  85. result.day = parseInt((new Date().getTime() - new Date(result.latest.startDate).getTime()) / 86400000, 10);
  86. result.expireDay = result.expireTime && parseInt((new Date().getTime() - new Date(result.expireTime).getTime()) / 86400000, 10);
  87. const list = [];
  88. list.push({ subject: 'quant', number: latest.quantNumber, time: latest.quantTime, version: latest.quantVersion });
  89. list.push({ subject: 'rc', number: latest.rcNumber, time: latest.rcTime, version: latest.rcVersion });
  90. list.push({ subject: 'ir', number: latest.irNumber, time: latest.irTime, version: latest.irVersion });
  91. this.setState({ data: result, list });
  92. });
  93. }
  94. textbookHistory({ page, size, subject }) {
  95. Textbook.listHistory({ subject })
  96. .then(result => {
  97. this.setState({
  98. updateList: result.map(row => {
  99. row.version = row[`${subject}Version`];
  100. row.content = row[`${subject}Content`];
  101. row.createTime = formatDate(row.createTime, 'YYYY-MM-DD\nHH:mm:ss');
  102. return row;
  103. }),
  104. // 不显示分页
  105. updateTotal: 0,
  106. updatePage: page,
  107. updateData: { page, size, subject, columns: textbookHistoryColumns, type: 'textbook' },
  108. });
  109. });
  110. }
  111. refreshExamination() {
  112. Main.getService('qx_cat').then(result => {
  113. this.setState({ service: result });
  114. });
  115. Question.getExaminationInfo(result => {
  116. result.expireDay = result.expireTime && parseInt((new Date().getTime() - new Date(result.expireTime).getTime()) / 86400000, 10);
  117. this.setState({ data: result });
  118. });
  119. }
  120. refreshVip() {
  121. Main.getService('vip').then(result => {
  122. this.setState({ service: result });
  123. });
  124. }
  125. recordList({ page, size, service, isUse, isExpire }) {
  126. Order.listRecord({ page, size, productType: 'service', service, isUse, isExpire })
  127. .then(result => {
  128. this.setState({
  129. updateList: result.map(row => {
  130. row.title = ServiceKeyMap[service];
  131. row.handler = <a onClick={() => {
  132. this.open(row.id);
  133. }}>立即开通</a>;
  134. row.endTime = `${formatDate(row.endTime, 'YYYY-MM-DD')} 前`;
  135. return row;
  136. }),
  137. updateTotal: result.length,
  138. updatePage: page,
  139. updateData: { page, size, service, isUse, columns: isUse ? [] : openColumns, type: 'record' },
  140. });
  141. });
  142. }
  143. refreshData() {
  144. const dataTypeSelect = DataType.map(row => {
  145. row.title = row.label;
  146. row.key = row.value;
  147. return row;
  148. });
  149. dataTypeSelect.unshift({
  150. title: '全部',
  151. key: '',
  152. });
  153. this.setState({ dataTypeSelect });
  154. Main.dataStruct().then(result => {
  155. const structs = result.filter(row => row.level === 1).map(row => {
  156. row.title = `${row.titleZh}${row.titleEn}`;
  157. row.key = `${row.id}`;
  158. return row;
  159. });
  160. structs.unshift({
  161. title: '全部',
  162. key: '',
  163. });
  164. this.setState({
  165. structs,
  166. });
  167. });
  168. My.listData(Object.assign({}, this.state.search))
  169. .then(result => {
  170. result = {
  171. list: [{
  172. title: '123123',
  173. latestTime: '',
  174. id: 1,
  175. number: 10,
  176. version: '1231',
  177. }],
  178. };
  179. this.setState({
  180. list: result.list.map(row => {
  181. row.time = formatDate(row.time, 'YYYY-MM-DD HH:mm:ss');
  182. return row;
  183. }),
  184. total: result.total,
  185. page: this.state.search.page,
  186. });
  187. });
  188. }
  189. dataHistory({ dataId, page, size }) {
  190. My.listDataHistory({ page, size, dataId })
  191. .then(result => {
  192. result.list = result.list.map(row => {
  193. row.time = formatDate(row.time, 'YYYY-MM-DD\nHH:mm:ss');
  194. return row;
  195. });
  196. this.setState({ updateList: result.list, updateTotal: result.total, updatePage: page, updateData: { page, size, dataId, columns: dataHistoryColumns, type: 'data' } });
  197. });
  198. }
  199. onFilter(value) {
  200. this.search(value);
  201. }
  202. onSort(value) {
  203. const { sortMap } = this.state;
  204. const keys = Object.keys(value);
  205. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  206. this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null });
  207. }
  208. onTabChange(tab) {
  209. const data = { tab };
  210. this.refreshQuery(data);
  211. }
  212. submitComment() {
  213. const { comment } = this.state;
  214. My.addComment(comment.channel, comment.position, comment.content)
  215. .then(() => {
  216. this.setState({ showComment: false, showFinish: true, comment: {} });
  217. });
  218. }
  219. submitFeedbackError() {
  220. const { feedbackError } = this.state;
  221. My.addFeedbackErrorData(feedbackError.dataId, feedbackError.title, feedbackError.position, feedbackError.originContent, feedbackError.content)
  222. .then(() => {
  223. this.setState({ showFinish: true, showFeedbackError: false, feedbackError: {} });
  224. });
  225. }
  226. submitFeedback() {
  227. const { feedback } = this.state;
  228. My.addTextbookFeedback('', feedback.target, feedback.content)
  229. .then(() => {
  230. this.setState({ showFinish: true, showFeedback: false, feedbackError: {} });
  231. });
  232. }
  233. subscribe(value) {
  234. My.subscribeData(value)
  235. .then(() => {
  236. const { info } = this.props.user;
  237. info.dataEmailSubscribe = value;
  238. User.infoHandle(info);
  239. })
  240. .catch(err => {
  241. asyncSMessage(err.message, 'warn');
  242. });
  243. }
  244. open(recordId) {
  245. Order.useRecord(recordId).then(() => {
  246. asyncSMessage('开通成功');
  247. this.refresh();
  248. });
  249. }
  250. renderView() {
  251. const { config } = this.props;
  252. return <UserLayout active={config.key} menu={menu} center={this.renderDetail()} />;
  253. }
  254. renderDetail() {
  255. const { tab, comment = {}, showComment, showFinish, showUpdate, updateList, updateTotal, updateData = {} } = this.state;
  256. return (
  257. <div className="table-layout">
  258. <Tabs
  259. border
  260. type="division"
  261. theme="theme"
  262. size="small"
  263. space={2.5}
  264. width={100}
  265. active={tab}
  266. tabs={[
  267. { key: 'data', title: '资料' },
  268. { key: 'textbook', title: '机经' },
  269. { key: 'examination', title: '模考' },
  270. { key: 'vip', title: 'VIP' },
  271. { key: 'cal', title: '考分计算器' },
  272. ]}
  273. onChange={key => this.onTabChange(key)}
  274. />
  275. {this[`renderTab${tab}`]()}
  276. <Modal show={showUpdate} maskClosable close={false} body={false} width={630} onClose={() => this.setState({ showUpdate: false, updateList: [] })} >
  277. <UserTable
  278. size="small"
  279. columns={updateData.columns}
  280. data={updateList}
  281. current={updateData.page}
  282. onChange={(page) => {
  283. updateData.page = page;
  284. if (updateData.type === 'data') {
  285. this.dataHistory(updateData);
  286. } else if (updateData.type === 'textbook') {
  287. this.textbookHistory(updateData);
  288. } else if (updateData.type === 'record') {
  289. this.recordList(updateData);
  290. }
  291. }}
  292. total={updateTotal}
  293. />
  294. </Modal>
  295. <Modal show={showComment} title="评价" onConfirm={() => comment.content && this.submitComment()} onCancel={() => this.setState({ showComment: false, comment: {} })}>
  296. <textarea value={comment.content} className="b-c-1 w-10 p-10" rows={6} placeholder="您的看法对我们来说很重要!" onChange={(e) => {
  297. comment.content = e.target.value;
  298. this.setState({ comment });
  299. }} />
  300. <div className="b-b m-t-2" />
  301. </Modal>
  302. <Modal show={showFinish} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => this.setState({ showFinish: false })} >
  303. <div className="t-2 t-s-18">
  304. <Icon type="check" className="t-5 m-r-5" />
  305. 您的每一次反馈都是千行进步的动力。
  306. </div>
  307. </Modal>
  308. </div>
  309. );
  310. }
  311. renderTabdata() {
  312. const { list = [], filterMap = {}, sortMap = {}, structs, dataTypeSelect, total, page } = this.state;
  313. const { info } = this.props.user;
  314. return (
  315. <div className="tab-1-layout">
  316. <UserAction
  317. selectList={[{
  318. label: '学科',
  319. key: 'structId',
  320. select: structs,
  321. },
  322. {
  323. label: '资料形式',
  324. key: 'dataType',
  325. select: dataTypeSelect,
  326. }]}
  327. sortList={[{ right: true, label: '销量', key: 'sale_number' }, { right: true, label: '更新时间', key: 'latest_time' }]}
  328. sortMap={sortMap}
  329. filterMap={filterMap}
  330. onFilter={value => this.onFilter(value)}
  331. onSort={value => this.onSort(value)}
  332. right={
  333. <div className="email">
  334. 邮箱订阅 <Switch checked={info.dataEmailSubscribe} onChange={() => {
  335. this.subscribe(!info.dataEmailSubscribe);
  336. }} />
  337. </div>
  338. }
  339. />
  340. <div className="data-layout">
  341. {list.map(item => {
  342. return (
  343. <div className="data-item">
  344. <Assets name="sun_blue" src={item.cover} />
  345. <div className="fixed">
  346. <div className="btns">
  347. <Button size="small" radius onClick={() => {
  348. openLink(item.resource);
  349. }}>
  350. 阅读
  351. </Button>
  352. <div className="white" onClick={() => {
  353. openLink(item.resource);
  354. }}>下载</div>
  355. </div>
  356. </div>
  357. <div className="title">
  358. <span>版本{item.version}</span>
  359. {item.title}
  360. </div>
  361. <div className="date">{formatDate(item.latestTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  362. <More
  363. menu={[{ label: '纠错', key: 'feedback' }, { label: '评价', key: 'comment' }, { label: '更新', key: 'update' }]}
  364. onClick={(value) => {
  365. const { key } = value;
  366. if (key === 'comment') {
  367. this.setState({ showComment: true, comment: { channel: 'course_data', position: item.id } });
  368. } else if (key === 'update') {
  369. this.setState({ showUpdate: true });
  370. this.dataHistory({ dataId: item.id, page: 1, size: 10 });
  371. } else if (key === 'feedback') {
  372. this.setState({ showFeedbackError: true, feedbackError: { dataId: item.id, title: item.title } });
  373. }
  374. }}
  375. />
  376. </div>
  377. );
  378. })}
  379. </div>
  380. {total && list.length > 0 && <UserPagination total={total} current={page} onChange={(p) => this.onChangePage(p)} />}
  381. </div>
  382. );
  383. }
  384. renderTabtextbook() {
  385. const { data = {}, list = [], service } = this.state;
  386. const { latest = {}, day } = data;
  387. return (
  388. <div className="tab-2-layout">
  389. <UserAction
  390. left={
  391. <div className="total-log">
  392. <span>最新换库</span>
  393. <span>{latest.startDate ? formatDate(latest.startDate, 'YYYY-MM-DD') : ''}</span>
  394. <span>
  395. 已换库<b>{day}</b>天
  396. </span>
  397. </div>
  398. }
  399. right={!data.hasService && data.unUseRecord && <div className="email" onClick={() => {
  400. this.recordList({ page: 1, size: 10, service: 'textbook', isUse: false, isExpire: false });
  401. }}>待开通</div>}
  402. />
  403. {data.hasService && <div className="data-layout">
  404. {list.map(item => {
  405. return (
  406. <div className="data-item">
  407. <Assets name="sun_blue" />
  408. <div className="title">
  409. 已更新至<b>{item.num}</b>题
  410. </div>
  411. <div className="date">{item.date}</div>
  412. <More
  413. menu={[{ label: '更新', key: 'update' }, { label: '反馈', key: 'feedback' }, { label: '评价', key: 'comment' }]}
  414. onClick={(value) => {
  415. const { key } = value;
  416. if (key === 'comment') {
  417. this.setState({ showComment: true, comment: { channel: 'library' } });
  418. } else if (key === 'update') {
  419. this.setState({ showUpdate: true });
  420. this.textbookHistory({ page: 1, size: 100, subject: item.subject });
  421. } else if (key === 'feedback') {
  422. this.setState({ showFeedback: true });
  423. }
  424. }}
  425. />
  426. </div>
  427. );
  428. })}
  429. </div>}
  430. {!data.hasService && !data.unUseRecord && <div className="tip-layout">
  431. <div className="t1">还未购买本月机经</div>
  432. <div className="desc">¥ {service && service.package && service.package[0].price}</div>
  433. <Button radius size="lager" width={150}>
  434. 立即购买
  435. </Button>
  436. </div>}
  437. {data.hasService && <div className="tip-layout">
  438. <div className="t1">使用中</div>
  439. <div className="t2">距离到期还有 {data.expireDay} 天</div>
  440. </div>}
  441. {!data.hasService && data.unUseRecord && <div className="tip-layout">
  442. <div className="t2">请于{formatDate(data.unUseRecord.endTime, 'YYYY-MM-DD')}前开通</div>
  443. <Button radius size="lager" width={150} onClick={() => {
  444. this.open(data.unUseRecord.id);
  445. }}>
  446. 立即开通
  447. </Button>
  448. </div>}
  449. </div>
  450. );
  451. }
  452. renderTabexamination() {
  453. const { data = {}, service } = this.state;
  454. return (
  455. <div className="tab-3-layout">
  456. <UserAction right={!data.hasService && data.unUseRecord && <div className="email" onClick={() => {
  457. this.recordList({ page: 1, size: 10, service: 'qx_cat', isUse: false, isExpire: false });
  458. }}>待开通</div>} />
  459. {!data.hasService && !data.unUseRecord && !data.expireTime && <div className="tip-layout">
  460. <div className="t1">未购买</div>
  461. <div className="desc">¥ {service && service.package && service.package[0].price}</div>
  462. <Button radius size="lager" width={150}>
  463. 立即购买
  464. </Button>
  465. </div>}
  466. {!data.hasService && data.unUseRecord && <div className="tip-layout">
  467. <div className="t2">请于{formatDate(data.unUseRecord.endTime, 'YYYY-MM-DD')}前开通</div>
  468. <Button radius size="lager" width={150} onClick={() => {
  469. this.open(data.unUseRecord.id);
  470. }}>
  471. 立即开通
  472. </Button>
  473. </div>}
  474. {data.hasService && <div className="tip-layout">
  475. <div className="t1">使用中</div>
  476. <div className="t2">距离到期还有 {data.expireDay} 天</div>
  477. </div>}
  478. {!data.hasService && !data.unUseRecord && data.expireTime && <div className="tip-layout">
  479. <div className="t3">已过期</div>
  480. <div className="date">{formatDate(data.startTime, 'YYYY-MM-DD')} ~ {formatDate(data.expireTime, 'YYYY-MM-DD')}</div>
  481. <div className="desc">¥ {service && service.package && service.package[0].price}</div>
  482. <Button radius size="lager" width={150}>
  483. 立即购买
  484. </Button>
  485. </div>}
  486. </div>
  487. );
  488. }
  489. renderTabvip() {
  490. const { data } = this.state;
  491. return (
  492. <div className="tab-4-layout">
  493. {!data.hasService && !data.unUseRecord && !data.expireTime && <div className="tip-layout">
  494. <div className="t2">未购买</div>
  495. <Button radius size="lager" width={150}>
  496. 立即购买
  497. </Button>
  498. </div>}
  499. {data.hasService && <div className="tip-layout">
  500. <div className="t1">使用中</div>
  501. <div className="desc">{formatDate(data.expireTime, 'YYYY-MM-DD')} 到期</div>
  502. <Button radius size="lager" width={150}>
  503. 续费
  504. </Button>
  505. </div>}
  506. {!data.hasService && !data.unUseRecord && data.expireTime && <div className="tip-layout">
  507. <div className="t1">已过期</div>
  508. <div className="desc">{formatDate(data.startTime, 'YYYY-MM-DD')} ~ {formatDate(data.expireTime, 'YYYY-MM-DD')}</div>
  509. <Button radius size="lager" width={150}>
  510. 立即购买
  511. </Button>
  512. </div>}
  513. </div>
  514. );
  515. }
  516. renderTabcal() {
  517. const { data = {} } = this.state;
  518. return (
  519. <div className="tab-5-layout">
  520. <TotalSort
  521. value={data.value || 650}
  522. onChange={(value) => {
  523. data.value = value;
  524. this.setState({ data });
  525. }}
  526. />
  527. </div>
  528. );
  529. }
  530. }