page.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from 'react';
  2. import './index.less';
  3. import { Tabs } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import Money from '../../../components/Money';
  6. import Button from '../../../components/Button';
  7. import { FAQItem, CommentItem } from '../../../components/Item';
  8. import { Course } from '../../../stores/course';
  9. import { Order } from '../../../stores/order';
  10. import { PcUrl } from '../../../../Constant';
  11. export default class extends Page {
  12. initState() {
  13. return { tab: 'teacherContent' };
  14. }
  15. initData() {
  16. const { id } = this.params;
  17. Course.get(id).then(result => {
  18. this.setState({ data: result });
  19. });
  20. }
  21. buy() {
  22. Order.speedPay({ productType: 'course', productId: this.params.id })
  23. .then((result) => {
  24. linkTo(`/pay/${result.id}`);
  25. });
  26. }
  27. renderText() {
  28. const { tab, data } = this.state;
  29. let content;
  30. switch (tab) {
  31. case 'teacherContent':
  32. case 'baseContent':
  33. case 'pointContent':
  34. content = <div dangerouslySetInnerHTML={{ __html: data[tab] }} />;
  35. break;
  36. case 'faq':
  37. content = <div>{(data.faqs || []).map(row => <FAQItem data={row} />)}</div>;
  38. break;
  39. case 'comment':
  40. content = <div>{(data.comments || []).map(row => <CommentItem data={row} />)}</div>;
  41. break;
  42. default:
  43. break;
  44. }
  45. return content;
  46. }
  47. renderView() {
  48. const { data = {}, tab } = this.state;
  49. return (
  50. <div>
  51. <div className="b-g" style={{ backgroundImage: `url(${data.cover})` }}>
  52. <div className="title">{data.title}</div>
  53. </div>
  54. <div className="tip">访问{PcUrl}/course/detail/{data.id},试听该课程</div>
  55. <div className="detail">
  56. <Tabs
  57. page={tab}
  58. tabs={[
  59. { title: '老师资质', key: 'teacherContent' },
  60. { title: '基本参数', key: 'baseContent' },
  61. { title: '授课重点', key: 'pointContent' },
  62. { title: 'FAQs', key: 'faq' },
  63. { title: '用户评价', key: 'comment' },
  64. ]}
  65. onChange={(value) => {
  66. this.setState({ tab: value.key });
  67. }}
  68. />
  69. {this.renderText()}
  70. </div>
  71. <div className="fixed">
  72. <div className="fee">
  73. 总额: <Money value={data.price} size="lager" />
  74. </div>
  75. <Button width={110} className="f-r" radius onClick={() => {
  76. this.buy();
  77. }}>
  78. 立即购买
  79. </Button>
  80. </div>
  81. </div>
  82. );
  83. }
  84. }