page.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 Icon from '../../../components/Icon';
  9. import { Order } from '../../../stores/order';
  10. import { ServiceKey } from '../../../../Constant';
  11. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  12. export default class extends Page {
  13. initState() {
  14. return { state: 'open' };
  15. }
  16. initData() {
  17. const { id } = this.params;
  18. Order.getRecord(id)
  19. .then(result => {
  20. if (result.isUse) {
  21. this.setState({ state: 'finish', data: result });
  22. return;
  23. }
  24. this.setState(result);
  25. });
  26. }
  27. submit() {
  28. Order.useRecord(this.params.id)
  29. .then((result) => {
  30. this.setState({ state: 'finish', data: result });
  31. });
  32. }
  33. renderView() {
  34. const { state } = this.state;
  35. switch (state) {
  36. case 'finish':
  37. return this.renderFinish();
  38. default:
  39. return this.renderOpen();
  40. }
  41. }
  42. renderOpen() {
  43. const { productType } = this.state;
  44. if (productType === 'service') {
  45. return this.renderService();
  46. }
  47. return this.renderCourse();
  48. }
  49. renderCourse() {
  50. const { course = {}, endTime } = this.state;
  51. if (!endTime) return null;
  52. return (
  53. <div>
  54. <div className="icon">
  55. <Assets name="img3" />
  56. </div>
  57. <div className="title">您正在开通“{course.data}”</div>
  58. <div className="tip">有效期至:{formatDate(endTime, 'YYYY-MM-DD')}</div>
  59. <Button block radius onClick={() => {
  60. this.submit();
  61. }}>
  62. 立即开通
  63. </Button>
  64. <div className="no" onClick={() => {
  65. goBack();
  66. }}>暂不开通</div>
  67. </div>
  68. );
  69. }
  70. renderService() {
  71. const { service, endTime } = this.state;
  72. if (!endTime) return null;
  73. return (
  74. <div>
  75. <div className="icon">
  76. <Assets name="img3" />
  77. </div>
  78. <div className="title">您正在开通“{ServiceKeyMap[service]}”服务</div>
  79. <div className="tip">有效期至:{formatDate(endTime, 'YYYY-MM-DD')}</div>
  80. {service === 'textbook' && <div className="check">
  81. <Checkbox checked={!!this.state.checked} onClick={() => {
  82. this.setState({ checked: !this.state.checked });
  83. }} />
  84. <span>邮箱订阅机经</span>
  85. </div>}
  86. <Button block radius onClick={() => {
  87. this.submit();
  88. }}>
  89. 立即开通
  90. </Button>
  91. <div className="no" onClick={() => {
  92. goBack();
  93. }}>暂不开通</div>
  94. </div>
  95. );
  96. }
  97. renderFinish() {
  98. const { data } = this.state;
  99. return (
  100. <div className="finish">
  101. <div className="icon">
  102. <Icon type="check-circle" />
  103. </div>
  104. <div className="title">开通成功!</div>
  105. <div className="desc">生效时间:{formatDate(data.useStartTime, 'YYYY-MM-DD')}</div>
  106. </div>
  107. );
  108. }
  109. }