page.js 7.2 KB

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