1
0

page.js 10 KB

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