page.js 7.0 KB

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