page.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Assets from '@src/components/Assets';
  5. import { getMap, formatDate } from '@src/services/Tools';
  6. import Checkbox from '../../../components/CheckBox';
  7. import Button from '../../../components/Button';
  8. import { My } from '../../../stores/my';
  9. import { ServiceKey } from '../../../../Constant';
  10. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  11. export default class extends Page {
  12. initData() {
  13. const { id } = this.params;
  14. My.getOrderRecord(id)
  15. .then(result => {
  16. this.setState(result);
  17. });
  18. }
  19. submit() {
  20. My.useRecord(this.params.id)
  21. .then();
  22. }
  23. renderView() {
  24. const { productType } = this.state;
  25. if (productType === 'service') {
  26. return this.renderService();
  27. }
  28. return this.renderCourse();
  29. }
  30. renderCourse() {
  31. const { course = {}, endTime } = this.state;
  32. if (!endTime) return null;
  33. return (
  34. <div>
  35. <div className="icon">
  36. <Assets name="img3" />
  37. </div>
  38. <div className="title">您正在开通“{course.data}”</div>
  39. <div className="tip">有效期至:{formatDate(endTime, 'YYYY-MM-DD')}</div>
  40. <Button block radius onClick={() => {
  41. this.submit();
  42. }}>
  43. 立即开通
  44. </Button>
  45. <div className="no" onClick={() => {
  46. goBack();
  47. }}>暂不开通</div>
  48. </div>
  49. );
  50. }
  51. renderService() {
  52. const { service, endTime } = this.state;
  53. if (!endTime) return null;
  54. return (
  55. <div>
  56. <div className="icon">
  57. <Assets name="img3" />
  58. </div>
  59. <div className="title">您正在开通“{ServiceKeyMap[service]}”</div>
  60. <div className="tip">有效期至:{formatDate(endTime, 'YYYY-MM-DD')}</div>
  61. {service === 'textbook' && <div className="check">
  62. <Checkbox checked={!!this.state.checked} onClick={() => {
  63. this.setState({ checked: !this.state.checked });
  64. }} />
  65. <span>邮箱订阅机经</span>
  66. </div>}
  67. <Button block radius onClick={() => {
  68. this.submit();
  69. }}>
  70. 立即开通
  71. </Button>
  72. <div className="no" onClick={() => {
  73. goBack();
  74. }}>暂不开通</div>
  75. </div>
  76. );
  77. }
  78. }