1
0

page.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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, formatDate } from '@src/services/Tools';
  6. import Footer from '../../../components/Footer';
  7. import { Contact, AnswerCarousel, Comment } from '../../../components/Other';
  8. import { FaqModal, CommentModal, FinishModal } from '../../../components/OtherModal';
  9. import Tabs from '../../../components/Tabs';
  10. import Button from '../../../components/Button';
  11. import { User } from '../../../stores/user';
  12. import { Course } from '../../../stores/course';
  13. import { Order } from '../../../stores/order';
  14. import { Main } from '../../../stores/main';
  15. export default class extends Page {
  16. initState() {
  17. return {
  18. tab: '1',
  19. };
  20. }
  21. init() {
  22. Main.dataStruct().then(result => {
  23. const dataStructSelect = result.map(row => {
  24. return {
  25. title: `${row.titleZh}${row.titleEn}`,
  26. key: row.id,
  27. };
  28. });
  29. const dataStructMap = getMap(dataStructSelect, 'key');
  30. this.setState({ dataStructSelect, dataStructMap });
  31. });
  32. Main.getBase().then(result => {
  33. this.setState({ base: result });
  34. });
  35. }
  36. initData() {
  37. const { id } = this.params;
  38. Course.getData(id).then(result => {
  39. this.setState({ data: result });
  40. });
  41. this.view(id);
  42. Main.listFaq({ page: 1, size: 100, channel: 'course_data', position: id }).then(result => {
  43. this.faqs = result.list;
  44. this.setState({ faqs: result.list });
  45. });
  46. Main.listComment({ page: 1, size: 100, channel: 'course_data', position: id }).then(result => {
  47. this.comments = result.list;
  48. this.setState({ comments: result.list });
  49. });
  50. }
  51. onChangeTab(tab) {
  52. this.setState({ tab });
  53. }
  54. view(id) {
  55. Course.dataView(id);
  56. }
  57. buy() {
  58. const { data } = this.props;
  59. User.needLogin().then(() => {
  60. Order.speedPay({ productType: 'data', productId: data.id }).then(result => {
  61. User.needPay(result).then(() => {
  62. linkTo('/my/tools?tab=data');
  63. });
  64. });
  65. });
  66. }
  67. add() {
  68. const { data } = this.props;
  69. User.needLogin().then(() => {
  70. Order.addCheckout({ productType: 'data', productId: data.id }).then(() => {
  71. this.setState({ add: true });
  72. });
  73. });
  74. }
  75. renderView() {
  76. const { base = {}, data = {}, dataStructMap = {}, showComment, showFinish, comment = {}, showFaq, faq = {} } = this.state;
  77. return (
  78. <div>
  79. <div className="top content t-8">
  80. 千行课堂 > 全部资料 > {data.parentStructId > 0 ? `${(dataStructMap[data.parentStructId] || {}).title} >` : ''}{' '}
  81. {(dataStructMap[data.structId] || {}).title} > {data.title} > <span className="t-1">资料详情</span>
  82. </div>
  83. {this.renderDetail()}
  84. <Contact data={base.contact} />
  85. <Footer />
  86. <CommentModal
  87. show={showComment}
  88. defaultData={comment}
  89. onConfirm={() => this.setState({ showComment: false, comment: {}, showFinish: true })}
  90. onCancel={() => this.setState({ showComment: false, comment: {} })}
  91. onClose={() => this.setState({ showComment: false, comment: {} })}
  92. />
  93. <FaqModal show={showFaq} defaultData={faq} onCancel={() => this.setState({ showFaq: false, faq: {} })} onConfirm={() => this.setState({ showFaq: false, faq: {}, showFinish: true })} />
  94. <FinishModal
  95. show={showFinish}
  96. onConfirm={() => this.setState({ showFinish: false })}
  97. />
  98. </div>
  99. );
  100. }
  101. renderDetail() {
  102. const { tab, data = {}, add } = this.state;
  103. return [
  104. <div className="center">
  105. <div className="content">
  106. <div className="item-detail">
  107. <div className="left">
  108. <Assets name="" src={data.cover} />
  109. <div className="tag-list">
  110. {data.isNovice > 0 && <div className="tag">新手</div>}
  111. {data.isOriginal > 0 && <div className="tag">原创</div>}
  112. </div>
  113. </div>
  114. <div style={{ width: 760 }} className="right">
  115. <div className="t-1 t-s-20">{data.title}</div>
  116. <div className="t-7 m-b-2" dangerouslySetInnerHTML={{ __html: data.content }} />
  117. <div className="">
  118. <div className="d-i-b t-1">最近更新:</div>
  119. <div className="d-i-b t-8">{data.latestTime && formatDate(data.latestTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  120. </div>
  121. <div className="">
  122. <div className="d-i-b t-1">页数:</div>
  123. <div className="d-i-b t-8">{data.pages}页</div>
  124. </div>
  125. <div className="">
  126. <div className="d-i-b t-1">格式:</div>
  127. <div className="d-i-b t-8">{data.dataType === 'paper' ? '纸质' : 'PDF'}</div>
  128. </div>
  129. <div className="m-b-1">
  130. <div style={{ marginTop: 12 }} className="d-i-b t-1 t-s-16 v-a-t">
  131. 价格:
  132. </div>
  133. <div className="d-i-b t-7 t-s-28 f-w-b"> ¥ {data.price}</div>
  134. </div>
  135. <div className="action">
  136. {!data.have && (
  137. <Button
  138. className="m-r-1"
  139. radius
  140. size="lager"
  141. onClick={() => {
  142. if (data.dataType === 'paper') {
  143. openLink(data.link);
  144. } else {
  145. this.buy();
  146. }
  147. }}
  148. >
  149. 立即购买
  150. </Button>
  151. )}
  152. {!data.have && (
  153. <Button
  154. className="m-r-1"
  155. theme="default"
  156. disabled={data.add || add}
  157. radius
  158. size="lager"
  159. onClick={() => this.add()}
  160. >
  161. <Assets name="add" />
  162. </Button>
  163. )}
  164. {!data.have && (
  165. <Button theme="default" radius size="lager" onClick={() => openLink(data.resource)}>
  166. 预览
  167. </Button>
  168. )}
  169. {data.have && (
  170. <Button className="f-r" theme="default" radius size="lager" onClick={() => openLink(data.resource)}>
  171. 查看资料
  172. </Button>
  173. )}
  174. </div>
  175. {data.have && <Assets className="buyed" width={75} height={75} name="Purchased" />}
  176. </div>
  177. </div>
  178. </div>
  179. </div>,
  180. <div className="bottom">
  181. <div className="content">
  182. <Tabs
  183. type="full"
  184. border
  185. active={tab}
  186. tabs={[
  187. { title: '资料介绍', key: '1' },
  188. { title: '作者介绍', key: '2' },
  189. { title: '获取方式', key: '3' },
  190. { title: 'FAQs', key: '4' },
  191. { title: '学员评价', key: '5' },
  192. ]}
  193. onChange={key => this.onChangeTab(key)}
  194. />
  195. {this[`renderTab${tab}`]()}
  196. </div>
  197. </div>,
  198. ];
  199. }
  200. renderTab1() {
  201. const { data } = this.state;
  202. return (
  203. <div className="tab-layout">
  204. <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.content }} />
  205. </div>
  206. );
  207. }
  208. renderTab2() {
  209. const { data } = this.state;
  210. return (
  211. <div className="tab-layout">
  212. <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.authorContent }} />
  213. </div>
  214. );
  215. }
  216. renderTab3() {
  217. const { data } = this.state;
  218. return (
  219. <div className="tab-layout">
  220. <div className="tab-desc" dangerouslySetInnerHTML={{ __html: data.methodContent }} />
  221. </div>
  222. );
  223. }
  224. renderTab4() {
  225. const { faqs, data = {} } = this.state;
  226. return (
  227. <div className="tab-layout">
  228. <AnswerCarousel
  229. hideBtn
  230. list={faqs}
  231. onFaq={() => User.needLogin().then(() => this.setState({ showFaq: true, faq: { channel: 'course_data', position: data.id } }))}
  232. />
  233. </div>
  234. );
  235. }
  236. renderTab5() {
  237. const { data, comments } = this.state;
  238. return (
  239. <div className="tab-layout">
  240. {data.have && <div className="m-b-1 t-r">
  241. <Button width={100} radius onClick={() => User.needLogin().then(() => this.setState({ showComment: true, comment: { channel: 'course_data', position: data.id } }))}>
  242. 写评论
  243. </Button>
  244. </div>}
  245. {(comments || []).map(item => {
  246. return <Comment data={item} />;
  247. })}
  248. </div>
  249. );
  250. }
  251. }