page.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { formatDate, formatMonth, getMap, formatPercent } from '@src/services/Tools';
  5. import Ratio from '../../../components/Ratio';
  6. import UserAction from '../../../components/UserAction';
  7. import UserPagination from '../../../components/UserPagination';
  8. import { ExperienceScore, ExperienceDay, PrepareStatus, ExperiencePercent } from '../../../../Constant';
  9. import { Main } from '../../../stores/main';
  10. import { My } from '../../../stores/my';
  11. import { Course } from '../../../stores/course';
  12. const PrepareStatusMap = getMap(PrepareStatus, 'value', 'label');
  13. const ExperiencePercentMap = getMap(ExperiencePercent, 'value', 'label');
  14. const colorList = ['#2754E0', '#3F86EA', '#41A6F3', '#9BD4FF'];
  15. export default class extends Page {
  16. initState() {
  17. const prepareStatusSelect = PrepareStatus.map(row => {
  18. return {
  19. title: row.label,
  20. key: row.value,
  21. };
  22. });
  23. prepareStatusSelect.unshift({
  24. title: '全部',
  25. key: '',
  26. });
  27. const experienceDaySelect = ExperienceDay.map(row => {
  28. return {
  29. title: row.label,
  30. key: row.value,
  31. };
  32. });
  33. experienceDaySelect.unshift({
  34. title: '全部',
  35. key: '',
  36. });
  37. const experienceScoreSelect = ExperienceScore.map(row => {
  38. return {
  39. title: row.label,
  40. key: row.value,
  41. };
  42. });
  43. experienceScoreSelect.unshift({
  44. title: '全部',
  45. key: '',
  46. });
  47. const experiencePercentSelect = ExperiencePercent.map(row => {
  48. return {
  49. title: row.label,
  50. key: row.value,
  51. };
  52. });
  53. experiencePercentSelect.unshift({
  54. title: '全部',
  55. key: '',
  56. });
  57. return {
  58. prepareStatusSelect,
  59. experienceDaySelect,
  60. experienceScoreSelect,
  61. experiencePercentSelect,
  62. };
  63. }
  64. init() {
  65. Main.getExperience()
  66. .then(result => {
  67. const totalScoreNumber = result.score.reduce((x, y) => x + y, 0);
  68. const totalPercentNumber = result.percent.reduce((x, y) => x + y, 0);
  69. const scoreList = ExperienceScore.map((row, index) => {
  70. const percent = formatPercent(result.score[index] || 0, totalScoreNumber);
  71. return {
  72. color: colorList[index],
  73. label: `${row.label} ${percent} ${result.score[index] || 0}人`,
  74. value: percent,
  75. };
  76. });
  77. const percentList = ExperiencePercent.map((row, index) => {
  78. const percent = formatPercent(result.percent[index] || 0, totalPercentNumber);
  79. return {
  80. color: colorList[index],
  81. label: `${row.label} ${percent} ${result.percent[index] || 0}人`,
  82. value: percent,
  83. };
  84. });
  85. this.setState({ data: result, scoreList, percentList });
  86. });
  87. }
  88. initData() {
  89. const data = Object.assign(this.state, this.state.search);
  90. if (data.order) {
  91. data.sortMap = { [data.order]: data.direction };
  92. }
  93. data.filterMap = this.state.search;
  94. this.setState(data);
  95. Course.listExperience(Object.assign({}, this.state.search))
  96. .then(result => {
  97. this.setState({ list: result.list, total: result.total });
  98. });
  99. }
  100. onFilter(value) {
  101. this.search(value, false);
  102. this.initData();
  103. }
  104. onChangePage(page) {
  105. this.search({ page }, false);
  106. this.initData();
  107. }
  108. renderView() {
  109. return (
  110. <div>
  111. <div className="top content t-8">
  112. 千行课堂 > <span className="t-1">学员表现</span>
  113. </div>
  114. {this.renderDetail()}
  115. </div>
  116. );
  117. }
  118. renderDetail() {
  119. const { filterMap, list, data = {}, scoreList, percentList, total, page } = this.state;
  120. const { prepareStatusSelect, experienceDaySelect, experienceScoreSelect, experiencePercentSelect } = this.state;
  121. return [
  122. <div className="center">
  123. <div className="content">
  124. <div className="total-list">
  125. <div className="total-item">
  126. <div className="title">学员人数</div>
  127. <div className="label">{data.number || 0}</div>
  128. </div>
  129. <div className="total-item">
  130. <div className="title">考分分布</div>
  131. <Ratio
  132. size="small"
  133. values={scoreList || []}
  134. />
  135. </div>
  136. <div className="total-item">
  137. <div className="title">出分周期</div>
  138. <div className="label">{data.period || 0}天</div>
  139. </div>
  140. <div className="total-item">
  141. <div className="title">提分比例</div>
  142. <Ratio
  143. size="small"
  144. values={percentList || []}
  145. />
  146. </div>
  147. </div>
  148. <UserAction
  149. selectList={[
  150. {
  151. key: 'prepareStatus',
  152. placeholder: '身份',
  153. select: prepareStatusSelect,
  154. },
  155. {
  156. key: 'experienceDay',
  157. placeholder: '备考周期',
  158. select: experienceDaySelect,
  159. },
  160. {
  161. key: 'experienceScore',
  162. placeholder: '分手成绩',
  163. select: experienceScoreSelect,
  164. },
  165. {
  166. key: 'experiencePercent',
  167. placeholder: '提分幅度',
  168. select: experiencePercentSelect,
  169. },
  170. ]}
  171. filterMap={filterMap}
  172. onFilter={value => this.onFilter(value)}
  173. />
  174. {list.map(item => {
  175. return <Article data={item} />;
  176. })}
  177. {total > 0 && list.length > 0 && (
  178. <UserPagination total={total} current={page} pageSize={this.state.search.size} onChange={p => this.onChangePage(p)} />
  179. )}
  180. </div>
  181. </div>,
  182. ];
  183. }
  184. }
  185. class Article extends Component {
  186. constructor(props) {
  187. super(props);
  188. this.state = {};
  189. }
  190. onCollect() {
  191. const { data } = this.props;
  192. const { collect } = this.state;
  193. let collectStatus = false;
  194. if (collect !== undefined) {
  195. collectStatus = collect;
  196. } else {
  197. collectStatus = data.collect;
  198. }
  199. if (!collectStatus) {
  200. My.addExperienceCollect(data.id)
  201. .then(() => {
  202. this.setState({ collect: true });
  203. });
  204. } else {
  205. My.delExperienceCollect(data.id)
  206. .then(() => {
  207. this.setState({ collect: false });
  208. });
  209. }
  210. }
  211. render() {
  212. const { data } = this.props;
  213. const { collect } = this.state;
  214. let collectStatus = false;
  215. if (collect !== undefined) {
  216. collectStatus = collect;
  217. } else {
  218. collectStatus = data.collect;
  219. }
  220. return (
  221. <div className="article-item p-t-2 b-b" onClick={() => linkTo(`/course/experience/detail/${data.id}`)}>
  222. <div className="t-1 t-s-14 f-w-b">
  223. {data.title}
  224. <div className="f-r t-3 t-s-12 f-w-d">
  225. <span>{data.updateTime && formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')}</span>
  226. <span className="m-l-2">阅读 {data.viewNumber}</span>
  227. <span className="m-l-2 c-p" onClick={(e) => {
  228. e.stopPropagation();
  229. this.onCollect();
  230. }}>
  231. {collectStatus ? '收藏' : '取消收藏'}
  232. </span>
  233. </div>
  234. </div>
  235. <div className="t-1 t-s-12 m-b-2">
  236. <span className="m-r-2">{data.user ? data.user.nickname : data.nickname}</span>
  237. <span className="m-r-2">{PrepareStatusMap[data.prepareStatus]}</span>
  238. <span className="m-r-2">备考:{!!data.experienceDay && formatMonth(data.experienceDay, false)}</span>
  239. <span className="m-r-2">
  240. {data.experienceScore}分 /提分 {ExperiencePercentMap[data.experiencePercent]}
  241. </span>
  242. </div>
  243. <div className="t-2 m-b-2 detail">{data.description}</div>
  244. </div>
  245. );
  246. }
  247. }