page.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.minNumber || 1);
  73. }
  74. changeNumber(number) {
  75. const { data } = this.state;
  76. let price = data.price * number;
  77. const days = data.expirePreDays / 10 * number;
  78. let max = 0;
  79. let maxIndex = -1;
  80. this.promote.forEach((row, i) => {
  81. if (row.number <= number) {
  82. if (row.number > max) {
  83. max = number;
  84. maxIndex = i;
  85. }
  86. }
  87. });
  88. if (maxIndex >= 0) {
  89. price *= this.promote[maxIndex].percent / 100;
  90. }
  91. this.setState({ number, price, days });
  92. }
  93. buy() {
  94. const { data, number } = this.state;
  95. User.needLogin().then(() => {
  96. Order.speedPay({ productType: 'course', productId: data.id, number }).then(result => {
  97. User.needPay(result).then(() => {
  98. linkTo('/my/course');
  99. });
  100. });
  101. });
  102. }
  103. add() {
  104. const { data, number } = this.state;
  105. User.needLogin().then(() => {
  106. Order.addCheckout({ productType: 'course', productId: data.id, number }).then(() => {
  107. this.setState({ add: true });
  108. });
  109. });
  110. }
  111. renderView() {
  112. const { number } = this.props.order;
  113. const { promote = {}, base = {}, showComment, comment = {}, showFaq, faq = {}, showFinish } = this.state;
  114. return (
  115. <div>
  116. <div className="top content">
  117. <Tabs
  118. type="text"
  119. active={'vs'}
  120. tabs={[
  121. { title: '在线课程', key: 'online', path: '/course/online' },
  122. { title: '1v1私教', key: 'vs', path: '/course/vs' },
  123. ]}
  124. />
  125. <div className="f-r">
  126. <span className="t-2 m-r-1">{(promote.vs || {}).text ? `优惠活动:${promote.vs.text}` : ''}</span>
  127. <Assets name="cart" onClick={() => linkTo('/cart')} />
  128. <span className="t-2">( {number || 0} )</span>
  129. </div>
  130. </div>
  131. {this.renderDetail()}
  132. <Contact data={base.contact} />
  133. <Footer />
  134. <CommentModal
  135. show={showComment}
  136. defaultData={comment}
  137. onConfirm={() => this.setState({ showComment: false, comment: {}, showFinish: true })}
  138. onCancel={() => this.setState({ showComment: false, comment: {} })}
  139. onClose={() => this.setState({ showComment: false, comment: {} })}
  140. />
  141. <FaqModal show={showFaq} defaultData={faq} onCancel={() => this.setState({ showFaq: false, faq: {} })} onConfirm={() => this.setState({ showFaq: false, faq: {}, showFinish: true })} />
  142. <FinishModal
  143. show={showFinish}
  144. onConfirm={() => this.setState({ showFinish: false })}
  145. />
  146. </div>
  147. );
  148. }
  149. renderDetail() {
  150. const { info, key, data, number, price, days } = this.state;
  151. return [
  152. <div className="center">
  153. <div className="content">
  154. <Assets className="m-b-2" width={1140} name="s" />
  155. <div className="item-list">
  156. {CourseVsType.map(t => {
  157. const course = this.courseVsMap[t.value] || {};
  158. return (
  159. <div className={`item ${key === t.value ? 'active' : ''}`} onClick={() => this.onChangeItem(t.value)}>
  160. <Assets name={t.icon} />
  161. <div className="t-1 t-s-20 f-w-b">{course.title}</div>
  162. <div className="t-2">{course.comment}</div>
  163. </div>
  164. );
  165. })}
  166. </div>
  167. <div className="item-detail">
  168. <div className="left">
  169. <div className="img c-p" style={{ backgroundImage: `url(${data.cover})`, backgroundSize: '100% 100%', width: '100%', height: '100%' }} />
  170. </div>
  171. <div className="right">
  172. <div className="t-1 t-s-16 m-b-2" dangerouslySetInnerHTML={{ __html: data.serviceContent }} />
  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.crowdContent }} />
  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.courseNoContent }} />
  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" dangerouslySetInnerHTML={{ __html: data.processContent }} />
  190. </div>
  191. <div className="m-b-5">
  192. <div style={{ width: 120 }} className="d-i-b t-2">
  193. 课程有效期
  194. </div>
  195. <div className="d-i-b t-1">{days}天</div>
  196. </div>
  197. <div className="m-b-5 input">
  198. <div style={{ width: 120 }} className="d-i-b t-2">
  199. 购买课时
  200. </div>
  201. <div className="d-i-b t-1">
  202. <input value={number} style={{ width: 32 }} className="m-l-5 t-c" />
  203. <Icon
  204. className="up"
  205. type="caret-up"
  206. onClick={() => number < data.maxNumber && this.changeNumber(number + 1)}
  207. />
  208. <Icon
  209. className="down"
  210. type="caret-down"
  211. onClick={() => number !== 1 && number > data.minNumber && this.changeNumber(number - 1)}
  212. />
  213. </div>
  214. </div>
  215. <div className="m-b-5">
  216. <div style={{ width: 120 }} className="d-i-b t-2">
  217. 课程总价
  218. </div>
  219. <div className="d-i-b t-7 t-s-20 f-w-b"> ¥ {formatMoney(price)}</div>
  220. </div>
  221. <div className="action">
  222. {data.have && <Button className="m-r-1" radius size="lager" onClick={() => linkTo('/my/course')}>
  223. 我的课程
  224. </Button>}
  225. {!data.have && <Button className="m-r-1" radius size="lager" onClick={() => this.buy()}>
  226. 立即购买
  227. </Button>}
  228. {!data.have && <Button theme="default" disabled={this.state.add || data.add} radius size="lager" onClick={() => this.add()}>
  229. <Assets name={data.add || this.state.add ? 'add_disabled' : 'add'} />
  230. </Button>}
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. </div >,
  236. <div className="bottom">
  237. <div className="content">
  238. <Tabs
  239. type="full"
  240. border
  241. active={info}
  242. tabs={[
  243. { title: '老师资料', key: '1' },
  244. { title: '咨询方式', key: '2' },
  245. { title: 'FAQs', key: '3' },
  246. { title: '学员评价', key: '4' },
  247. ]}
  248. onChange={tab => this.onChangeTab(tab)}
  249. />
  250. {this[`renderTab${info}`]()}
  251. </div>
  252. </div>,
  253. ];
  254. }
  255. renderTab1() {
  256. const { teachers = [] } = this.state;
  257. const [teacher] = teachers;
  258. if (!teacher) return null;
  259. return (
  260. <div className="tab-layout">
  261. <div className="teach-item">
  262. <div className="left t-c">
  263. <Assets className="m-b-1" src={teacher.avatar} />
  264. <div className="t-1 t-s-20">{teacher.realname}</div>
  265. </div>
  266. <div className="right t-1 t-s-16 ws-p">{teacher.description}</div>
  267. </div>
  268. </div>
  269. );
  270. }
  271. renderTab2() {
  272. const { base } = this.state;
  273. return (
  274. <div className="tab-layout">
  275. <Consultation data={base.contact} />
  276. </div>
  277. );
  278. }
  279. renderTab3() {
  280. const { faqs, data = {} } = this.state;
  281. return (
  282. <div className="tab-layout">
  283. <AnswerCarousel
  284. hideBtn
  285. list={faqs || []}
  286. onFaq={() => User.needLogin().then(() => this.setState({ showFaq: true, faq: { channel: 'course-vs', position: data.id } }))}
  287. />
  288. </div>
  289. );
  290. }
  291. renderTab4() {
  292. const { data, comments } = this.state;
  293. return (
  294. <div className="tab-layout">
  295. {data.have && <div className="m-b-1 t-r">
  296. <Button width={100} radius onClick={() => User.needLogin().then(() => this.setState({ showComment: true, comment: { channel: 'course-vs', position: data.id } }))}>
  297. 写评论
  298. </Button>
  299. </div>}
  300. {(comments || []).map(item => {
  301. return <Comment data={item} />;
  302. })}
  303. </div>
  304. );
  305. }
  306. }