page.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. import React from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { formatMoney } from '@src/services/Tools';
  7. import Footer from '../../../components/Footer';
  8. import { FaqModal, CommentModal, FinishModal } from '../../../components/OtherModal';
  9. import { Contact, Comment, Consultation, AnswerCarousel } from '../../../components/Other';
  10. import Tabs from '../../../components/Tabs';
  11. import Button from '../../../components/Button';
  12. import { Main } from '../../../stores/main';
  13. import { Order } from '../../../stores/order';
  14. import { User } from '../../../stores/user';
  15. import { Course } from '../../../stores/course';
  16. import { CourseVsType } from '../../../../Constant';
  17. export default class extends Page {
  18. initState() {
  19. return {
  20. info: '1',
  21. number: 0,
  22. };
  23. }
  24. init() {
  25. this.courseVsMap = {};
  26. this.faqMap = {};
  27. this.faqs = null;
  28. this.commentMap = {};
  29. this.comments = null;
  30. this.promote = [];
  31. this.teacherMap = {};
  32. Main.getPromote().then(result => {
  33. this.promote = result.vs_list || [];
  34. this.setState({ promote: result });
  35. });
  36. Main.getBase().then(result => {
  37. this.setState({ base: result });
  38. });
  39. }
  40. initData() {
  41. Course.allVs().then(result => {
  42. result.forEach(row => {
  43. this.courseVsMap[row.vsType] = row;
  44. });
  45. this.onChangeItem(CourseVsType[0].value);
  46. });
  47. }
  48. onChangeTab(info) {
  49. this.setState({ info });
  50. }
  51. onChangeItem(key) {
  52. const item = this.courseVsMap[key];
  53. if (!this.faqs) {
  54. Main.listFaq({ page: 1, size: 100, channel: 'course-vs_index' }).then(result => {
  55. this.faqs = result.list;
  56. this.setState({ faqs: result.list });
  57. });
  58. }
  59. if (!this.commentMap[key]) {
  60. Main.listComment({ page: 1, size: 100, channel: 'course-vs', position: item.id }).then(result => {
  61. this.commentMap[key] = result.list;
  62. this.setState({ comments: result.list });
  63. });
  64. }
  65. if (!this.teacherMap[key]) {
  66. Course.allTeacher(item.id).then(result => {
  67. this.teacherMap[key] = result;
  68. this.setState({ teachers: result });
  69. });
  70. }
  71. this.setState({ key, data: item, faqs: this.faqs, comments: this.commentMap[key], teachers: this.teacherMap[key] });
  72. this.changeNumber(item, item.minNumber || 1);
  73. }
  74. changeNumber(data, number) {
  75. let price = data.price * number;
  76. const days = data.expirePreDays / 10 * number;
  77. let max = 0;
  78. let maxIndex = -1;
  79. this.promote.forEach((row, i) => {
  80. if (row.number <= number) {
  81. if (row.number > max) {
  82. max = number;
  83. maxIndex = i;
  84. }
  85. }
  86. });
  87. if (maxIndex >= 0) {
  88. price *= this.promote[maxIndex].percent / 100;
  89. }
  90. this.setState({ number, price, days });
  91. }
  92. buy() {
  93. const { data, number } = this.state;
  94. User.needLogin().then(() => {
  95. Order.speedPay({ productType: 'course', productId: data.id, number }).then(result => {
  96. User.needPay(result).then(() => {
  97. linkTo('/my/course');
  98. });
  99. });
  100. });
  101. }
  102. add() {
  103. const { data, number } = this.state;
  104. User.needLogin().then(() => {
  105. Order.addCheckout({ productType: 'course', productId: data.id, number }).then(() => {
  106. this.setState({ add: true });
  107. });
  108. });
  109. }
  110. renderView() {
  111. const { number } = this.props.order;
  112. const { promote = {}, base = {}, showComment, comment = {}, showFaq, faq = {}, showFinish } = this.state;
  113. return (
  114. <div>
  115. <div className="top content">
  116. <Tabs
  117. type="text"
  118. active={'vs'}
  119. tabs={[
  120. { title: '在线课程', key: 'online', path: '/course/online' },
  121. { title: '1v1私教', key: 'vs', path: '/course/vs' },
  122. ]}
  123. />
  124. <div className="f-r">
  125. <span className="t-2 m-r-1">{(promote.vs || {}).text ? `优惠活动:${promote.vs.text}` : ''}</span>
  126. <Assets name="cart" onClick={() => linkTo('/cart')} />
  127. <span className="t-2">( {number || 0} )</span>
  128. </div>
  129. </div>
  130. {this.renderDetail()}
  131. <Contact data={base.contact} />
  132. <Footer />
  133. <CommentModal
  134. show={showComment}
  135. defaultData={comment}
  136. onConfirm={() => this.setState({ showComment: false, comment: {}, showFinish: true })}
  137. onCancel={() => this.setState({ showComment: false, comment: {} })}
  138. onClose={() => this.setState({ showComment: false, comment: {} })}
  139. />
  140. <FaqModal show={showFaq} defaultData={faq} onCancel={() => this.setState({ showFaq: false, faq: {} })} onConfirm={() => this.setState({ showFaq: false, faq: {}, showFinish: true })} />
  141. <FinishModal
  142. show={showFinish}
  143. onConfirm={() => this.setState({ showFinish: false })}
  144. />
  145. </div>
  146. );
  147. }
  148. renderDetail() {
  149. const { info, key, data, number, price, days } = this.state;
  150. return [
  151. <div className="center">
  152. <div className="content">
  153. <Assets className="m-b-2" width={1140} name="s" />
  154. <div className="item-list">
  155. {CourseVsType.map(t => {
  156. const course = this.courseVsMap[t.value] || {};
  157. return (
  158. <div className={`item ${key === t.value ? 'active' : ''}`} onClick={() => this.onChangeItem(t.value)}>
  159. <Assets name={t.icon} />
  160. <div className="t-1 t-s-20 f-w-b">{course.title}</div>
  161. <div className="t-2">{course.comment}</div>
  162. </div>
  163. );
  164. })}
  165. </div>
  166. <div className="item-detail">
  167. <div className="left">
  168. <div className="img c-p" style={{ backgroundImage: `url(${data.cover})`, backgroundSize: '100% 100%', width: '100%', height: '100%' }} />
  169. </div>
  170. <div className="right">
  171. <div className="t-1 t-s-16 m-b-2" dangerouslySetInnerHTML={{ __html: data.serviceContent }} />
  172. <div className="m-b-5">
  173. <div style={{ width: 120 }} className="d-i-b t-2">
  174. 适合人群
  175. </div>
  176. <div className="d-i-b t-1" dangerouslySetInnerHTML={{ __html: data.crowdContent }} />
  177. </div>
  178. <div className="m-b-5">
  179. <div style={{ width: 120 }} className="d-i-b t-2">
  180. 课时数
  181. </div>
  182. <div className="d-i-b t-1" dangerouslySetInnerHTML={{ __html: data.courseNoContent }} />
  183. </div>
  184. <div className="m-b-5">
  185. <div style={{ width: 120 }} className="d-i-b t-2">
  186. 授课流程
  187. </div>
  188. <div className="d-i-b t-1" dangerouslySetInnerHTML={{ __html: data.processContent }} />
  189. </div>
  190. <div className="m-b-5">
  191. <div style={{ width: 120 }} className="d-i-b t-2">
  192. 课程有效期
  193. </div>
  194. <div className="d-i-b t-1">{days}天</div>
  195. </div>
  196. <div className="m-b-5 input">
  197. <div style={{ width: 120 }} className="d-i-b t-2">
  198. 购买课时
  199. </div>
  200. <div className="d-i-b t-1">
  201. <input value={number} style={{ width: 32 }} className="m-l-5 t-c" />
  202. <Icon
  203. className="up"
  204. type="caret-up"
  205. onClick={() => number < data.maxNumber && this.changeNumber(data, number + 1)}
  206. />
  207. <Icon
  208. className="down"
  209. type="caret-down"
  210. onClick={() => number !== 1 && number > data.minNumber && this.changeNumber(data, number - 1)}
  211. />
  212. </div>
  213. </div>
  214. <div className="m-b-5">
  215. <div style={{ width: 120 }} className="d-i-b t-2">
  216. 课程总价
  217. </div>
  218. <div className="d-i-b t-7 t-s-20 f-w-b"> ¥ {formatMoney(price)}</div>
  219. </div>
  220. <div className="action">
  221. {data.have && <Button className="m-r-1" radius size="lager" onClick={() => linkTo('/my/course')}>
  222. 我的课程
  223. </Button>}
  224. {!data.have && <Button className="m-r-1" radius size="lager" onClick={() => this.buy()}>
  225. 立即购买
  226. </Button>}
  227. {!data.have && <Button theme="default" disabled={this.state.add || data.add} radius size="lager" onClick={() => this.add()}>
  228. <Assets name={data.add || this.state.add ? 'add_disabled' : 'add'} />
  229. </Button>}
  230. </div>
  231. </div>
  232. </div>
  233. </div>
  234. </div >,
  235. <div className="bottom">
  236. <div className="content">
  237. <Tabs
  238. type="full"
  239. border
  240. active={info}
  241. tabs={[
  242. { title: '老师资料', key: '1' },
  243. { title: '咨询方式', key: '2' },
  244. { title: 'FAQs', key: '3' },
  245. { title: '学员评价', key: '4' },
  246. ]}
  247. onChange={tab => this.onChangeTab(tab)}
  248. />
  249. {this[`renderTab${info}`]()}
  250. </div>
  251. </div>,
  252. ];
  253. }
  254. renderTab1() {
  255. const { teachers = [] } = this.state;
  256. const [teacher] = teachers;
  257. if (!teacher) return null;
  258. return (
  259. <div className="tab-layout">
  260. <div className="teach-item">
  261. <div className="left t-c">
  262. <Assets className="m-b-1" src={teacher.avatar} />
  263. <div className="t-1 t-s-20">{teacher.realname}</div>
  264. </div>
  265. <div className="right t-1 t-s-16 ws-p">{teacher.description}</div>
  266. </div>
  267. </div>
  268. );
  269. }
  270. renderTab2() {
  271. const { base } = this.state;
  272. return (
  273. <div className="tab-layout">
  274. <Consultation data={base.contact} />
  275. </div>
  276. );
  277. }
  278. renderTab3() {
  279. const { faqs, data = {} } = this.state;
  280. return (
  281. <div className="tab-layout">
  282. <AnswerCarousel
  283. hideBtn
  284. list={faqs || []}
  285. onFaq={() => User.needLogin().then(() => this.setState({ showFaq: true, faq: { channel: 'course-vs', position: data.id } }))}
  286. />
  287. </div>
  288. );
  289. }
  290. renderTab4() {
  291. const { data, comments } = this.state;
  292. return (
  293. <div className="tab-layout">
  294. {data.have && <div className="m-b-1 t-r">
  295. <Button width={100} radius onClick={() => User.needLogin().then(() => this.setState({ showComment: true, comment: { channel: 'course-vs', position: data.id } }))}>
  296. 写评论
  297. </Button>
  298. </div>}
  299. {(comments || []).map(item => {
  300. return <Comment data={item} />;
  301. })}
  302. </div>
  303. );
  304. }
  305. }