123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- var APIClient = require('../../../utils/APIClient.js');
- var util = require('../../../utils/util.js');
- Page({
- data: {
- userInfo: wx.getStorageSync('userInfo'),
- columnId: '',
- tabData: ['问答区', '学习资料', '学习目标', '课程表'],
- isSelect: 0,
- teacherId: -1,
- qaData: {},
- inputvalue: '',
- _inputvalue: '', //重制input的值
- isReply: false,
- postsId: -1,
- focus: false,
- goal: '',
- schedule: [],
- scheduleLesson: [],
- scheduleUnfolded: 'scheduleUnfolded',
- scheduleSelect: -1,
- courseWare: [],
- title: '',
- materials: []
- },
- onLoad(options) {
- console.log(options)
- this.setData({
- userInfo: wx.getStorageSync('userInfo'),
- columnId: options.id
- })
- this.getScheduleGoal(this.data.columnId); //目标
- this.getScheduleMaterials(this.data.userInfo.id, this.data.columnId) //学习资料
- this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50) // 问答
- this.getScheduleCourse(this.data.columnId, 'COURSE', this.data.userInfo.id) // 学习目标和课程表
- },
- // 用户点击右上角分享
- onShareAppMessage(res) {
- console.log(res);
- let id = this.data.columnId
- let title= this.data.title
- return {
- title: title,
- path: `pages/schedule/scheduleSubjectInner/scheduleSubjectInner?id=${id}`
- }
- },
- // 获取学习资料
- getScheduleMaterials(userId, itemId) {
- APIClient.getScheduleMaterials(userId, itemId).success(function(res) {
- console.log('获取学习资料', res.data.data);
- this.setData({ materials: res.data.data})
- }.bind(this))
- },
- switchTab(e) {
- let index = e.currentTarget.dataset.index
- this.setData({
- isSelect: index
- })
- },
- // 获取teacherID goal title
- getScheduleGoal(itemId) {
- APIClient.getScheduleGoal(itemId).success(function(res) {
- let paragraph = res.data.data.goal
- res.data.data.goal = paragraph.split(/[\r\n]/g)
- this.setData({
- goal: res.data.data.goal,
- teacherId: res.data.data.teacherId,
- title: res.data.data.title
- })
- console.log(this.data.teacherId);
- wx.setNavigationBarTitle({
- title: this.data.title
- })
- }.bind(this))
- },
- // 获取问答区数据
- getScheduleQA(userId, columnId, columnType, pageNo, pageSize) {
- APIClient.getQAList(userId, columnId, columnType, pageNo, pageSize).success(function(res) {
- console.log('问答区数据', res)
- let list = []
- if(res.data.data && res.data.data.list) {
- list = res.data.data.list
- }
- if (list.length > 0) {
- list.forEach(function(item, index) {
- list[index].posts.gmtModified = util.formatTime(item.posts.gmtModified)
- })
- }
- this.setData({
- qaData: list
- })
- }.bind(this))
- },
- // 获取输入框里面的内容
- getValue(e) {
- this.setData({
- inputvalue: e.detail.value,
- })
- },
- //回复问题
- reply(e) {
- if (!this.data.userInfo.id) {
- util.showToast('请删除小程序再次进入时授权用户信息', 'success', '2000')
- return;
- }
- this.setData({
- isReply: true,
- focus: true,
- postsId: e.currentTarget.dataset.questions_id
- })
- },
- //问问题
- setReplay() {
- console.log('是否回复');
- if (this.data.inputvalue == '') {
- console.log('添加问题');
- this.setData({
- isReply: false
- })
- }
- },
- // 回复问题
- replyQuestion(userId, postsId, content, columnNames) {
- console.log(userId, postsId, content, columnNames);
- APIClient.addReply(userId, postsId, content, columnNames).success(function(res){
- console.log('回复问题', res);
- this.setData({
- _inputvalue: '',
- isReply: false
- })
- this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
- }.bind(this))
- },
- // 增加问题
- addQuestion(userId, columnId, columnType, title, columnNames) {
- APIClient.addQuestion(userId, columnId, columnType, title, columnNames).success(function(res){
- console.log('增加问题', res);
- this.setData({
- _inputvalue: ''
- })
- this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
- }.bind(this))
- },
- //点击发送
- submit() {
- let userId = this.data.userInfo.id;
- let value = this.data.inputvalue.trim();
- let postsId = this.data.postsId;
- let columnId = this.data.columnId;
- let columnNames = this.data.title
- if(this.data.inputvalue.trim() === '') {
- util.showToast('输入内容为空', 'success', '2000')
- } else if (!this.data.userInfo.id) {
- util.showToast('请删除小程序再次进入时授权用户信息', 'success', '2000')
- } else if(this.data.isReply) {
- console.log('回复问题');
- this.replyQuestion(userId, postsId, value, columnNames)
- } else {
- console.log('添加问题');
- this.addQuestion(userId, columnId, 'CLASS_SCHEDULE', value, columnNames)
- }
- },
- // 问题点赞
- addPraise(userId, id) {
- APIClient.addPraise(userId, id).success(function(res) {
- console.log('问题点赞', res);
- this.praiseLock = false;
- this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
- }.bind(this))
- },
- // 取消点赞
- cancelPraise(userId, id) {
- APIClient.cancelPraise(userId, id).success(function(res) {
- console.log('取消收藏', res);
- this.praiseLock = false;
- this.getScheduleQA(this.data.userInfo.id, this.data.columnId, 'CLASS_SCHEDULE', 1, 50)
- }.bind(this))
- },
- //点赞操作锁
- praiseLock: false,
- // 问题点赞切换
- togglePraise(e) {
- if (this.praiseLock) {
- return;
- }
- this.praiseLock = true;
- let userId = this.data.userInfo.id;
- let id = e.currentTarget.dataset.questions_id
- let islike = e.currentTarget.dataset.islike
- if (!islike) {
- console.log('点赞');
- this.addPraise(userId, id)
- } else {
- console.log('取消点赞');
- this.cancelPraise(userId, id)
- }
- },
- // 获取资料列表
- getMaterials(columnId) {
- APIClient.getMaterials(columnId).success(function(res) {
- console.log('获取资料列表', res);
- })
- },
- // 课件预览
- viewMaterial(e) {
- console.log('课件预览');
- var _url = e.currentTarget.dataset.url
- var url = '';
- if (_url.indexOf('/') === 0) {
- url = 'https://efunimgs.ai160.com' + _url;
- } else {
- url = 'https://efunimgs.ai160.com/' + _url;
- }
- wx.showToast({
- title: '打开中请稍后',
- icon: 'loading',
- duration: 6000
- })
- wx.downloadFile({
- url: url,
- success: function(res) {
- console.log(res, '下载')
- let tempFilePath = res.tempFilePath
- wx.openDocument({
- filePath: tempFilePath,
- success: function(res) {
- wx.hideToast()
- console.log('打开文档成功')
- },
- fail: function(res) {
- wx.hideToast()
- console.log('打开文件失败', res);
- }
- })
- },
- fail: function(res) {
- wx.hideToast()
- wx.showToast({
- title: '资源出错',
- icon: 'success',
- duration: 1000
- })
- console.log('下载失败', res);
- }
- })
- },
- // 课件收藏
- collectMaterial(e) {
- console.log(e, '课件收藏');
- let userId = this.data.userInfo.id
- let name = this.data.title
- let favoritesCode = e.currentTarget.dataset.id
- console.log(favoritesCode);
- APIClient.toggleCollection(userId, favoritesCode, 'CLASS_SCHEDULE', name).success(function(res) {
- console.log('课件收藏', res);
- this.getScheduleMaterials(this.data.userInfo.id, this.data.columnId)
- }.bind(this))
- },
- // 分享
- share() {
- console.log('share');
- },
- // 课程表
- getScheduleCourse(id, type, userId) {
- APIClient.getScheduleDetailGoalSchedule(id, type, userId).success(function(res) {
- console.log('----调取课程表课程----', res);
- this.setData({
- schedule: res.data.data
- })
- }.bind(this))
- },
- // 获取课程表lesson
- getScheduleLesson(id, type, userId) {
- APIClient.getScheduleDetailGoalSchedule(id, type, userId).success(function(res) {
- console.log('----调取课程表课---', res);
- this.setData({
- scheduleLesson: res.data.data
- })
- }.bind(this))
- },
- // 折叠课程表
- scheduleUnfolded(e) {
- let id = e.currentTarget.dataset.id
- this.getScheduleLesson(id, 'LESSON', this.data.userInfo.id)
- if (id == this.data.scheduleSelect) {
- this.setData({
- scheduleSelect: -1
- })
- } else {
- this.setData({
- scheduleSelect: id
- })
- }
- }
- })
|