// pages/gradereport/gradereport.js import bLoadingStatus from '../../../base/behaviors/bLoadingStatus'; import bLoadingToast from '../../../base/behaviors/bLoadingToast'; const echarts = require('../../../component/ec-canvas/echarts'); const assessmentService = require('../../../service/assessmentservice'); const moment = require('../../../utils/moment.min'); const app = getApp(); function setOption(chart, data) { var option = { title: { text: data.score, //主标题文本 subtext: `测评${data.level}`, //副标题文本 left: 'center', top: '40%', textStyle: { fontSize: 20, fontWeight: 'bold', color: 'black', align: 'center', textBorderColor: 'black', // textBorderWidth: 1 }, subtextStyle: { fontFamily: '微软雅黑', fontSize: 10, color: 'black', textBorderColor: 'black', // textBorderWidth: 1 }, // backgroundColor: 'black' }, color: ['white'], tooltip: {}, legend: { show: false, }, radar: { radius: '60%', axisName: { color: 'white', }, shape: 'polygon', axisLine: { show: true, lineStyle: { color: 'white', type: 'dashed', join: 'round', }, }, axisLabel: { show: false, }, splitLine: { show: true, color: 'white', }, splitArea: { show: true, areaStyle: { color: ['#4ca796', '#63c5b3', '#74DFCB', '#76E6D2', '#75ECD7'], }, }, indicator: data.indicator, }, series: [ { name: '得分', type: 'radar', areaStyle: { color: 'white', opacity: 0.9, }, label: { show: false, position: 'inside', }, data: [ { value: data.value, name: '得分', }, ], }, ], // grid: { // x: 30, // y: 30, // x2: 35, // y2: 53 // }, }; chart.setOption(option); } Page({ behaviors: [bLoadingStatus, bLoadingToast], /** * 页面的初始数据 */ data: { ec: { lazyLoad: true, }, creditText: '----------------------', gradeDetails: [ { name: '自评得分', detail: '--', }, { name: '风险排名', detail: '--', }, { name: '风险等级', detail: '--', }, { name: '自评周期', detail: '--', }, { name: '自评时间', detail: '--', }, ], //失分的类型 losePointsItem: [], losePoints: [ { baseRule: '', name: '', itemlist: [ { ruleName: '----', score: '--', remark: '------------', }, { ruleName: '----', score: '--', remark: '------------', }, ], }, ], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.period) { this.setData({ period: options.period, }); } else { let now = moment(); //根据当前时间获取评估周期YYYY/M-M let period = `${now.year()}/${now.month() + 1}-${now.month() + 1}`; this.setData({ period: period, }); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { this.ecComponent = this.selectComponent('#mychart-dom-radar'); this.initChart(); }, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, initChart: function () { var data = { score: '--', level: '一般', indicator: [ { name: '法规', max: 100, }, { name: '管理', max: 100, }, { name: '承诺', max: 100, }, { name: '守法', max: 100, }, { name: '设备', max: 100, }, ], value: [100, 100, 80, 5, 67, 82], }; this.ecComponent.init((canvas, width, height, dpr) => { // 获取组件的 canvas、width、height 后的回调函数 // 在这里初始化图表 const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr, // new }); // setOption(chart, data); // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问 this.chart = chart; this.getDetail(); // 注意这里一定要返回 chart 实例,否则会影响事件处理等 return chart; }); }, getDetail() { var that = this; this.setData({ loading: true }); assessmentService.getDetail( app.globalData.accessToken.userId, this.data.period, { success(data) { let creditText = data.creditText; let year = data.period.split('/')[0]; let month = data.period.split('/')[1].split('-')[0]; let gradeDetails = [ { name: '自评得分', detail: data.score, }, { name: '风险排名', detail: data.rank, }, { name: '风险等级', detail: data.level, }, { name: '自评周期', detail: `${year}年${month}月`, }, { name: '自评时间', detail: moment(data.time).format('YYYY-MM-DD HH:mm'), }, ]; const { pointsItem: losePointsItem, points: losePoints, } = that.parsePoint(data.loseScore); const { pointsItem, points } = that.parsePoint(data.scoring); let classPoints = { score: data.score, level: data.level, indicator: [], value: [], }; data.classScore.forEach(c => { classPoints.indicator.push({ name: c.first, max: c.second, }); classPoints.value.push(c.third); }); that.setData({ creditText, gradeDetails, losePoints, losePointsItem, pointsItem, points, }); setOption(that.chart, classPoints); }, complete() { that.setData({ loading: false }); }, }, ); }, parsePoint(itemList) { const pointsItem = []; const points = []; for (const key in itemList) { const s = itemList[key]; if (Object.keys(s).length > 0) { pointsItem.push(key); for (const key1 in s) { const rule = s[key1]; let p = { baseRule: key, name: key1, itemlist: [], }; rule.forEach(r => { // fixme : 此处暂时将【餐饮】类型的企业评估建议的第一句话删除 if (app.globalData.userInfo.extension2 === '1') { const i = r.third.indexOf(','); r.third = r.third.slice(i + 1); r.third = r.third.replaceAll('你', '您'); } p.itemlist.push({ ruleName: r.first, score: r.second, remark: r.third, }); }); points.push(p); } } } return { pointsItem, points }; }, });