page.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. this.setState({ list: result.list, total: result.total });
  86. });
  87. }
  88. refreshMy() {
  89. const { id } = this.params;
  90. this.setState({
  91. orderSelect: [
  92. { title: '无', key: '' },
  93. { title: '时间轴', key: 'position' },
  94. { title: '更新时间', key: 'updateTime' },
  95. ],
  96. });
  97. My.listCourseAsk(Object.assign({ courseId: id }, this.state.search)).then(result => {
  98. this.setState({ list: result.list, total: result.total });
  99. });
  100. }
  101. onTabChange(tab) {
  102. const data = { tab };
  103. this.refreshQuery(data);
  104. }
  105. onFilter(value) {
  106. this.search(value, false);
  107. this.initData();
  108. }
  109. onSearch(value) {
  110. this.search({ keyword: value }, false);
  111. this.initData();
  112. }
  113. onAction() {}
  114. delAsk(id) {
  115. My.delCourseAsk(id).then(() => {
  116. this.refresh();
  117. });
  118. }
  119. viewAsk(id) {
  120. Course.askView(id);
  121. }
  122. renderView() {
  123. const { course = {}, courseNoMap = {} } = this.state;
  124. const { tab, courseNoSelect, answerSelect, timelineSelect, orderSelect, filterMap = {}, list = [] } = this.state;
  125. const { total, page } = this.state;
  126. const selectActionList = [
  127. {
  128. key: 'courseNoId',
  129. placeholder: '全部课时',
  130. select: courseNoSelect,
  131. },
  132. ];
  133. selectActionList.push({
  134. key: 'order',
  135. placeholder: '排序',
  136. select: orderSelect,
  137. });
  138. if (filterMap.order === 'position') {
  139. selectActionList.push({
  140. key: 'position',
  141. placeholder: '时间区间',
  142. select: timelineSelect,
  143. });
  144. }
  145. if (tab === 'my') {
  146. selectActionList.push({
  147. key: 'answerStatus',
  148. placeholder: '状态',
  149. select: answerSelect,
  150. });
  151. }
  152. return (
  153. <div>
  154. <div className="top content t-8">
  155. 千行课堂 > 全部课程 > {course.title} > <span className="t-1">全部问答</span>
  156. <div className="f-r" onClick={() => linkTo(`/course/detail/${course.id}`)}>
  157. 返回课程
  158. </div>
  159. </div>
  160. <div className="center content">
  161. <div className="t-1 t-s-20 m-b-2">{course.title}</div>
  162. <Tabs
  163. border
  164. type="division"
  165. theme="theme"
  166. size="small"
  167. space={2.5}
  168. width={100}
  169. active={tab}
  170. tabs={[{ key: 'special', title: '精选问答' }, { key: 'my', title: '我的提问' }]}
  171. onChange={key => this.onTabChange(key)}
  172. />
  173. <UserAction
  174. search
  175. defaultSearch={filterMap.keyword}
  176. selectList={selectActionList}
  177. filterMap={filterMap}
  178. onFilter={value => this.onFilter(value)}
  179. onSearch={value => this.onSearch(value)}
  180. />
  181. {list.map(item => {
  182. return (
  183. <div className="answer-item">
  184. <div className="t-2">
  185. 课时{(courseNoMap[item.key] || {}).no} {item.position}:00~{item.position + 5}:00
  186. </div>
  187. <div className="t-2">课程内容: {(courseNoMap[item.key] || {}).title}</div>
  188. {tab === 'my' && item.answerStatus === 0 && (
  189. <div className="f-r">
  190. <Button radius size="small" onClick={() => this.delAsk(item.id)}>
  191. 删除
  192. </Button>
  193. </div>
  194. )}
  195. <div>
  196. <div className="small-tag">提问</div>
  197. <div className="f-r t-2 t-s-12">{formatDate(item.createTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  198. </div>
  199. <div className="desc">
  200. <OpenText>{item.content}</OpenText>
  201. </div>
  202. {item.answerStatus > 0 && (
  203. <div>
  204. <div className="small-tag">回答</div>
  205. <div className="f-r t-2 t-s-12">{formatDate(item.answerTime, 'YYYY-MM-DD HH:mm:ss')}</div>
  206. </div>
  207. )}
  208. {item.answerStatus > 0 && (
  209. <div className="desc">
  210. <OpenText onOpen={() => tab !== 'my' && this.viewAsk(item.id)}>
  211. {item.answerStatus === 2 ? '与课程内容无关,老师无法作出回答,敬请谅解。' : item.answer}
  212. </OpenText>
  213. </div>
  214. )}
  215. </div>
  216. );
  217. })}
  218. {total > 0 && list.length > 0 && (
  219. <UserPagination
  220. total={total}
  221. pageSize={this.state.search.size}
  222. current={page}
  223. onChange={p => this.onChangePage(p)}
  224. />
  225. )}
  226. </div>
  227. </div>
  228. );
  229. }
  230. }