riku
2023-11-29 9b09d13712c0c005891450a3bf4b6d848ec0ff37
pages/mAssessment/gradereport/gradereport.js
@@ -1,11 +1,11 @@
// pages/gradereport/gradereport.js
import bLoadingStatus from '../../../base/behaviors/bLoadingStatus'
import bLoadingToast from '../../../base/behaviors/bLoadingToast'
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()
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 = {
@@ -23,7 +23,7 @@
        // textBorderWidth: 1
      },
      subtextStyle: {
        fontFamily: "微软雅黑",
        fontFamily: '微软雅黑',
        fontSize: 10,
        color: 'black',
        textBorderColor: 'black',
@@ -34,12 +34,12 @@
    color: ['white'],
    tooltip: {},
    legend: {
      show: false
      show: false,
    },
    radar: {
      radius: '60%',
      axisName: {
        color: 'white'
        color: 'white',
      },
      shape: 'polygon',
      axisLine: {
@@ -47,40 +47,44 @@
        lineStyle: {
          color: 'white',
          type: 'dashed',
          join: 'round'
        }
          join: 'round',
        },
      },
      axisLabel: {
        show: false
        show: false,
      },
      splitLine: {
        show: true,
        color: 'white'
        color: 'white',
      },
      splitArea: {
        show: true,
        areaStyle: {
          color: ['#4ca796', '#63c5b3', '#74DFCB', '#76E6D2', '#75ECD7'],
        }
        },
      },
      indicator: data.indicator
      indicator: data.indicator,
    },
    series: [{
      name: "得分",
      type: "radar",
      areaStyle: {
        color: 'white',
        opacity: 0.9
    series: [
      {
        name: '得分',
        type: 'radar',
        areaStyle: {
          color: 'white',
          opacity: 0.9,
        },
        label: {
          show: false,
          position: 'inside',
        },
        data: [
          {
            value: data.value,
            name: '得分',
          },
        ],
      },
      label: {
        show: false,
        position: 'inside'
      },
      data: [{
        value: data.value,
        name: "得分"
      }]
    }],
    ],
    // grid: {
    //   x: 30,
    //   y: 30,
@@ -98,41 +102,52 @@
   */
  data: {
    ec: {
      lazyLoad: true
      lazyLoad: true,
    },
    creditText: '----------------------',
    gradeDetails: [{
      name: '自评得分',
      detail: '--'
    }, {
      name: '风险排名',
      detail: '--'
    }, {
      name: '风险等级',
      detail: '--'
    }, {
      name: '自评周期',
      detail: '--'
    }, {
      name: '自评时间',
      detail: '--'
    }],
    gradeDetails: [
      {
        name: '自评得分',
        detail: '--',
      },
      {
        name: '风险排名',
        detail: '--',
      },
      {
        name: '风险等级',
        detail: '--',
      },
      {
        name: '自评周期',
        detail: '--',
      },
      {
        name: '自评时间',
        detail: '--',
      },
    ],
    //失分的类型
    losePointsItem: [],
    losePoints: [{
      baseRule: '',
      name: '',
      itemlist: [{
        ruleName: '----',
        score: '--',
        remark: '------------'
      },{
        ruleName: '----',
        score: '--',
        remark: '------------'
      }]
    }]
    losePoints: [
      {
        baseRule: '',
        name: '',
        itemlist: [
          {
            ruleName: '----',
            score: '--',
            remark: '------------',
          },
          {
            ruleName: '----',
            score: '--',
            remark: '------------',
          },
        ],
      },
    ],
  },
  /**
@@ -141,15 +156,15 @@
  onLoad: function (options) {
    if (options.period) {
      this.setData({
        period: options.period
      })
        period: options.period,
      });
    } else {
      let now = moment()
      let now = moment();
      //根据当前时间获取评估周期YYYY/M-M
      let period = `${now.year()}/${now.month()+1}-${now.month()+1}`
      let period = `${now.year()}/${now.month() + 1}-${now.month() + 1}`;
      this.setData({
        period: period
      })
        period: period,
      });
    }
  },
@@ -158,137 +173,163 @@
   */
  onReady: function () {
    this.ecComponent = this.selectComponent('#mychart-dom-radar');
    this.initChart()
    this.initChart();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },
  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;
      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.getDetail()
        // 注意这里一定要返回 chart 实例,否则会影响事件处理等
        return chart;
      // 将图表实例绑定到 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")
        }]
        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)
        });
    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: creditText,
          gradeDetails: gradeDetails,
          losePoints: losePoints,
          losePointsItem: losePointsItem
        })
        setOption(that.chart, classPoints)
          that.setData({
            creditText,
            gradeDetails,
            losePoints,
            losePointsItem,
            pointsItem,
            points,
          });
          setOption(that.chart, classPoints);
        },
        complete() {
          that.setData({ loading: false });
        },
      },
      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 };
  },
});