page.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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, formatTreeData } from '@src/services/Tools';
  6. import Footer from '../../../components/Footer';
  7. import { FaqModal } from '../../../components/OtherModal';
  8. import { CommentFalls, AnswerCarousel, Consultation, Contact } from '../../../components/Other';
  9. import Tabs from '../../../components/Tabs';
  10. import Filter from '../../../components/Filter';
  11. import { SingleItem, PackageItem } from '../../../components/Item';
  12. import { Main } from '../../../stores/main';
  13. import { Course } from '../../../stores/course';
  14. export default class extends Page {
  15. initState() {
  16. return {
  17. list: [],
  18. tab: 'single',
  19. };
  20. }
  21. init() {
  22. Main.getPromote()
  23. .then(result => {
  24. this.setState({ promote: result });
  25. });
  26. Main.getBase()
  27. .then(result => {
  28. this.setState({ base: result });
  29. });
  30. Main.courseStruct().then(result => {
  31. const courseStruct = result.map(row => {
  32. return {
  33. level: row.level,
  34. title: `${row.titleZh}${row.titleEn}`,
  35. key: `${row.id}`,
  36. parentId: row.parentId,
  37. isExamination: row.isExamination,
  38. };
  39. });
  40. const courseStructSelect = courseStruct.filter(row => row.level === 1);
  41. const packageStructSelect = courseStructSelect.filter(row => row.isExamination);
  42. courseStructSelect.unshift({
  43. title: '全部',
  44. key: '',
  45. });
  46. packageStructSelect.unshift({
  47. title: '全部',
  48. key: '',
  49. });
  50. const courseStructTree = formatTreeData(courseStruct, 'key', 'title', 'parentId');
  51. const courseStructTreeMap = getMap(courseStructTree, 'key', 'children');
  52. this.setState({ courseStructSelect, courseStructTreeMap, packageStructSelect });
  53. });
  54. }
  55. initData() {
  56. const data = Object.assign(this.state, this.state.search);
  57. if (data.order) {
  58. data.sortMap = { [data.order]: data.direction };
  59. }
  60. data.filterMap = this.state.search;
  61. this.setState(data);
  62. const { tab } = this.state;
  63. switch (tab) {
  64. case 'single':
  65. this.refreshSingle();
  66. break;
  67. case 'package':
  68. this.refreshPackage();
  69. break;
  70. default:
  71. break;
  72. }
  73. }
  74. refreshSingle() {
  75. Main.listFaq({ page: 1, size: 100, channel: 'course-video_index' }).then(result => {
  76. this.setState({ faqs: result.list });
  77. });
  78. Main.listComment({ page: 1, size: 100, channel: 'course-video_index' }).then(result => {
  79. this.setState({ coments: result.list });
  80. });
  81. Course.listVideo(Object.assign({ structId: this.state.search.parentStructId }, this.state.search))
  82. .then(result => {
  83. this.setState({ list: result.list, total: result.total });
  84. });
  85. }
  86. refreshPackage() {
  87. Main.listFaq({ page: 1, size: 100, channel: 'course-package_index' }).then(result => {
  88. this.setState({ faqs: result.list });
  89. });
  90. Main.listComment({ page: 1, size: 100, channel: 'course-package_index' }).then(result => {
  91. this.setState({ coments: result.list });
  92. });
  93. Course.listPackage(Object.assign({}, this.state.search))
  94. .then(result => {
  95. this.setState({ list: result.list, total: result.total });
  96. });
  97. }
  98. onTabChange(tab) {
  99. const data = { tab };
  100. this.refreshQuery(data);
  101. }
  102. onFilter(key, value) {
  103. const { filterMap } = this.state;
  104. filterMap[key] = value;
  105. this.search(filterMap);
  106. }
  107. onChangePage(page) {
  108. this.search({ page }, false);
  109. this.initData();
  110. }
  111. renderView() {
  112. const { number } = this.props.order;
  113. const { tab, promote = {}, base = {}, comments, faqs, showFaq, faq } = this.state;
  114. return (
  115. <div>
  116. <div className="top content">
  117. <Tabs type="text" active={'online'} tabs={[{ title: '在线课程', key: 'online', path: '/course/online' }, { title: '1v1私教', key: 'vs', path: '/course/vs' }]} />
  118. <div className="f-r">
  119. <span className="t-2 m-r-1">{(promote.video || {}).text ? `优惠活动:${promote.video.text}` : ''}</span>
  120. <Assets name="cart" onClick={() => linkTo('cart')} />
  121. <span className="t-2">( {number || 0} )</span>
  122. </div>
  123. </div>
  124. <div className="center">
  125. <div className="content">
  126. <Tabs
  127. type="division"
  128. theme="theme"
  129. size="small"
  130. space={2.5}
  131. width={100}
  132. border
  133. active={tab}
  134. tabs={[{ title: '单项购买', key: 'single' }, { title: '套餐购买', key: 'package' }]}
  135. onChange={key => this.onTabChange(key)}
  136. />
  137. {this[`renderTab${tab}`]()}
  138. </div>
  139. </div>
  140. <Consultation data={base.contact} />
  141. <CommentFalls list={comments} />
  142. <AnswerCarousel list={faqs} onFaq={() => this.setState({ showFaq: true, faq: { channel: tab === 'single' ? 'course-video_index' : 'course-package_index' } })} />
  143. <Contact data={base.contact} />
  144. <Footer />
  145. <FaqModal show={showFaq} defaultData={faq} onCancel={() => this.setState({ showFaq: false })} onConfirm={() => this.setState({ showFaq: false })} />
  146. </div>
  147. );
  148. }
  149. renderTabsingle() {
  150. const { filterMap, list = [], courseStructSelect, courseStructTreeMap = {} } = this.state;
  151. const child = (courseStructTreeMap[filterMap.parentStructId] || []).map(row => {
  152. return {
  153. title: row.title,
  154. key: row.key,
  155. };
  156. });
  157. child.unshift({
  158. title: '全部',
  159. key: '',
  160. });
  161. return [
  162. <Filter
  163. filter={filterMap}
  164. list={[
  165. {
  166. key: 'parentStructId',
  167. children: courseStructSelect,
  168. },
  169. {
  170. key: 'structId',
  171. children: child,
  172. },
  173. ]}
  174. onFilter={(key, value) => this.onFilter(key, value)}
  175. />,
  176. <div className="tab-1-list">
  177. {list.map((data) => {
  178. return <SingleItem data={data} />;
  179. })}
  180. </div>,
  181. ];
  182. }
  183. renderTabpackage() {
  184. const { filterMap, list = [], packageStructSelect } = this.state;
  185. return [
  186. <Filter
  187. filter={filterMap}
  188. list={[
  189. {
  190. key: 'structId',
  191. children: packageStructSelect,
  192. },
  193. ]}
  194. onFilter={(key, value) => this.onFilter(key, value)}
  195. />,
  196. <div className="tab-2-list">
  197. {list.map((data) => {
  198. return <PackageItem data={data} />;
  199. })}
  200. </div>,
  201. ];
  202. }
  203. }