1
0

page.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { formatDate, getMap } from '@src/services/Tools';
  5. import UserAction from '../../../components/UserAction';
  6. import UserPagination from '../../../components/UserPagination';
  7. import Tabs from '../../../components/Tabs';
  8. import { OpenText } from '../../../components/Open';
  9. import { Button } from '../../../components/Button';
  10. import { Course } from '../../../stores/course';
  11. import { My } from '../../../stores/my';
  12. export default class extends Page {
  13. constructor(props) {
  14. props.size = 10;
  15. super(props);
  16. }
  17. initState() {
  18. return {
  19. filterMap: {},
  20. list: [],
  21. tab: 'special',
  22. answerSelect: [{ title: '全部', key: '' }, { title: '已回答', key: '1' }, { title: '未回答', key: '0' }],
  23. };
  24. }
  25. init() {
  26. const { id } = this.params;
  27. Course.get(id).then(result => {
  28. const courseNoSelect = result.courseNos.map(row => {
  29. return {
  30. title: row.title,
  31. key: `${row.id}`,
  32. };
  33. });
  34. courseNoSelect.unshift({
  35. title: '全部课时',
  36. key: '',
  37. });
  38. const courseNoMap = getMap(result.courseNos, 'id');
  39. const timelineSelect = [{ title: '全部区间', value: '' }];
  40. const max = Math.max(result.courseNos.map(row => row.time));
  41. let start = 0;
  42. let end = start + 5;
  43. while (start < max) {
  44. timelineSelect.push({
  45. title: `${start}:00~${end}:00`,
  46. key: `${start}`,
  47. });
  48. start += 5;
  49. end = Math.min(start + 5, max);
  50. }
  51. this.setState({ course: result, courseNoMap, courseNoSelect, timelineSelect });
  52. });
  53. }
  54. initData() {
  55. const data = Object.assign(this.state, this.state.search);
  56. if (data.order) {
  57. data.sortMap = { [data.order]: data.direction };
  58. }
  59. data.filterMap = this.state.search;
  60. this.setState(data);
  61. const { tab } = this.state;
  62. switch (tab) {
  63. case 'special':
  64. this.refreshSpecial();
  65. break;
  66. case 'my':
  67. this.refreshMy();
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. refreshSpecial() {
  74. const { id } = this.params;
  75. this.setState({
  76. orderSelect: [
  77. { title: '无', key: '' },
  78. { title: '时间轴', key: 'position' },
  79. { title: '更新时间', key: 'updateTime' },
  80. { title: '查看次数', key: 'viewNumber' },
  81. ],
  82. });
  83. // paixu
  84. Course.listAsk(Object.assign({ courseId: id }, this.state.search)).then(result => {
  85. // 只显示单个提问
  86. if (this.state.search.askId) {
  87. const askId = Number(this.state.search.askId);
  88. result.list = result.list.filter(row => row.id === askId);
  89. }
  90. this.setState({ list: result.list, total: result.total });
  91. });
  92. }
  93. refreshMy() {
  94. const { id } = this.params;
  95. this.setState({
  96. orderSelect: [
  97. { title: '无', key: '' },
  98. { title: '时间轴', key: 'position' },
  99. { title: '更新时间', key: 'updateTime' },
  100. ],
  101. });
  102. My.listCourseAsk(Object.assign({ courseId: id }, this.state.search)).then(result => {
  103. this.setState({ list: result.list, total: result.total });
  104. });
  105. }
  106. onTabChange(tab) {
  107. const data = { tab };
  108. this.refreshQuery(data);
  109. }
  110. onFilter(value) {
  111. this.search(value, false);
  112. this.initData();
  113. }
  114. onSearch(value) {
  115. this.search({ keyword: value }, false);
  116. this.initData();
  117. }
  118. onAction() { }
  119. delAsk(id) {
  120. My.delCourseAsk(id).then(() => {
  121. this.refresh();
  122. });
  123. }
  124. viewAsk(id) {
  125. Course.askView(id);
  126. }
  127. renderView() {
  128. const { course = {}, courseNoMap = {} } = this.state;
  129. const { tab, courseNoSelect, answerSelect, timelineSelect, orderSelect, filterMap = {}, list = [] } = this.state;
  130. const { total, page } = this.state;
  131. const selectActionList = [
  132. {
  133. key: 'courseNoId',
  134. placeholder: '全部课时',
  135. select: courseNoSelect,
  136. },
  137. ];
  138. selectActionList.push({
  139. key: 'order',
  140. placeholder: '排序',
  141. select: orderSelect,
  142. });
  143. if (filterMap.order === 'position') {
  144. selectActionList.push({
  145. key: 'position',
  146. placeholder: '时间区间',
  147. select: timelineSelect,
  148. });
  149. }
  150. if (tab === 'my') {
  151. selectActionList.push({
  152. key: 'answerStatus',
  153. placeholder: '状态',
  154. select: answerSelect,
  155. });
  156. }
  157. return (
  158. <div>
  159. <div className="top content t-8">
  160. 千行课堂 > 全部课程 > {course.title} > <span className="t-1">全部问答</span>
  161. <div className="f-r" onClick={() => linkTo(`/course/detail/${course.id}`)}>
  162. 返回课程
  163. </div>
  164. </div>
  165. <div className="center content">
  166. <div className="t-1 t-s-20 m-b-2">{course.title}</div>
  167. <Tabs
  168. border
  169. type="division"
  170. theme="theme"
  171. size="small"
  172. space={2.5}
  173. width={100}
  174. active={tab}
  175. tabs={[{ key: 'special', title: '精选问答' }, { key: 'my', title: '我的提问' }]}
  176. onChange={key => this.onTabChange(key)}
  177. />
  178. <UserAction
  179. search
  180. defaultSearch={filterMap.keyword}
  181. selectList={selectActionList}
  182. filterMap={filterMap}
  183. onFilter={value => this.onFilter(value)}
  184. onSearch={value => this.onSearch(value)}
  185. />
  186. {list.map(item => {
  187. return (
  188. <div className="answer-item">
  189. <div className="t-2">
  190. 课时{(courseNoMap[item.key] || {}).no} {item.position}:00~{item.position + 5}:00
  191. </div>
  192. <div className="t-2">课程内容: {(courseNoMap[item.key] || {}).title}</div>
  193. {tab === 'my' && item.answerStatus === 0 && (
  194. <div className="f-r">
  195. <Button radius size="small" onClick={() => this.delAsk(item.id)}>
  196. 删除
  197. </Button>
  198. </div>
  199. )}
  200. <div>
  201. <div className="small-tag">提问</div>
  202. <div className="f-r t-2 t-s-12">{formatDate(item.createTime, 'YYYY-MM-DD HH:mm:ss')} <span hidden={tab === 'my'}>阅读 {item.viewNumber}</span></div>
  203. </div>
  204. <div className="desc">
  205. <OpenText>{item.content}</OpenText>
  206. </div>
  207. {item.answerStatus > 0 && (
  208. <div>
  209. <div className="small-tag">回答</div>
  210. <div className="f-r t-2 t-s-12">{formatDate(item.answerTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  211. </div>
  212. )}
  213. {item.answerStatus > 0 && (
  214. <div className="desc">
  215. <OpenText onOpen={() => tab !== 'my' && this.viewAsk(item.id)}>
  216. {item.answerStatus === 2 ? '与课程内容无关,老师无法作出回答,敬请谅解。' : item.answer}
  217. </OpenText>
  218. </div>
  219. )}
  220. </div>
  221. );
  222. })}
  223. {total > 0 && list.length > 0 && (
  224. <UserPagination
  225. total={total}
  226. pageSize={this.state.search.size}
  227. current={page}
  228. onChange={p => this.onChangePage(p)}
  229. />
  230. )}
  231. </div>
  232. </div>
  233. );
  234. }
  235. }