scheduleSubjectInner.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. var APIClient = require('../../../utils/APIClient.js');
  2. var util = require('../../../utils/util.js');
  3. Page({
  4. data: {
  5. userInfo: wx.getStorageSync('userInfo'),
  6. columnId: '',
  7. tabData: ['问答区', '学习资料', '学习目标', '课程表'],
  8. isSelect: 0,
  9. teacherId: -1,
  10. qaData: {},
  11. inputvalue: '',
  12. _inputvalue: '', //重制input的值
  13. isReply: false,
  14. postsId: -1,
  15. focus: false,
  16. goal: '',
  17. schedule: [],
  18. scheduleLesson: [],
  19. scheduleUnfolded: 'scheduleUnfolded',
  20. scheduleSelect: -1,
  21. courseWare: [],
  22. title: '',
  23. materials: []
  24. },
  25. onLoad(options) {
  26. console.log(options)
  27. this.setData({
  28. userInfo: wx.getStorageSync('userInfo'),
  29. columnId: options.id
  30. })
  31. this.getScheduleGoal(this.data.columnId); //目标
  32. this.getScheduleMaterials(this.data.userInfo.id, this.data.columnId) //学习资料
  33. this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50) // 问答
  34. this.getScheduleCourse(this.data.columnId, 'COURSE', this.data.userInfo.id) // 学习目标和课程表
  35. },
  36. // 用户点击右上角分享
  37. onShareAppMessage(res) {
  38. console.log(res);
  39. let id = this.data.columnId
  40. let title= this.data.title
  41. return {
  42. title: title,
  43. path: `pages/schedule/scheduleSubjectInner/scheduleSubjectInner?id=${id}`
  44. }
  45. },
  46. // 获取学习资料
  47. getScheduleMaterials(userId, itemId) {
  48. APIClient.getScheduleMaterials(userId, itemId).success(function(res) {
  49. console.log('获取学习资料', res.data.data);
  50. this.setData({ materials: res.data.data})
  51. }.bind(this))
  52. },
  53. switchTab(e) {
  54. let index = e.currentTarget.dataset.index
  55. this.setData({
  56. isSelect: index
  57. })
  58. },
  59. // 获取teacherID goal title
  60. getScheduleGoal(itemId) {
  61. APIClient.getScheduleGoal(itemId).success(function(res) {
  62. let paragraph = res.data.data.goal
  63. res.data.data.goal = paragraph.split(/[\r\n]/g)
  64. this.setData({
  65. goal: res.data.data.goal,
  66. teacherId: res.data.data.teacherId,
  67. title: res.data.data.title
  68. })
  69. console.log(this.data.teacherId);
  70. wx.setNavigationBarTitle({
  71. title: this.data.title
  72. })
  73. }.bind(this))
  74. },
  75. // 获取问答区数据
  76. getScheduleQA(userId, columnId, columnType, pageNo, pageSize) {
  77. APIClient.getQAList(userId, columnId, columnType, pageNo, pageSize).success(function(res) {
  78. console.log('问答区数据', res)
  79. let list = []
  80. if(res.data.data && res.data.data.list) {
  81. list = res.data.data.list
  82. }
  83. if (list.length > 0) {
  84. list.forEach(function(item, index) {
  85. list[index].posts.gmtModified = util.formatTime(item.posts.gmtModified)
  86. })
  87. }
  88. this.setData({
  89. qaData: list
  90. })
  91. }.bind(this))
  92. },
  93. // 获取输入框里面的内容
  94. getValue(e) {
  95. this.setData({
  96. inputvalue: e.detail.value,
  97. })
  98. },
  99. //回复问题
  100. reply(e) {
  101. if (!this.data.userInfo.id) {
  102. util.showToast('请删除小程序再次进入时授权用户信息', 'success', '2000')
  103. return;
  104. }
  105. this.setData({
  106. isReply: true,
  107. focus: true,
  108. postsId: e.currentTarget.dataset.questions_id
  109. })
  110. },
  111. //问问题
  112. setReplay() {
  113. console.log('是否回复');
  114. if (this.data.inputvalue == '') {
  115. console.log('添加问题');
  116. this.setData({
  117. isReply: false
  118. })
  119. }
  120. },
  121. // 回复问题
  122. replyQuestion(userId, postsId, content, columnNames) {
  123. console.log(userId, postsId, content, columnNames);
  124. APIClient.addReply(userId, postsId, content, columnNames).success(function(res){
  125. console.log('回复问题', res);
  126. this.setData({
  127. _inputvalue: '',
  128. isReply: false
  129. })
  130. this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
  131. }.bind(this))
  132. },
  133. // 增加问题
  134. addQuestion(userId, columnId, columnType, title, columnNames) {
  135. APIClient.addQuestion(userId, columnId, columnType, title, columnNames).success(function(res){
  136. console.log('增加问题', res);
  137. this.setData({
  138. _inputvalue: ''
  139. })
  140. this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
  141. }.bind(this))
  142. },
  143. //点击发送
  144. submit() {
  145. let userId = this.data.userInfo.id;
  146. let value = this.data.inputvalue.trim();
  147. let postsId = this.data.postsId;
  148. let columnId = this.data.columnId;
  149. let columnNames = this.data.title
  150. if(this.data.inputvalue.trim() === '') {
  151. util.showToast('输入内容为空', 'success', '2000')
  152. } else if (!this.data.userInfo.id) {
  153. util.showToast('请删除小程序再次进入时授权用户信息', 'success', '2000')
  154. } else if(this.data.isReply) {
  155. console.log('回复问题');
  156. this.replyQuestion(userId, postsId, value, columnNames)
  157. } else {
  158. console.log('添加问题');
  159. this.addQuestion(userId, columnId, 'CLASS_SCHEDULE', value, columnNames)
  160. }
  161. },
  162. // 问题点赞
  163. addPraise(userId, id) {
  164. APIClient.addPraise(userId, id).success(function(res) {
  165. console.log('问题点赞', res);
  166. this.praiseLock = false;
  167. this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
  168. }.bind(this))
  169. },
  170. // 取消点赞
  171. cancelPraise(userId, id) {
  172. APIClient.cancelPraise(userId, id).success(function(res) {
  173. console.log('取消收藏', res);
  174. this.praiseLock = false;
  175. this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
  176. }.bind(this))
  177. },
  178. //点赞操作锁
  179. praiseLock: false,
  180. // 问题点赞切换
  181. togglePraise(e) {
  182. if (this.praiseLock) {
  183. return;
  184. }
  185. this.praiseLock = true;
  186. let userId = this.data.userInfo.id;
  187. let id = e.currentTarget.dataset.questions_id
  188. let islike = e.currentTarget.dataset.islike
  189. if (!islike) {
  190. console.log('点赞');
  191. this.addPraise(userId, id)
  192. } else {
  193. console.log('取消点赞');
  194. this.cancelPraise(userId, id)
  195. }
  196. },
  197. // 获取资料列表
  198. getMaterials(columnId) {
  199. APIClient.getMaterials(columnId).success(function(res) {
  200. console.log('获取资料列表', res);
  201. })
  202. },
  203. // 课件预览
  204. viewMaterial(e) {
  205. console.log('课件预览');
  206. var _url = e.currentTarget.dataset.url
  207. var url = '';
  208. if (_url.indexOf('/') === 0) {
  209. url = 'https://efunimgs.ai160.com' + _url;
  210. } else {
  211. url = 'https://efunimgs.ai160.com/' + _url;
  212. }
  213. wx.showToast({
  214. title: '打开中请稍后',
  215. icon: 'loading',
  216. duration: 6000
  217. })
  218. wx.downloadFile({
  219. url: url,
  220. success: function(res) {
  221. console.log(res, '下载')
  222. let tempFilePath = res.tempFilePath
  223. wx.openDocument({
  224. filePath: tempFilePath,
  225. success: function(res) {
  226. wx.hideToast()
  227. console.log('打开文档成功')
  228. },
  229. fail: function(res) {
  230. wx.hideToast()
  231. console.log('打开文件失败', res);
  232. }
  233. })
  234. },
  235. fail: function(res) {
  236. wx.hideToast()
  237. wx.showToast({
  238. title: '资源出错',
  239. icon: 'success',
  240. duration: 1000
  241. })
  242. console.log('下载失败', res);
  243. }
  244. })
  245. },
  246. // 课件收藏
  247. collectMaterial(e) {
  248. console.log(e, '课件收藏');
  249. let userId = this.data.userInfo.id
  250. let name = this.data.title
  251. let favoritesCode = e.currentTarget.dataset.id
  252. console.log(favoritesCode);
  253. APIClient.toggleCollection(userId, favoritesCode, 'CLASS_SCHEDULE', name).success(function(res) {
  254. console.log('课件收藏', res);
  255. this.getScheduleMaterials(this.data.userInfo.id, this.data.columnId)
  256. }.bind(this))
  257. },
  258. // 分享
  259. share() {
  260. console.log('share');
  261. },
  262. // 课程表
  263. getScheduleCourse(id, type, userId) {
  264. APIClient.getScheduleDetailGoalSchedule(id, type, userId).success(function(res) {
  265. console.log('----调取课程表课程----', res);
  266. this.setData({
  267. schedule: res.data.data
  268. })
  269. }.bind(this))
  270. },
  271. // 获取课程表lesson
  272. getScheduleLesson(id, type, userId) {
  273. APIClient.getScheduleDetailGoalSchedule(id, type, userId).success(function(res) {
  274. console.log('----调取课程表课---', res);
  275. this.setData({
  276. scheduleLesson: res.data.data
  277. })
  278. }.bind(this))
  279. },
  280. // 折叠课程表
  281. scheduleUnfolded(e) {
  282. let id = e.currentTarget.dataset.id
  283. this.getScheduleLesson(id, 'LESSON', this.data.userInfo.id)
  284. if (id == this.data.scheduleSelect) {
  285. this.setData({
  286. scheduleSelect: -1
  287. })
  288. } else {
  289. this.setData({
  290. scheduleSelect: id
  291. })
  292. }
  293. }
  294. })