page.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Assets from '@src/components/Assets';
  5. import Page from '@src/containers/Page';
  6. import { getMap, formatMoney } from '@src/services/Tools';
  7. import Button from '../../../components/Button';
  8. import { SingleItem } from '../../../components/Item';
  9. import Footer from '../../../components/Footer';
  10. import { Contact } from '../../../components/Other';
  11. import { Main } from '../../../stores/main';
  12. import { Course } from '../../../stores/course';
  13. import { User } from '../../../stores/user';
  14. import { Order } from '../../../stores/order';
  15. import { ServiceKey, ServiceParamMap } from '../../../../Constant';
  16. const serviceIconMap = {
  17. textbook: 'mokao',
  18. vip: 'VIP_1',
  19. qx_cat: 'jijing',
  20. };
  21. export default class extends Page {
  22. constructor(props) {
  23. props.size = 10;
  24. super(props);
  25. }
  26. init() {
  27. Main.getBase()
  28. .then(result => {
  29. this.setState({ base: result });
  30. });
  31. }
  32. initData() {
  33. const { id } = this.params;
  34. Course.getPackage(id)
  35. .then(result => {
  36. this.setState({ data: result });
  37. });
  38. }
  39. buy() {
  40. const { data } = this.state;
  41. User.needLogin().then(() => {
  42. Order.speedPay({ productType: 'course_package', productId: data.id }).then(result => {
  43. User.needPay(result).then(() => {
  44. linkTo('/my/course');
  45. });
  46. });
  47. });
  48. }
  49. add() {
  50. const { data } = this.state;
  51. User.needLogin().then(() => {
  52. Order.addCheckout({ productType: 'course_package', productId: data.id }).then(() => {
  53. this.setState({ add: true });
  54. });
  55. });
  56. }
  57. renderView() {
  58. const { data = {}, base = {}, add } = this.state;
  59. const hasGift = data.gift && Object.keys(data.gift).length > 0;
  60. return (
  61. <div>
  62. <div className="top content t-8">
  63. <Link to="/course">千行课堂</Link> > <Link to="/course/online?tab=package">全部套餐</Link> > <Link to={`/course/package/detail/${data.id}`}>{data.title}</Link> > <span className="t-1">套餐详情</span>
  64. </div>
  65. <div className="center content">
  66. <div className="t-1 t-s-20 m-b-2">
  67. {data.title}
  68. <div className="action f-r">
  69. <Button className="m-r-1" radius size="lager" onClick={() => this.buy()}>
  70. 立即购买
  71. </Button>
  72. <Button
  73. className="f-r"
  74. theme="default"
  75. radius
  76. size="lager"
  77. disabled={data.add || add}
  78. onClick={() => this.add()}
  79. >
  80. <Assets name={data.add || add ? 'add_disabled' : 'add'} />
  81. </Button>
  82. </div>
  83. </div>
  84. <div className="t-7 t-s-18 f-w-b m-b-1">套餐价: ¥ {formatMoney(data.price)}</div>
  85. <div className="t-1 t-s-16 desc">{data.description}</div>
  86. <div className="main-title">包含课程</div>
  87. <div className="list">
  88. {(data.courses || []).map(item => {
  89. return <SingleItem noAction data={item} />;
  90. })}
  91. </div>
  92. <div className="main-title">配套服务</div>
  93. <div className="list">
  94. <div className="other-item d-i-b">
  95. <Assets name="" />
  96. </div>
  97. <div className="other-item d-i-b">
  98. <Assets name="" />
  99. </div>
  100. </div>
  101. {hasGift && <div className="main-title">赠送服务</div>}
  102. {hasGift && <div className="list">
  103. {ServiceKey.map(row => {
  104. if (!data.gift[row.value]) return null;
  105. const list = ServiceParamMap[row.value];
  106. const map = getMap(list || [], 'value', 'label');
  107. return <div className="service-item d-i-b">
  108. <Assets name={serviceIconMap[row.value]} />
  109. <div className="t t-13 t-s-20 f-w-b">{row.label}</div>
  110. <div className="t-13">{list ? map[data.gift[row.value]] : data.gift[row.value]}</div>
  111. </div>;
  112. })}
  113. </div>}
  114. </div>
  115. <Contact data={base.contact} />
  116. <Footer />
  117. </div >
  118. );
  119. }
  120. }