123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- const app = getApp()
- import * as echarts from '../../../commpents/ec-canvas/echarts'
- let chart;
- Page({
- data: {
- frameStyle: { useTop: true, name: '授课情况', leftArrow: true, useBar: false },
- xdata: [],
- // 学校
- zhSchool: '',
- school_id: '',
- schoolList: [],
- },
- // 返回
- back(e) {
- wx.navigateBack({ delta: 1 })
- },
- // 选择学校
- schoolChange: function (e) {
- const that = this;
- let data = that.data.schoolList[e.detail.value];
- if (data) {
- that.setData({ school_id: data.school_id });
- that.setData({ zhSchool: data.school_id_name });
- }
- that.watchLogin();
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- const that = this;
- that.setData({ ec: { onInit: that.initChart } })
- // 监听用户是否登录
- await that.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- // 学校
- const school = await app.$get(`/rcs`, { coach_id: res.data.info.id });
- if (school.errcode == '0' && school.total > 0) {
- that.setData({ schoolList: school.data })
- }
- if (that.data.school_id) {
- const arr = await app.$get(`/statistics/coachLesson`, { school_id: that.data.school_id, coach_id: res.data.info.id });
- if (arr.errcode == '0') {
- that.setData({ xdata: arr.data })
- const option = {
- series: [{ data: arr.data }],
- }
- if (chart) chart.setOption(option)
- }
- }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- // 饼图
- initChart(canvas, width, height, dpr) {
- const that = this;
- var xdata = that.data.xdata;
- chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr });
- canvas.setChart(chart);
- var option = {
- tooltip: { trigger: 'item' },
- legend: {
- orient: 'vertical',
- height: 40,
- padding: 50
- },
- series: [
- {
- name: '授课情况',
- type: 'pie',
- radius: '50%',
- data: xdata,
- emphasis: {
- itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' }
- },
- label: {
- normal: {
- show: true,
- formatter: '{b}({c}节课)'
- }
- }
- }
- ]
- };
- chart.setOption(option, true);
- return chart;
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () { },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- },
- })
|