import echarts from '../../../../components/ec-canvas/echarts'; import dayjs from 'dayjs'; import { useLoading } from '../../../../behaviors/loading'; import { fetchAssessmentDetail } from '../../../../services/enterprise/fetchAssessment'; 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: ['#389AFF', '#53A7FF', '#71B6FF', '#A1CFFF', '#A1CFFF'], }, }, 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: [useLoading], 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.period = options.period; this.userId = options.userId; } else { let now = dayjs(); //根据当前时间获取评估周期YYYY/M-M this.period = `${now.year()}/${now.month() + 1}-${now.month() + 1}`; } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { this.ecComponent = this.selectComponent('#mychart-dom-radar'); this.initChart(); }, onPullDownRefresh() { this._startLoad(); }, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, initChart: function () { 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._startLoad(); // 注意这里一定要返回 chart 实例,否则会影响事件处理等 return chart; }); }, _fetchData(page) { let { userId, period } = this; return fetchAssessmentDetail({ userId, period }).then(res => { let data = res.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: dayjs(data.time).format('YYYY-MM-DD HH:mm'), }, ]; let losePointsItem = []; let losePoints = []; for (const key in data.loseScore) { const s = data.loseScore[key]; if (Object.keys(s).length > 0) { losePointsItem.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, }); }); losePoints.push(p); } } } 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); }); this.setData({ creditText: creditText, gradeDetails: gradeDetails, losePoints: losePoints, losePointsItem: losePointsItem, }); setOption(this.chart, classPoints); }); }, });