page.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React from 'react';
  2. import './index.less';
  3. import { Tabs } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { formatDate, getMap } from '@src/services/Tools';
  7. import Money from '../../../components/Money';
  8. import Button from '../../../components/Button';
  9. import Tag from '../../../components/Tag';
  10. import { Course } from '../../../stores/course';
  11. import { Order } from '../../../stores/order';
  12. import { DataType } from '../../../../Constant';
  13. import { FAQItem, CommentItem } from '../../../components/Item';
  14. const DataTypeMap = getMap(DataType, 'value', 'label');
  15. export default class extends Page {
  16. initState() {
  17. return { tab: 'content' };
  18. }
  19. initData() {
  20. const { id } = this.params;
  21. Course.getData(id).then(data => {
  22. this.setState({ data });
  23. });
  24. }
  25. buy() {
  26. Order.speedPay({ productType: 'data', productId: this.params.id })
  27. .then((result) => {
  28. linkTo(`/pay/${result.id}`);
  29. });
  30. }
  31. renderText() {
  32. const { tab, data } = this.state;
  33. let content;
  34. switch (tab) {
  35. case 'content':
  36. case 'authorContent':
  37. case 'methodContent':
  38. content = <div dangerouslySetInnerHTML={{ __html: data[tab] }} />;
  39. break;
  40. case 'faq':
  41. content = (
  42. <div>
  43. {(data.faqs || []).map(row => (
  44. <FAQItem data={row} />
  45. ))}
  46. </div>
  47. );
  48. break;
  49. case 'comment':
  50. content = (
  51. <div>
  52. {(data.comments || []).map(row => (
  53. <CommentItem data={row} />
  54. ))}
  55. </div>
  56. );
  57. break;
  58. default:
  59. break;
  60. }
  61. return content;
  62. }
  63. renderView() {
  64. const { data = {}, tab } = this.state;
  65. return (
  66. <div>
  67. <div className="detail">
  68. <Assets className="info-img" name="d_b" src={data.cover} />
  69. <div className="info">
  70. <div className="title">{data.title}</div>
  71. <div className="tags">
  72. {data.isOriginal > 0 && <Tag size="small">原创</Tag>}
  73. {data.isNovice > 0 && <Tag size="small">适合新手</Tag>}
  74. </div>
  75. <div className="data">页数: {data.pages}页</div>
  76. <div className="data">格式: {DataTypeMap[data.dataType]}</div>
  77. <div className="data">{data.updateTime && formatDate(data.updateTime, 'YYYY-MM-DD HH:mm')} 更新</div>
  78. <Money value={data.price} size="lager" theme="sell" />
  79. </div>
  80. </div>
  81. <div className="desc" dangerouslySetInnerHTML={{ __html: data.description }} />
  82. <Tabs
  83. page={tab}
  84. tabs={[
  85. { title: '资料介绍', key: 'content' },
  86. { title: '作者介绍', key: 'authorContent' },
  87. { title: '获取方式', key: 'methodContent' },
  88. { title: 'FAQs', key: 'faq' },
  89. { title: '用户评价', key: 'comment' },
  90. ]}
  91. onChange={value => {
  92. this.setState({ tab: value.key });
  93. }}
  94. />
  95. {this.renderText()}
  96. <div className="fixed">
  97. <div className="fee">
  98. 总额: <Money value={data.price} size="lager" />
  99. </div>
  100. <Button
  101. width={110}
  102. className="f-r"
  103. radius
  104. onClick={() => {
  105. this.buy();
  106. }}
  107. >
  108. 立即购买
  109. </Button>
  110. </div>
  111. </div>
  112. );
  113. }
  114. }