// pages/teacher/count/count.js import uCharts from '../../../utils/chart/u-charts'; const { getClassList, getProjectList, getTongji, getStudentTongji, getStudentList, getClassRoomRecord, getClassRoomReportDetails } = require("../../../utils/serve/teacher"); const tabService = require("../../../utils/tab-serve"); const app = getApp() var uChartsInstance = {}; Page({ /** * 页面的初始数据 */ data: { classList: [], //班级列表 nowClass: {}, //当前选择班级 page: 1, studentList: [], hasMore: true, projectList: [], nowProject: {}, gradeList: ['不及格', '及格', '良好', '优秀'], nowGrade: '不及格', num: 0, //总人数 rank: {}, isTrainer: false, courseList: [], //教练课堂记录 nowCourse: {}, showDialog: false, clickCouse: {}, //选中的教练课程 nowCourseDetail: {}, cWidth: 330, cHeight: 280, pixelRatio: 2, }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { wx.showLoading({ title: '', }) if (wx.getStorageSync('roleId') && wx.getStorageSync('roleId') == 4) { await this.getTrainClass(true) } else { await this.getClass() } wx.hideLoading() }, clickCouse(e) { this.setData({ clickCouse: e.currentTarget.dataset.item }) }, async sureClickCouse() { const that = this if (!this.data.clickCouse.id) return app.showToast('请选择课程后再确认哦~') wx.showLoading({ title: '加载中', }) const res = await getClassRoomReportDetails(this.data.clickCouse.id) that.setData({ nowCourse: this.data.clickCouse, clickCouse: {}, showDialog: false, nowCourseDetail: res.data },()=>{ this.drawCharts(this) }) wx.hideLoading() }, showDialog() { this.setData({ showDialog: true }) }, closeDialog() { this.setData({ showDialog: false }) }, //获取班级列表 async getClass() { const res = await getClassList() this.setData({ classList: res.data, nowClass: res.data[0] }, async () => { await this.getProject() this.getStudent() }) }, //获取教练课堂记录 刷新 加载更多 async getTrainClass(isRefresh) { const that = this let refresh = isRefresh && isRefresh.type != "scrolltolower" console.log(isRefresh) console.log('aaaaaaaaaaa',refresh) if (!this.data.hasMore && !refresh) return //非刷新且没有 const res = await getClassRoomRecord({ pageIndex: this.data.page, PageSize: 20, }) if(!this.data.nowCourse.id){ const detail = await getClassRoomReportDetails(res.data.datas[0].id) this.setData({ nowCourseDetail:this.data.nowCourse.id ? this.data.nowCourseDetail: detail.data },()=>{ that.drawCharts(that) }) } this.setData({ courseList: refresh ? res.data.datas : [...this.data.courseList, ...res.data.datas], page: this.data.page + 1, hasMore: res.data.total > (this.data.page) * 20, nowCourse: !this.data.nowCourse.id || refresh ? res.data.datas[0] : this.data.nowCourse, }) }, //获取项目列表 async getProject() { const res = await getProjectList(this.data.nowClass.gradeId) this.setData({ projectList: res.data, nowProject: res.data[0] }) }, //获取学生列表 刷新 加载更多 async getStudent(isRefresh) { if (!this.data.hasMore && !isRefresh) return //非刷新且没有 const res = await getTongji({ ClassId: this.data.nowClass.classId, CategoryValue: this.data.nowProject.id || 2, Rank: this.data.nowGrade, PageIndex: isRefresh ? 1 : this.data.page, PageSize: 50 }) console.log(res.data.studentlist.total) this.setData({ page: this.data.page + 1, hasMore: res.data.studentlist.total > this.data.page * 50, studentList: isRefresh ? res.data.studentlist.datas : [...this.data.studentList, ...res.data.studentlist.datas], total: res.data.headTotal, rank: res.data.rankDic }) }, pickerChange(e) { const that = this this.setData({ [e.currentTarget.dataset.key]: this.data[e.currentTarget.dataset.id][Number(e.detail.value)] }, async () => { if (e.currentTarget.dataset.key == 'nowClass') { await that.getProject() } that.getStudent(true) }) }, goDetail(e) { wx.navigateTo({ url: '/subpackage/teacher/count-detail/count-detail?id=' + e.currentTarget.dataset.item.studentNo + '&classId=' + this.data.nowClass.classId, }) }, drawCharts(that) { const query = wx.createSelectorQuery().in(that); console.log('重新绘图',that.data.nowCourseDetail) query.select('#mycanvas').fields({ node: true, size: true }).exec(res => { if (res[0]) { const canvas = res[0].node; const ctx = canvas.getContext('2d'); canvas.width = res[0].width * that.data.pixelRatio; canvas.height = res[0].height * that.data.pixelRatio; uChartsInstance['mycanvas'] = new uCharts({ type: "line", context: ctx, width: that.data.cWidth * that.data.pixelRatio, height: that.data.cHeight * that.data.pixelRatio, categories: that.data.nowCourseDetail.heartRateTrend.axisX, series: [{ data: that.data.nowCourseDetail.heartRateTrend.axisY }, ], pixelRatio: that.data.pixelRatio, animation: true, background: "#FFFFFF", color: that.data.chartType == 1 ? ["#FFA30C"] : that.data.chartType == 2 ? ["#6CB7FB"] : ["#FF4949"], padding: [15, 15, 10, 0], enableScroll: true, // touchMoveLimit: 24, legend: { show: false, fontColor: "#37b7e8" }, xAxis: { disableGrid: true, itemCount: 5, scrollShow: true, fontSize: 12, lineHeight: 30, axisLineColor: "#f1f1f1", fontColor: "#000", scrollColor: "#f6ecc9", scrollBackgroundColor: "#F4F6F8" }, yAxis: { gridType: "dash", gridColor: "#F1F1F1", // data: [{ // min: 40, // // axisLine: false, // fontSize: 12 // }] }, extra: { line: { type: "curve", width: 2, activeType: "hollow", onShadow: true, linearType: "custom", }, tooltip: { showBox: false } } }); } else { console.error("[uCharts]: 未获取到 context"); } }); }, tap(e) { uChartsInstance[e.target.id].touchLegend(e); uChartsInstance[e.target.id].showToolTip(e); }, touchstart(e){ uChartsInstance[e.target.id].scrollStart(e); }, touchmove(e){ uChartsInstance[e.target.id].scroll(e); }, touchend(e){ uChartsInstance[e.target.id].scrollEnd(e); uChartsInstance[e.target.id].touchLegend(e); uChartsInstance[e.target.id].showToolTip(e); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { const cWidth = 315 / 375 * wx.getWindowInfo().windowWidth;; //这里的 500 对应 css .charts 的 height const cHeight = 220 / 375 * wx.getWindowInfo().windowWidth; console.log(wx.getWindowInfo()) const pixelRatio = wx.getWindowInfo().pixelRatio this.setData({ cWidth, cHeight ,pixelRatio}); }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ isTrainer: wx.getStorageSync('roleId') && wx.getStorageSync('roleId') == 4 }) tabService.updateIndex(this, 2) }, goStudentList(e){ wx.navigateTo({ url: '/subpackage/teacher/report-list/report-list?studentNo='+e.currentTarget.dataset.item.studentNo, }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.setData({ page:1, hasMore:true },()=>{ if(this.data.isTrainer){ this.getTrainClass(true) }else{ this.getClass() } wx.stopPullDownRefresh() app.showToast('刷新成功') }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { console.log('加载') }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })